Skip to content
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
13 changes: 7 additions & 6 deletions Source/Mockolate.SourceGenerators/Sources/Sources.MockClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4257,9 +4257,10 @@ private static void AppendMethodSetupImplementation(StringBuilder sb, Method met

sb.AppendLine();
sb.AppendLine("\t\t{");
string methodSetupVar = Helpers.GetUniqueLocalVariableName("methodSetup", method.Parameters);
if (method.ReturnType != Type.Void)
{
sb.Append("\t\t\tvar methodSetup = new global::Mockolate.Setup.ReturnMethodSetup<")
sb.Append("\t\t\tvar ").Append(methodSetupVar).Append(" = new global::Mockolate.Setup.ReturnMethodSetup<")
.AppendTypeOrWrapper(method.ReturnType);

foreach (MethodParameter parameter in method.Parameters)
Expand All @@ -4271,7 +4272,7 @@ private static void AppendMethodSetupImplementation(StringBuilder sb, Method met
}
else
{
sb.Append("\t\t\tvar methodSetup = new global::Mockolate.Setup.VoidMethodSetup");
sb.Append("\t\t\tvar ").Append(methodSetupVar).Append(" = new global::Mockolate.Setup.VoidMethodSetup");

if (method.Parameters.Count > 0)
{
Expand Down Expand Up @@ -4305,8 +4306,8 @@ private static void AppendMethodSetupImplementation(StringBuilder sb, Method met

sb.Append(");").AppendLine();
sb.Append("\t\t\tthis.").Append(mockRegistryName).Append(".SetupMethod(")
.Append(memberIdRef).Append(", ").Append(scopePrefix).Append("methodSetup);").AppendLine();
sb.Append("\t\t\treturn methodSetup;").AppendLine();
.Append(memberIdRef).Append(", ").Append(scopePrefix).Append(methodSetupVar).Append(");").AppendLine();
sb.Append("\t\t\treturn ").Append(methodSetupVar).Append(';').AppendLine();
}
else
{
Expand All @@ -4330,8 +4331,8 @@ private static void AppendMethodSetupImplementation(StringBuilder sb, Method met

sb.Append(");").AppendLine();
sb.Append("\t\t\tthis.").Append(mockRegistryName).Append(".SetupMethod(")
.Append(memberIdRef).Append(", ").Append(scopePrefix).Append("methodSetup);").AppendLine();
sb.Append("\t\t\treturn methodSetup;").AppendLine();
.Append(memberIdRef).Append(", ").Append(scopePrefix).Append(methodSetupVar).Append(");").AppendLine();
sb.Append("\t\t\treturn ").Append(methodSetupVar).Append(';').AppendLine();
}

sb.AppendLine("\t\t}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,32 @@ public interface IMyService
await That(result.Diagnostics).IsEmpty();
}

[Fact]
public async Task ParameterNamedSetup_ShouldCompile()
{
GeneratorResult result = Generator
.Run("""
using Mockolate;

namespace MyCode;

public class Program
{
public static void Main(string[] args)
{
_ = IMyService.CreateMock();
}
}

public interface IMyService
{
void Run(int setup, int methodSetup, int s_methodSetup);
}
""");

await That(result.Diagnostics).IsEmpty();
}

[Fact]
public async Task ShouldImplementAllMethodsFromInterfaces()
{
Expand Down