-
Notifications
You must be signed in to change notification settings - Fork 260
feat(.net): dynmic type checking for union-typed parameters #3668
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 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8d12e6b
feat(.net): dynmic type checking for union-typed parameters
RomainMuller 036f8a1
linter fix
RomainMuller b717545
more linter fixes :oops:
RomainMuller 9c8e5fb
update snapshot
RomainMuller 56c89a9
Merge branch 'main' into rmuller/type-check-dotnet-unions
RomainMuller 537d57c
update snapshots
RomainMuller cf5f597
update snapshots
RomainMuller ddaf60a
Add .NET runtime tests around type unions checking
RomainMuller 29be798
fix snapshots
RomainMuller 161cf4c
Merge branch 'main' into rmuller/type-check-dotnet-unions
RomainMuller 52bcc12
Merge remote-tracking branch 'origin/main' into rmuller/type-check-do…
RomainMuller ae33199
update snapshots
RomainMuller d64e134
Update packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts
RomainMuller ca3fba9
Merge remote-tracking branch 'origin/main' into rmuller/type-check-do…
RomainMuller a20d565
Merge remote-tracking branch 'origin/main' into rmuller/type-check-do…
RomainMuller 67df780
make opt-in runtime dynamic instead of compile time
RomainMuller 857f92b
dispose service container
RomainMuller 4e5d2cc
Merge branch 'main' into rmuller/type-check-dotnet-unions
mergify[bot] 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
Add .NET runtime tests around type unions checking
- Loading branch information
commit ddaf60a5673d9a09ecdb01992650b58777b5ea5f
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
.../@jsii/dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/TypeCheckingTests.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,55 @@ | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Amazon.JSII.Tests.CalculatorNamespace; | ||
| using Xunit; | ||
|
|
||
| #pragma warning disable CS0612 | ||
|
|
||
| namespace Amazon.JSII.Runtime.IntegrationTests | ||
| { | ||
| public sealed class TypeCheckingTests | ||
| { | ||
| const string Prefix = nameof(TypeCheckingTests) + "."; | ||
|
|
||
| [Fact(DisplayName = Prefix + nameof(Constructor))] | ||
| public void Constructor() | ||
| { | ||
| var exception = Assert.Throws<System.ArgumentException>(() => | ||
| new ClassWithCollectionOfUnions(new IDictionary<string, object>[] | ||
| { | ||
| new Dictionary<string, object> | ||
| { | ||
| { "good", new StructA { RequiredString = "present"} }, | ||
| { "bad", $"Not a {nameof(StructA)} or {nameof(StructB)}" }, | ||
| } | ||
| }) | ||
| ); | ||
| Assert.Equal("Expected argument unionProperty[0][\"bad\"] to be one of: Amazon.JSII.Tests.CalculatorNamespace.IStructA, Amazon.JSII.Tests.CalculatorNamespace.IStructB; received System.String (Parameter 'unionProperty')", exception.Message); | ||
| } | ||
|
|
||
| [Fact(DisplayName = Prefix + nameof(Setter))] | ||
| public void Setter() | ||
| { | ||
| var subject = new ClassWithCollectionOfUnions(Array.Empty<IDictionary<string, object>>()); | ||
| var exception = Assert.Throws<System.ArgumentException>(() => | ||
| subject.UnionProperty = new IDictionary<string, object>[] | ||
| { | ||
| new Dictionary<string, object> | ||
| { | ||
| { "good", new StructA { RequiredString = "present" } }, | ||
| { "bad", $"Not a {nameof(StructA)} or {nameof(StructB)}" }, | ||
| } | ||
| }); | ||
| Assert.Equal("Expected value[0][\"bad\"] to be one of: Amazon.JSII.Tests.CalculatorNamespace.IStructA, Amazon.JSII.Tests.CalculatorNamespace.IStructB; received System.String (Parameter 'value')", exception.Message); | ||
| } | ||
|
|
||
| [Fact(DisplayName = Prefix + nameof(StaticMethod))] | ||
| public void StaticMethod() | ||
| { | ||
| var exception = Assert.Throws<System.ArgumentException>(() => | ||
| StructUnionConsumer.IsStructA("Not a StructA")); | ||
| Assert.Equal("Expected argument struct to be one of: Amazon.JSII.Tests.CalculatorNamespace.IStructA, Amazon.JSII.Tests.CalculatorNamespace.IStructB; received System.String (Parameter 'struct')", exception.Message); | ||
| } | ||
| } | ||
| } |
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
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.