-
Notifications
You must be signed in to change notification settings - Fork 261
fix: dotnet abstract classes should have proxy implementations #241
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ad1b15b
fix: dotnet abstract classes should have proxy implementations
costleya 795ce88
test: Add ReturnsAbstract compliance test
costleya bdfe854
refactor: Address changes for pr 241
costleya f708532
fix: Reverted sln file to resolve build failure
costleya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
188 changes: 188 additions & 0 deletions
188
...t-generator/src/Amazon.JSII.Generator.UnitTests/Class/AbstractClassProxyGeneratorTests.cs
This file contains hidden or 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,188 @@ | ||
| using Amazon.JSII.Generator.Class; | ||
| using Amazon.JSII.JsonModel.Spec; | ||
| using Xunit; | ||
|
|
||
| namespace Amazon.JSII.Generator.UnitTests.Class | ||
| { | ||
| public class AbstractClassProxyGeneratorTests : GeneratorTestBase | ||
| { | ||
| private const string Prefix = nameof(Generator) + "." + nameof(AbstractClassProxyGenerator) + "."; | ||
|
|
||
| private string Render(ClassType classType) | ||
| { | ||
| Symbols.MapTypeToPackage("myFqn", classType.Assembly); | ||
| Symbols.MapNamespace(classType.QualifiedNamespace, "MyNamespace"); | ||
| Symbols.MapTypeName("myFqn", "MyClass", TypeKind.Class); | ||
|
|
||
| var generator = new AbstractClassProxyGenerator(classType.Assembly, classType, Symbols, Namespaces); | ||
|
|
||
| var syntaxTree = generator.CreateSyntaxTree(); | ||
| return syntaxTree.ToString(); | ||
| } | ||
|
|
||
| [Fact(DisplayName = Prefix + nameof(IncludesAttribute))] | ||
| public void IncludesAttribute() | ||
| { | ||
| var classType = new ClassType | ||
| ( | ||
| "myFqn", | ||
| "myPackage", | ||
| "myClass", | ||
| true, | ||
| initializer: new Method(true, false, false) | ||
| ); | ||
|
|
||
| var actual = Render(classType); | ||
| var expected = | ||
| @"namespace MyNamespace | ||
| { | ||
| [JsiiTypeProxy(typeof(MyClass), ""myFqn"")] | ||
| internal sealed class MyClassProxy : MyClass | ||
| { | ||
| private MyClassProxy(ByRefValue reference): base(reference) | ||
| { | ||
| } | ||
| } | ||
| }"; | ||
| Assert.Equal(expected, actual, ignoreLineEndingDifferences: true); | ||
| } | ||
|
|
||
| [Fact(DisplayName = Prefix + nameof(IncludesDocs))] | ||
| public void IncludesDocs() | ||
| { | ||
| // Docs are not currently generated as part of the C# code. | ||
| ClassType classType = new ClassType | ||
| ( | ||
| fullyQualifiedName: "myFqn", | ||
| assembly: "myPackage", | ||
| name: "myClass", | ||
| isAbstract: true, | ||
| initializer: new Method(true, false, false), | ||
| docs: new Docs {{"foo", "bar"}} | ||
| ); | ||
|
|
||
| string actual = Render(classType); | ||
| string expected = | ||
| @"namespace MyNamespace | ||
| { | ||
| /// <remarks>foo: bar</remarks> | ||
| [JsiiTypeProxy(typeof(MyClass), ""myFqn"")] | ||
| internal sealed class MyClassProxy : MyClass | ||
| { | ||
| private MyClassProxy(ByRefValue reference): base(reference) | ||
| { | ||
| } | ||
| } | ||
| }"; | ||
| Assert.Equal(expected, actual, ignoreLineEndingDifferences: true); | ||
| } | ||
|
|
||
| [Fact(DisplayName = Prefix + nameof(IncludesProperties))] | ||
| public void IncludesProperties() | ||
| { | ||
| ClassType classType = new ClassType | ||
| ( | ||
| fullyQualifiedName: "myFqn", | ||
| assembly: "myPackage", | ||
| name: "myClass", | ||
| isAbstract: true, | ||
| initializer: new Method(true, false, false), | ||
| properties: new[] | ||
| { | ||
| new Property | ||
| ( | ||
| name: "myProp", | ||
| type: new TypeReference("myPropTypeFqn"), | ||
| isImmutable: false, | ||
| isAbstract: true, | ||
| isProtected: false | ||
| ), | ||
| new Property | ||
| ( | ||
| name: "notMyProp", | ||
| type: new TypeReference("myPropTypeFqn"), | ||
| isImmutable: false, | ||
| isAbstract: false, | ||
| isProtected: false | ||
| ) | ||
| } | ||
| ); | ||
|
|
||
| Symbols.MapTypeName("myPropTypeFqn", "MyPropType", TypeKind.Class); | ||
| Symbols.MapPropertyName("myFqn", "myProp", "MyProp"); | ||
|
|
||
| string actual = Render(classType); | ||
| string expected = | ||
| @"namespace MyNamespace | ||
| { | ||
| [JsiiTypeProxy(typeof(MyClass), ""myFqn"")] | ||
| internal sealed class MyClassProxy : MyClass | ||
| { | ||
| private MyClassProxy(ByRefValue reference): base(reference) | ||
| { | ||
| } | ||
|
|
||
| [JsiiProperty(""myProp"", ""{\""fqn\"":\""myPropTypeFqn\""}"")] | ||
| public override MyPropType MyProp | ||
| { | ||
| get => GetInstanceProperty<MyPropType>(); | ||
| set => SetInstanceProperty(value); | ||
| } | ||
| } | ||
| }"; | ||
| Assert.Equal(expected, actual, ignoreLineEndingDifferences: true); | ||
| } | ||
|
|
||
| [Fact(DisplayName = Prefix + nameof(IncludesMethods))] | ||
| public void IncludesMethods() | ||
| { | ||
| ClassType classType = new ClassType | ||
| ( | ||
| fullyQualifiedName: "myFqn", | ||
| assembly: "myPackage", | ||
| name: "myClass", | ||
| isAbstract: true, | ||
| initializer: new Method(true, false, false), | ||
| methods: new[] | ||
| { | ||
| new Method | ||
| ( | ||
| false, | ||
| false, | ||
| true, | ||
| name: "myMethod" | ||
| ), | ||
| new Method | ||
| ( | ||
| false, | ||
| false, | ||
| false, | ||
| name: "notMyMethod" | ||
| ) | ||
| } | ||
| ); | ||
|
|
||
| Symbols.MapMethodName("myFqn", "myMethod", "MyMethod"); | ||
|
|
||
| string actual = Render(classType); | ||
| string expected = | ||
| @"namespace MyNamespace | ||
| { | ||
| [JsiiTypeProxy(typeof(MyClass), ""myFqn"")] | ||
| internal sealed class MyClassProxy : MyClass | ||
| { | ||
| private MyClassProxy(ByRefValue reference): base(reference) | ||
| { | ||
| } | ||
|
|
||
| [JsiiMethod(""myMethod"", null, ""[]"")] | ||
| public override void MyMethod() | ||
| { | ||
| InvokeInstanceVoidMethod(new object[]{}); | ||
| } | ||
| } | ||
| }"; | ||
| Assert.Equal(expected, actual, ignoreLineEndingDifferences: true); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.