-
-
Notifications
You must be signed in to change notification settings - Fork 116
Implemented IJSInProcessRuntime and IJSUnmarshalledRuntime interf…
#279
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e5c7d75
Implemented `IJSInProcessRuntime` and `IJSUnmarshalledRuntime` interf…
KristofferStrube 9e24071
Added zero argument test for `IJSUnmarshalledRuntime` invocation
KristofferStrube f73c90b
Added suppression for ValueTask message
KristofferStrube 44c5766
Removed `DisallowNull` attribute at `InvokeUnmarshalled`'s arguments …
KristofferStrube 17ad18d
Added two happy path tests for strict mode of Unmarshelled
KristofferStrube eba6cd3
Moved .NET 5 tests for BunitJSInterop to their own file and made that…
KristofferStrube 1383047
Added more tests for IJSUnmarshalled
KristofferStrube 1e6915a
Removed unused CancelationTokens and simplified exception throwing te…
KristofferStrube 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
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
98 changes: 98 additions & 0 deletions
98
tests/bunit.web.tests/JSInterop/BunitJSInteropTest.net5.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,98 @@ | ||
| #if NET5_0 | ||
| using System; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Bunit; | ||
| using Microsoft.JSInterop; | ||
| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| namespace Bunit.JSInterop | ||
| { | ||
| public partial class BunitJSInteropTest | ||
| { | ||
| [Fact(DisplayName = "Mock throws exception when in strict mode and IJSUnmarshalledRuntime invocation has not been setup with one argument")] | ||
| public void Test047() | ||
| { | ||
| var sut = CreateSut(JSRuntimeMode.Strict); | ||
| var identifier = "func"; | ||
| var args = new[] { "bar" }; | ||
|
|
||
| var exception = Should.Throw<JSRuntimeUnhandledInvocationException>(() => { var _ = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled<string, object>(identifier, "bar"); }); | ||
| exception.Invocation.Identifier.ShouldBe(identifier); | ||
| exception.Invocation.Arguments.ShouldBe(args); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Mock throws exception when in strict mode and IJSUnmarshalledRuntime invocation has not been setup with two arguments")] | ||
| public void Test048() | ||
| { | ||
| var sut = CreateSut(JSRuntimeMode.Strict); | ||
| var identifier = "func"; | ||
| var args = new[] { "bar", "baz" }; | ||
|
|
||
| var exception = Should.Throw<JSRuntimeUnhandledInvocationException>(() => { var _ = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled<string, string, object>(identifier, "bar", "baz"); }); | ||
| exception.Invocation.Identifier.ShouldBe(identifier); | ||
| exception.Invocation.Arguments.ShouldBe(args); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Mock throws exception when in strict mode and IJSUnmarshalledRuntime invocation has not been setup with three arguments")] | ||
| public void Test049() | ||
| { | ||
| var sut = CreateSut(JSRuntimeMode.Strict); | ||
| var identifier = "func"; | ||
| var args = new[] { "bar", "baz", "bau" }; | ||
|
|
||
| var exception = Should.Throw<JSRuntimeUnhandledInvocationException>(() => { var _ = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled<string, string, string, object>(identifier, "bar", "baz", "bau"); }); | ||
| exception.Invocation.Identifier.ShouldBe(identifier); | ||
| exception.Invocation.Arguments.ShouldBe(args); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "Mock throws exception when in strict mode and IJSUnmarshalledRuntime invocation has not been setup with zero arguments")] | ||
| public void Test050() | ||
| { | ||
| var sut = CreateSut(JSRuntimeMode.Strict); | ||
| var identifier = "func"; | ||
|
|
||
| var exception = Should.Throw<JSRuntimeUnhandledInvocationException>(() => { var _ = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled<object>(identifier); }); | ||
| exception.Invocation.Identifier.ShouldBe(identifier); | ||
| exception.Invocation.Arguments.ShouldBeEmpty(); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "After IJSUnmarshalledRuntime invocation a invocation should be visible from the Invocations list.")] | ||
| public void Test051() | ||
| { | ||
| var identifier = "fooFunc"; | ||
| var args = new[] { "bar", "baz" }; | ||
| using var cts = new CancellationTokenSource(); | ||
| var sut = CreateSut(JSRuntimeMode.Strict); | ||
|
|
||
| var planned = sut.Setup<Guid>("fooFunc", args); | ||
| planned.SetResult(Guid.NewGuid()); | ||
|
|
||
| var _ = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled<string, string, Guid>(identifier, "bar", "baz"); | ||
|
|
||
| var invocation = sut.Invocations[identifier].Single(); | ||
| invocation.Identifier.ShouldBe(identifier); | ||
| invocation.Arguments.ShouldBe(args); | ||
| } | ||
|
|
||
| [Fact(DisplayName = "An IJSUnmarshalledRuntime invocation should return the correct result.")] | ||
| public void Test052() | ||
| { | ||
| var identifier = "fooFunc"; | ||
| var args = new[] { "bar", "baz" }; | ||
| using var cts = new CancellationTokenSource(); | ||
| var sut = CreateSut(JSRuntimeMode.Strict); | ||
|
|
||
| var expectedResult = Guid.NewGuid(); | ||
| var planned = sut.Setup<Guid>("fooFunc", args); | ||
| planned.SetResult(expectedResult); | ||
|
|
||
| var actual = ((IJSUnmarshalledRuntime)sut.JSRuntime).InvokeUnmarshalled<string, string, Guid>(identifier, "bar", "baz"); | ||
| actual.ShouldBe(expectedResult); | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
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.