Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New philosophy #17

Merged
merged 9 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

# SpecFlow auto-generated feature files
*.feature.cs

# User-specific files
*.rsuser
*.suo
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ This library is useful in case you want to have possibilities to mock static cla
## Requirements
* .NET 6 and higher

## Philosophy
1. `Stinim` should be associated with the words: **st**atic, **in**terface, **im**plementation, `Gen` - **gen**erator.
2. Static (and const) **fields** are converted to the **properties**.
3. Static **events**, **properties** and **methods** are converted to the **events**, **properties** and **methods** respectively.

## How to use
#### 1. Install NuGet package
Use any approach you prefer to install the NuGet package `Tum4ik.StinimGen`.
Expand Down Expand Up @@ -80,6 +85,3 @@ public class MyServiceTests
}
}
```

## Known limitations
* Generic methods are not supported yet.
3 changes: 2 additions & 1 deletion SolutionProperties/PackageReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Interface and implementation generation for static members.
- Interface and implementation generation for static members.
- Generic methods support.
Original file line number Diff line number Diff line change
@@ -1,92 +1,48 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis;

namespace Tum4ik.StinimGen.Specs.Extensions;
internal static class ScenarioContextExtensions
{
private const string UsingsKey = nameof(UsingsKey);

public static void AddUsings(this ScenarioContext context, string usings)
private const string DeclarationKey = nameof(DeclarationKey);
public static void AddDeclaration(this ScenarioContext context, string declaration)
{
context[UsingsKey] = usings;
context[DeclarationKey] = declaration;
}

public static string GetUsings(this ScenarioContext context)
public static string GetDeclaration(this ScenarioContext context)
{
if (context.TryGetValue(UsingsKey, out string usings))
{
return usings;
}

return string.Empty;
return (string) context[DeclarationKey];
}


private const string SourceMemberDeclarationKey = nameof(SourceMemberDeclarationKey);

public static void AddSourceMemberDeclaration(this ScenarioContext context, string sourceMemberDeclaration)
private const string AttributeUsageKey = nameof(AttributeUsageKey);
public static void AddAttributeUsage(this ScenarioContext context, string attributeUsage)
{
context[SourceMemberDeclarationKey] = sourceMemberDeclaration;
context[AttributeUsageKey] = attributeUsage;
}

public static string GetSourceMemberDeclaration(this ScenarioContext context)
public static string GetAttributeUsage(this ScenarioContext context)
{
return (string) context[SourceMemberDeclarationKey];
return (string) context[AttributeUsageKey];
}


private const string ExpectedGeneratedMemberForInterfaceKey = nameof(ExpectedGeneratedMemberForInterfaceKey);

public static void AddExpectedGeneratedMemberForInterface(this ScenarioContext context,
string expectedGeneratedMemberForInterface)
private const string MemberDeclarationKey = nameof(MemberDeclarationKey);
public static void AddMemberDeclaration(this ScenarioContext context, string memberDeclaration)
{
context[ExpectedGeneratedMemberForInterfaceKey] = expectedGeneratedMemberForInterface;
context[MemberDeclarationKey] = memberDeclaration;
}

public static string GetExpectedGeneratedMemberForInterface(this ScenarioContext context)
public static string GetMemberDeclaration(this ScenarioContext context)
{
return (string) context[ExpectedGeneratedMemberForInterfaceKey];
return (string) context[MemberDeclarationKey];
}


private const string InterfaceGeneratedMemberDeclarationKindKey = nameof(InterfaceGeneratedMemberDeclarationKindKey);

public static void AddInterfaceGeneratedMemberDeclarationKind(this ScenarioContext context, SyntaxKind kind)
{
context[InterfaceGeneratedMemberDeclarationKindKey] = kind;
}

public static SyntaxKind GetInterfaceGeneratedMemberDeclarationKind(this ScenarioContext context)
private const string GeneratorRunResultKey = nameof(GeneratorRunResultKey);
public static void AddGeneratorRunResult(this ScenarioContext context, GeneratorRunResult generatorRunResult)
{
return (SyntaxKind) context[InterfaceGeneratedMemberDeclarationKindKey];
context[GeneratorRunResultKey] = generatorRunResult;
}


private const string ImplementationGeneratedMemberDeclarationKindKey = nameof(ImplementationGeneratedMemberDeclarationKindKey);

public static void AddImplementationGeneratedMemberDeclarationKind(this ScenarioContext context, SyntaxKind kind)
{
context[ImplementationGeneratedMemberDeclarationKindKey] = kind;
}

public static SyntaxKind GetImplementationGeneratedMemberDeclarationKind(this ScenarioContext context)
{
return (SyntaxKind) context[ImplementationGeneratedMemberDeclarationKindKey];
}


private const string AdditionalNamespaceDeclarationsKey = nameof(AdditionalNamespaceDeclarationsKey);

public static void AddAdditionalNamespaceDeclarations(this ScenarioContext context, string declarations)
{
context[AdditionalNamespaceDeclarationsKey] = declarations;
}

public static string GetAdditionalNamespaceDeclarations(this ScenarioContext context)
public static GeneratorRunResult GetGeneratorRunResult(this ScenarioContext context)
{
if (context.TryGetValue(AdditionalNamespaceDeclarationsKey, out string declarations))
{
return declarations;
}
return string.Empty;
return (GeneratorRunResult) context[GeneratorRunResultKey];
}
}
Loading