|
| 1 | +using System.Text.Json; |
| 2 | +using Microsoft.AspNetCore.Components.WebAssembly.Authentication; |
| 3 | + |
1 | 4 | namespace Bunit.TestDoubles;
|
2 | 5 |
|
3 | 6 | using static Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers;
|
@@ -219,6 +222,47 @@ public void Test012()
|
219 | 222 | entry.State.ShouldBe(NavigationState.Faulted);
|
220 | 223 | }
|
221 | 224 |
|
| 225 | + [Fact(DisplayName = "StateFromJson deserialize InteractiveRequestOptions")] |
| 226 | + public void Test013() |
| 227 | + { |
| 228 | + var fakeNavigationManager = CreateFakeNavigationManager(); |
| 229 | + var requestOptions = new InteractiveRequestOptions |
| 230 | + { |
| 231 | + ReturnUrl = "return", Interaction = InteractionType.SignIn, |
| 232 | + }; |
| 233 | + requestOptions.TryAddAdditionalParameter("library", "bunit"); |
| 234 | + |
| 235 | + fakeNavigationManager.NavigateToLogin("/some-url", requestOptions); |
| 236 | + |
| 237 | + var options = fakeNavigationManager.History.Last().StateFromJson<InteractiveRequestOptions>(); |
| 238 | + options.ShouldNotBeNull(); |
| 239 | + options.Interaction.ShouldBe(InteractionType.SignIn); |
| 240 | + options.ReturnUrl.ShouldBe("return"); |
| 241 | + options.TryGetAdditionalParameter("library", out string libraryName).ShouldBeTrue(); |
| 242 | + libraryName.ShouldBe("bunit"); |
| 243 | + } |
| 244 | + |
| 245 | + [Fact(DisplayName = "Given no content in state then StateFromJson throws")] |
| 246 | + public void Test014() |
| 247 | + { |
| 248 | + var fakeNavigationManager = CreateFakeNavigationManager(); |
| 249 | + fakeNavigationManager.NavigateTo("/some-url"); |
| 250 | + |
| 251 | + Should.Throw<InvalidOperationException>( |
| 252 | + () => fakeNavigationManager.History.Last().StateFromJson<InteractiveRequestOptions>()); |
| 253 | + } |
| 254 | + |
| 255 | + [Fact(DisplayName = "StateFromJson with invalid json throws")] |
| 256 | + public void Test015() |
| 257 | + { |
| 258 | + var fakeNavigationManager = CreateFakeNavigationManager(); |
| 259 | + |
| 260 | + fakeNavigationManager.NavigateTo("/login", new NavigationOptions { HistoryEntryState = "<invalidjson>" }); |
| 261 | + |
| 262 | + Should.Throw<JsonException>( |
| 263 | + () => fakeNavigationManager.History.Last().StateFromJson<InteractiveRequestOptions>()); |
| 264 | + } |
| 265 | + |
222 | 266 | private class InterceptNavigateToCounterComponent : ComponentBase
|
223 | 267 | {
|
224 | 268 | protected override void BuildRenderTree(RenderTreeBuilder builder)
|
@@ -251,7 +295,6 @@ private void InterceptNavigation(LocationChangingContext context)
|
251 | 295 |
|
252 | 296 | public class GotoExternalResourceComponent : ComponentBase
|
253 | 297 | {
|
254 |
| -#pragma warning disable 1998 |
255 | 298 | protected override void BuildRenderTree(RenderTreeBuilder builder)
|
256 | 299 | {
|
257 | 300 | builder.OpenElement(0, "button");
|
|
0 commit comments