-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Locking the names of base contructor arguments to the subclass inject…
…ed field names. Closes GH-7
- Loading branch information
1 parent
97c324f
commit 430b00b
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/CodegenTests/Bugs/Bug_7_InjectedFieldNamedAsBaseCtor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using JasperFx.CodeGeneration; | ||
using JasperFx.CodeGeneration.Model; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace CodegenTests.Bugs; | ||
|
||
public class Bug_7_InjectedFieldNamedAsBaseCtor | ||
{ | ||
[Fact] | ||
public void ArrangeFrames_WhereInjectedFieldHasTheSameNameAsBaseClass_ShouldUseThatNameInBaseCall() | ||
{ | ||
// Arrange | ||
var generatedAssembly = GeneratedAssembly.Empty(); | ||
generatedAssembly.ReferenceAssembly(typeof(BaseClass).Assembly); | ||
var generatedType = generatedAssembly.AddType("ChildClass", typeof(BaseClass)); | ||
generatedType.AllInjectedFields.Add(new InjectedField(typeof(string), "dependency")); | ||
|
||
// Act | ||
generatedType.ArrangeFrames(); | ||
|
||
// Assert | ||
generatedType.AllInjectedFields[0].CtorArgDeclaration.ShouldBe("int __dependency1"); | ||
generatedType.AllInjectedFields[1].CtorArgDeclaration.ShouldBe("string __dependency2"); | ||
|
||
// This fails because the ctor argument was not renamed | ||
generatedType.BaseConstructorArguments[0].Usage.ShouldBe("__dependency1"); | ||
} | ||
|
||
public class BaseClass | ||
{ | ||
private readonly int dependency; | ||
|
||
public BaseClass(int dependency) | ||
{ | ||
this.dependency = dependency; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters