From 546fbef8e7a435b2dddd1c4bec56c44feb540ff1 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 1 Aug 2022 15:27:36 +0200 Subject: [PATCH 01/12] feat: Added navigation interception --- src/bunit.web/JSInterop/BunitJSInterop.cs | 4 + ...isableNavigationPromptInvocationHandler.cs | 14 ++ ...EnableNavigationPromptInvocationHandler.cs | 14 ++ .../FakeNavigationManager.cs | 23 ++- .../FakeNavigationManagerTest.cs | 149 ++++++++++++++++++ 5 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockDisableNavigationPromptInvocationHandler.cs create mode 100644 src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockEnableNavigationPromptInvocationHandler.cs diff --git a/src/bunit.web/JSInterop/BunitJSInterop.cs b/src/bunit.web/JSInterop/BunitJSInterop.cs index 1625c6a1a..4c15f4a65 100644 --- a/src/bunit.web/JSInterop/BunitJSInterop.cs +++ b/src/bunit.web/JSInterop/BunitJSInterop.cs @@ -143,6 +143,10 @@ private void AddCustomNet5Handlers() private void AddCustomNet6Handlers() { AddInvocationHandler(new FocusOnNavigateHandler()); +#if NET7_0_OR_GREATER + AddInvocationHandler(new NavigationLockDisableNavigationPromptInvocationHandler()); + AddInvocationHandler(new NavigationLockEnableNavigationPromptInvocationHandler()); +#endif } #endif } \ No newline at end of file diff --git a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockDisableNavigationPromptInvocationHandler.cs b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockDisableNavigationPromptInvocationHandler.cs new file mode 100644 index 000000000..f1740d2ce --- /dev/null +++ b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockDisableNavigationPromptInvocationHandler.cs @@ -0,0 +1,14 @@ +#if NET7_0_OR_GREATER +namespace Bunit.JSInterop.InvocationHandlers.Implementation; + +internal sealed class NavigationLockDisableNavigationPromptInvocationHandler : JSRuntimeInvocationHandler +{ + private const string Identifier = "Blazor._internal.NavigationLock.disableNavigationPrompt"; + + internal NavigationLockDisableNavigationPromptInvocationHandler() + : base(inv => inv.Identifier.Equals(Identifier, StringComparison.Ordinal), isCatchAllHandler: true) + { + SetVoidResult(); + } +} +#endif diff --git a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockEnableNavigationPromptInvocationHandler.cs b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockEnableNavigationPromptInvocationHandler.cs new file mode 100644 index 000000000..c5015288e --- /dev/null +++ b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/NavigationLockEnableNavigationPromptInvocationHandler.cs @@ -0,0 +1,14 @@ +#if NET7_0_OR_GREATER +namespace Bunit.JSInterop.InvocationHandlers.Implementation; + +internal sealed class NavigationLockEnableNavigationPromptInvocationHandler : JSRuntimeInvocationHandler +{ + private const string Identifier = "Blazor._internal.NavigationLock.enableNavigationPrompt"; + + internal NavigationLockEnableNavigationPromptInvocationHandler() + : base(inv => inv.Identifier.Equals(Identifier, StringComparison.Ordinal), isCatchAllHandler: true) + { + SetVoidResult(); + } +} +#endif diff --git a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs index e4c146f74..321b0149f 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs @@ -85,12 +85,24 @@ protected override void NavigateToCore(string uri, NavigationOptions options) if (options.ReplaceHistoryEntry && history.Count > 0) history.Pop(); - history.Push(new NavigationHistory(uri, options)); - - renderer.Dispatcher.InvokeAsync(() => +#if NET7_0_OR_GREATER + renderer.Dispatcher.InvokeAsync(async () => +#else + renderer.Dispatcher.InvokeAsync( () => +#endif { Uri = absoluteUri.OriginalString; +#if NET7_0_OR_GREATER + var shouldContinueNavigation = await NotifyLocationChangingAsync(uri, options.HistoryEntryState, isNavigationIntercepted: false).ConfigureAwait(false); + if (!shouldContinueNavigation) + { + return; + } +#endif + + history.Push(new NavigationHistory(uri, options)); + // Only notify of changes if user navigates within the same // base url (domain). Otherwise, the user navigated away // from the app, and Blazor's NavigationManager would @@ -107,6 +119,11 @@ protected override void NavigateToCore(string uri, NavigationOptions options) } #endif +#if NET7_0_OR_GREATER + /// + protected override void SetNavigationLockState(bool value) {} +#endif + private URI GetNewAbsoluteUri(string uri) => URI.IsWellFormedUriString(uri, UriKind.Relative) ? ToAbsoluteUri(uri) diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index bf3505516..b3592b79f 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -164,4 +164,153 @@ public void Test009() locationChangedInvoked.ShouldBeFalse(); } } + + [Fact(DisplayName = "LocationChanged is raised on the test renderer's dispatcher")] + public void Test006() + { + var sut = CreateFakeNavigationManager(); + var cut = RenderComponent(); + + sut.NavigateTo("foo"); + + cut.Find("p").MarkupMatches($"

{sut.BaseUri}foo

"); + } + + [Fact(DisplayName = "Uri should not be unescaped")] + public void Test007() + { + var sut = CreateFakeNavigationManager(); + + sut.NavigateTo("/with%20whitespace"); + + sut.Uri.ShouldEndWith("with%20whitespace"); + } + + [Theory(DisplayName = "NavigateTo(uri, forceLoad, replaceHistoryEntry) is saved in history")] + [InlineData("/uri", false, false)] + [InlineData("/uri", true, false)] + [InlineData("/uri", false, true)] + public void Test200(string uri, bool forceLoad, bool replaceHistoryEntry) + { + var sut = CreateFakeNavigationManager(); + + sut.NavigateTo(uri, forceLoad, replaceHistoryEntry); + + sut.History.ShouldHaveSingleItem() + .ShouldBeEquivalentTo(new NavigationHistory(uri, new NavigationOptions() { ForceLoad = forceLoad, ReplaceHistoryEntry = replaceHistoryEntry })); + } + + [Fact(DisplayName = "NavigateTo with replaceHistoryEntry true replaces previous history entry")] + public void Test201() + { + var sut = CreateFakeNavigationManager(); + + sut.NavigateTo("/firstUrl"); + sut.NavigateTo("/secondUrl", new NavigationOptions { ReplaceHistoryEntry = true }); + + sut.History.ShouldHaveSingleItem() + .ShouldBeEquivalentTo(new NavigationHistory("/secondUrl", new NavigationOptions() { ReplaceHistoryEntry = true })); + } + + [Fact(DisplayName = "Navigate to an external url should set BaseUri")] + public void Test008() + { + const string externalUri = "https://bunit.dev/docs/getting-started/index.html"; + var sut = CreateFakeNavigationManager(); + + sut.NavigateTo(externalUri); + + sut.BaseUri.ShouldBe("https://bunit.dev/"); + sut.Uri.ShouldBe(externalUri); + } + + [Fact(DisplayName = "Navigate to external url should not invoke LocationChanged event")] + public void Test009() + { + var locationChangedInvoked = false; + const string externalUri = "https://bunit.dev/docs/getting-started/index.html"; + var sut = CreateFakeNavigationManager(); + sut.LocationChanged += (s, e) => locationChangedInvoked = true; + + sut.NavigateTo(externalUri); + + locationChangedInvoked.ShouldBeFalse(); + } + +#if NET7_0_OR_GREATER + [Fact(DisplayName = "When component provides NavigationLock, FakeNavigationManager should intercept calls")] + public void Test010() + { + var fakeNavigationManager = CreateFakeNavigationManager(); + var cut = RenderComponent(); + + cut.Find("button").Click(); + + cut.Instance.NavigationIntercepted.ShouldBeTrue(); + cut.WaitForAssertion(() => fakeNavigationManager.History.ShouldBeEmpty()); + } + + [Fact(DisplayName = "Intercepting external url's should work")] + public void Test011() + { + var fakeNavigationManager = CreateFakeNavigationManager(); + var cut = RenderComponent(); + + cut.Find("button").Click(); + + fakeNavigationManager.History.ShouldNotBeEmpty(); + } + + private class InterceptNavigateToCounterComponent : ComponentBase + { + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, "button"); + builder.AddAttribute(1, "onclick", EventCallback.Factory.Create(this, + () => NavigationManager.NavigateTo("/counter") + )); + builder.AddContent(2, "Goto counter"); + builder.CloseElement(); + builder.AddMarkupContent(3, "\n\n"); + builder.OpenComponent(4); + builder.AddAttribute(5, "OnBeforeInternalNavigation", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(EventCallback.Factory.Create(this, + InterceptNavigation + ))); + builder.CloseComponent(); + } + + public bool NavigationIntercepted; + + private void InterceptNavigation(LocationChangingContext context) + { + context.PreventNavigation(); + NavigationIntercepted = true; + } + + [Inject] private NavigationManager NavigationManager { get; set; } = default!; + } + + public class GotoExternalResourceComponent : ComponentBase + { +#pragma warning disable 1998 + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, "button"); + builder.AddAttribute(1, "onclick", EventCallback.Factory.Create(this, + () => NavigationManager.NavigateTo("https://bunit.dev") + + )); + builder.AddContent(2, "bunit"); + builder.CloseElement(); + builder.AddMarkupContent(3, "\n"); + builder.OpenComponent(4); + builder.AddAttribute(5, "ConfirmExternalNavigation", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( + true + )); + builder.CloseComponent(); + } + + [Inject] private NavigationManager NavigationManager { get; set; } = default!; + } +#endif } From 269c80585feeb9290186592272eac20332e1b65e Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 4 Aug 2022 14:58:46 +0200 Subject: [PATCH 02/12] Use parameter instead of field Co-authored-by: Egil Hansen --- .../TestDoubles/NavigationManager/FakeNavigationManagerTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index b3592b79f..7d556662e 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -279,7 +279,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseComponent(); } - public bool NavigationIntercepted; + public bool NavigationIntercepted { get; set; } private void InterceptNavigation(LocationChangingContext context) { From 90b2d762dfd2d90e19dd2e7983a1ae6b40fb1be8 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 4 Aug 2022 15:01:38 +0200 Subject: [PATCH 03/12] Remove whitespace Co-authored-by: Egil Hansen --- .../TestDoubles/NavigationManager/FakeNavigationManagerTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index 7d556662e..131d1af00 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -298,7 +298,6 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.OpenElement(0, "button"); builder.AddAttribute(1, "onclick", EventCallback.Factory.Create(this, () => NavigationManager.NavigateTo("https://bunit.dev") - )); builder.AddContent(2, "bunit"); builder.CloseElement(); From d31559854631f3f313cc0270340e52938f1649fe Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 4 Aug 2022 15:27:50 +0200 Subject: [PATCH 04/12] fix: use static import to remove noise --- .../NavigationManager/FakeNavigationManagerTest.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index 131d1af00..3d72b3042 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -1,4 +1,8 @@ -namespace Bunit.TestDoubles +namespace Bunit.TestDoubles; + +using static Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers; + +public class FakeNavigationManagerTest : TestContext { public class FakeNavigationManagerTest : TestContext { @@ -273,7 +277,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseElement(); builder.AddMarkupContent(3, "\n\n"); builder.OpenComponent(4); - builder.AddAttribute(5, "OnBeforeInternalNavigation", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck(EventCallback.Factory.Create(this, + builder.AddAttribute(5, "OnBeforeInternalNavigation", TypeCheck(EventCallback.Factory.Create(this, InterceptNavigation ))); builder.CloseComponent(); @@ -303,9 +307,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseElement(); builder.AddMarkupContent(3, "\n"); builder.OpenComponent(4); - builder.AddAttribute(5, "ConfirmExternalNavigation", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( - true - )); + builder.AddAttribute(5, "ConfirmExternalNavigation", TypeCheck(true)); builder.CloseComponent(); } From 29387c558b7fdc7627034fcb1ef21bb851cb8a3a Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Wed, 10 Aug 2022 20:17:19 +0200 Subject: [PATCH 05/12] feat: Added exception handling for NavigationLock --- .../FakeNavigationManager.cs | 23 +- .../NavigationManager/NavigationHistory.cs | 44 ++- .../NavigationManager/NavigationState.cs | 24 ++ .../FakeNavigationManagerTest.cs | 287 +++++++++--------- 4 files changed, 220 insertions(+), 158 deletions(-) create mode 100644 src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs diff --git a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs index 321b0149f..a3c2b488b 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs @@ -1,4 +1,5 @@ using Bunit.Rendering; +using Microsoft.AspNetCore.Components.Routing; namespace Bunit.TestDoubles; @@ -94,14 +95,27 @@ protected override void NavigateToCore(string uri, NavigationOptions options) Uri = absoluteUri.OriginalString; #if NET7_0_OR_GREATER - var shouldContinueNavigation = await NotifyLocationChangingAsync(uri, options.HistoryEntryState, isNavigationIntercepted: false).ConfigureAwait(false); + var shouldContinueNavigation = false; + try + { + shouldContinueNavigation = await NotifyLocationChangingAsync(uri, options.HistoryEntryState, isNavigationIntercepted: false).ConfigureAwait(false); + } + catch (Exception exception) + { + history.Push(new NavigationHistory(uri, options, NavigationState.Failed, exception)); + return; + } + + history.Push(new NavigationHistory(uri, options, shouldContinueNavigation ? NavigationState.Succeeded : NavigationState.Prevented)); + if (!shouldContinueNavigation) { return; } +#else + history.Push(new NavigationHistory(uri, options)); #endif - history.Push(new NavigationHistory(uri, options)); // Only notify of changes if user navigates within the same // base url (domain). Otherwise, the user navigated away @@ -122,6 +136,9 @@ protected override void NavigateToCore(string uri, NavigationOptions options) #if NET7_0_OR_GREATER /// protected override void SetNavigationLockState(bool value) {} + + /// + protected override void HandleLocationChangingHandlerException(Exception ex, LocationChangingContext context) => throw ex; #endif private URI GetNewAbsoluteUri(string uri) @@ -141,4 +158,4 @@ private static string GetBaseUri(URI uri) { return uri.Scheme + "://" + uri.Authority + "/"; } -} \ No newline at end of file +} diff --git a/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs b/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs index 91ab03763..471b5c0c8 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs @@ -1,3 +1,5 @@ +using Microsoft.AspNetCore.Components.Routing; + namespace Bunit.TestDoubles; /// @@ -18,27 +20,61 @@ public sealed class NavigationHistory : IEquatable public Bunit.TestDoubles.NavigationOptions Options { get; } #endif #if NET6_0_OR_GREATER - public Microsoft.AspNetCore.Components.NavigationOptions Options { get; } + public NavigationOptions Options { get; } +#endif +#if NET7_0_OR_GREATER + /// + /// Gets the associated with this history entry. + /// + public NavigationState NavigationState { get; } + + /// + /// Gets the possible exception, which was thrown in a event. + /// + public Exception? Exception { get; } #endif +#if !NET6_0_OR_GREATER /// /// Initializes a new instance of the class. /// /// /// [SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Using string to align with NavigationManager")] -#if !NET6_0_OR_GREATER public NavigationHistory(string uri, Bunit.TestDoubles.NavigationOptions options) { Uri = uri; Options = options; } #endif -#if NET6_0_OR_GREATER - public NavigationHistory(string uri, Microsoft.AspNetCore.Components.NavigationOptions options) +#if NET6_0 + /// + /// Initializes a new instance of the class. + /// + /// + /// + [SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Using string to align with NavigationManager")] + public NavigationHistory(string uri, NavigationOptions options) + { + Uri = uri; + Options = options; + } +#endif +#if NET7_0_OR_GREATER + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + [SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Using string to align with NavigationManager")] + public NavigationHistory(string uri, NavigationOptions options, NavigationState navigationState, Exception? exception = null) { Uri = uri; Options = options; + NavigationState = navigationState; + Exception = exception; } #endif diff --git a/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs new file mode 100644 index 000000000..6a9768201 --- /dev/null +++ b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs @@ -0,0 +1,24 @@ +#if NET7_0_OR_GREATER +namespace Bunit.TestDoubles; + +/// +/// Describes the possible enumerations when a navigation gets intercepted. +/// +public enum NavigationState +{ + /// + /// The navigation was successfully executed. + /// + Succeeded, + + /// + /// The navigation was prevented. + /// + Prevented, + + /// + /// An exception was thrown + /// + Failed +} +#endif diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index 3d72b3042..e26e90fd6 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -4,168 +4,78 @@ namespace Bunit.TestDoubles; public class FakeNavigationManagerTest : TestContext { - public class FakeNavigationManagerTest : TestContext - { - private FakeNavigationManager CreateFakeNavigationManager() - => Services.GetRequiredService(); - - [Fact(DisplayName = "TestContext.Services has NavigationManager registered by default as FakeNavigationManager")] - public void Test001() - { - var nm = Services.GetService(); - var fnm = Services.GetService(); - - nm.ShouldNotBeNull(); - fnm.ShouldNotBeNull(); - nm.ShouldBe(fnm); - } - - [Fact(DisplayName = "FakeNavigationManager.BaseUrl is set to http://localhost/")] - public void Test002() - { - var sut = CreateFakeNavigationManager(); - - sut.BaseUri.ShouldBe("http://localhost/"); - } - - [Theory(DisplayName = "NavigateTo with relative URI converts it to absolute and sets the Uri property ")] - [InlineData("")] - [InlineData("/")] - [InlineData("/foo")] - public void Test003(string uri) - { - var sut = CreateFakeNavigationManager(); - var expectedUri = new Uri(new Uri(sut.BaseUri, UriKind.Absolute), new Uri(uri, UriKind.Relative)); - - sut.NavigateTo(uri); - - sut.Uri.ShouldBe(expectedUri.ToString()); - } - - [Theory(DisplayName = "NavigateTo with absolute URI sets the Uri property")] - [InlineData("http://localhost")] - [InlineData("http://localhost/")] - [InlineData("http://localhost/foo")] - public void Test004(string uri) - { - var sut = CreateFakeNavigationManager(); - var expectedUri = new Uri(uri, UriKind.Absolute); - - sut.NavigateTo(uri); - - sut.Uri.ShouldBe(expectedUri.OriginalString); - } - - [Fact(DisplayName = "NavigateTo raises the NotifyLocationChanged")] - [SuppressMessage("Major Bug", "S2259:Null pointers should not be dereferenced", Justification = "BUG in analyzer - 'actualLocationChange' is NOT null on the execution path.")] - public void Test005() - { - // arrange - LocationChangedEventArgs actualLocationChange = default; - var navigationUri = "foo"; - var sut = CreateFakeNavigationManager(); - sut.LocationChanged += Sut_LocationChanged; - - // act - sut.NavigateTo(navigationUri); + private FakeNavigationManager CreateFakeNavigationManager() + => Services.GetRequiredService(); - // assert - actualLocationChange.Location.ShouldBe($"{sut.BaseUri}{navigationUri}"); - actualLocationChange.IsNavigationIntercepted.ShouldBeFalse(); - - // test helpers - void Sut_LocationChanged(object? sender, LocationChangedEventArgs e) - { - actualLocationChange = e; - } - } - - [Fact(DisplayName = "LocationChanged is raised on the test renderer's dispatcher")] - public void Test006() - { - var sut = CreateFakeNavigationManager(); - var cut = RenderComponent(); - - sut.NavigateTo("foo"); - - cut.Find("p").MarkupMatches($"

{sut.BaseUri}foo

"); - } - - [Fact(DisplayName = "Uri should not be unescaped")] - public void Test007() - { - var sut = CreateFakeNavigationManager(); - - sut.NavigateTo("/with%20whitespace"); + [Fact(DisplayName = "TestContext.Services has NavigationManager registered by default as FakeNavigationManager")] + public void Test001() + { + var nm = Services.GetService(); + var fnm = Services.GetService(); - sut.Uri.ShouldEndWith("with%20whitespace"); - } + nm.ShouldNotBeNull(); + fnm.ShouldNotBeNull(); + nm.ShouldBe(fnm); + } -#if !NET6_0_OR_GREATER - [Theory(DisplayName = "NavigateTo(uri, forceLoad) is saved in history")] - [InlineData("/uri", false)] - [InlineData("/anotherUri", true)] - public void Test100(string uri, bool forceLoad) - { - var sut = CreateFakeNavigationManager(); + [Fact(DisplayName = "FakeNavigationManager.BaseUrl is set to http://localhost/")] + public void Test002() + { + var sut = CreateFakeNavigationManager(); - sut.NavigateTo(uri, forceLoad); + sut.BaseUri.ShouldBe("http://localhost/"); + } - sut.History.ShouldHaveSingleItem() - .ShouldBeEquivalentTo(new NavigationHistory(uri, new NavigationOptions(forceLoad))); - } -#endif -#if NET6_0_OR_GREATER - [Theory(DisplayName = "NavigateTo(uri, forceLoad, replaceHistoryEntry) is saved in history")] - [InlineData("/uri", false, false)] - [InlineData("/uri", true, false)] - [InlineData("/uri", false, true)] - public void Test200(string uri, bool forceLoad, bool replaceHistoryEntry) - { - var sut = CreateFakeNavigationManager(); + [Theory(DisplayName = "NavigateTo with relative URI converts it to absolute and sets the Uri property ")] + [InlineData("")] + [InlineData("/")] + [InlineData("/foo")] + public void Test003(string uri) + { + var sut = CreateFakeNavigationManager(); + var expectedUri = new Uri(new Uri(sut.BaseUri, UriKind.Absolute), new Uri(uri, UriKind.Relative)); - sut.NavigateTo(uri, forceLoad, replaceHistoryEntry); + sut.NavigateTo(uri); - sut.History.ShouldHaveSingleItem() - .ShouldBeEquivalentTo(new NavigationHistory(uri, new NavigationOptions { ForceLoad = forceLoad, ReplaceHistoryEntry = replaceHistoryEntry })); - } + sut.Uri.ShouldBe(expectedUri.ToString()); + } - [Fact(DisplayName = "NavigateTo with replaceHistoryEntry true replaces previous history entry")] - public void Test201() - { - var sut = CreateFakeNavigationManager(); + [Theory(DisplayName = "NavigateTo with absolute URI sets the Uri property")] + [InlineData("http://localhost")] + [InlineData("http://localhost/")] + [InlineData("http://localhost/foo")] + public void Test004(string uri) + { + var sut = CreateFakeNavigationManager(); + var expectedUri = new Uri(uri, UriKind.Absolute); - sut.NavigateTo("/firstUrl"); - sut.NavigateTo("/secondUrl", new NavigationOptions { ReplaceHistoryEntry = true }); + sut.NavigateTo(uri); - sut.History.ShouldHaveSingleItem() - .ShouldBeEquivalentTo(new NavigationHistory("/secondUrl", new NavigationOptions { ReplaceHistoryEntry = true })); - } -#endif + sut.Uri.ShouldBe(expectedUri.OriginalString); + } - [Fact(DisplayName = "Navigate to an external url should set BaseUri")] - public void Test008() - { - const string externalUri = "https://bunit.dev/docs/getting-started/index.html"; - var sut = CreateFakeNavigationManager(); + [Fact(DisplayName = "NavigateTo raises the NotifyLocationChanged")] + [SuppressMessage("Major Bug", "S2259:Null pointers should not be dereferenced", + Justification = "BUG in analyzer - 'actualLocationChange' is NOT null on the execution path.")] + public void Test005() + { + // arrange + LocationChangedEventArgs actualLocationChange = default; + var navigationUri = "foo"; + var sut = CreateFakeNavigationManager(); + sut.LocationChanged += Sut_LocationChanged; - sut.NavigateTo(externalUri); + // act + sut.NavigateTo(navigationUri); - sut.BaseUri.ShouldBe("https://bunit.dev/"); - sut.Uri.ShouldBe(externalUri); - } + // assert + actualLocationChange.Location.ShouldBe($"{sut.BaseUri}{navigationUri}"); + actualLocationChange.IsNavigationIntercepted.ShouldBeFalse(); - [Fact(DisplayName = "Navigate to external url should not invoke LocationChanged event")] - public void Test009() + // test helpers + void Sut_LocationChanged(object? sender, LocationChangedEventArgs e) { - var locationChangedInvoked = false; - const string externalUri = "https://bunit.dev/docs/getting-started/index.html"; - var sut = CreateFakeNavigationManager(); - sut.LocationChanged += (s, e) => locationChangedInvoked = true; - - sut.NavigateTo(externalUri); - - locationChangedInvoked.ShouldBeFalse(); + actualLocationChange = e; } } @@ -190,6 +100,21 @@ public void Test007() sut.Uri.ShouldEndWith("with%20whitespace"); } +#if !NET6_0_OR_GREATER + [Theory(DisplayName = "NavigateTo(uri, forceLoad) is saved in history")] + [InlineData("/uri", false)] + [InlineData("/anotherUri", true)] + public void Test100(string uri, bool forceLoad) + { + var sut = CreateFakeNavigationManager(); + + sut.NavigateTo(uri, forceLoad); + + sut.History.ShouldHaveSingleItem() + .ShouldBeEquivalentTo(new NavigationHistory(uri, new NavigationOptions(forceLoad))); + } +#endif +#if NET6_0_OR_GREATER [Theory(DisplayName = "NavigateTo(uri, forceLoad, replaceHistoryEntry) is saved in history")] [InlineData("/uri", false, false)] [InlineData("/uri", true, false)] @@ -200,8 +125,16 @@ public void Test200(string uri, bool forceLoad, bool replaceHistoryEntry) sut.NavigateTo(uri, forceLoad, replaceHistoryEntry); +#if NET6_0 + sut.History.ShouldHaveSingleItem() + .ShouldBeEquivalentTo(new NavigationHistory(uri, + new NavigationOptions { ForceLoad = forceLoad, ReplaceHistoryEntry = replaceHistoryEntry })); +#elif NET7_0_OR_GREATER + var navigationOptions = new NavigationOptions { ForceLoad = forceLoad, ReplaceHistoryEntry = + replaceHistoryEntry }; sut.History.ShouldHaveSingleItem() - .ShouldBeEquivalentTo(new NavigationHistory(uri, new NavigationOptions() { ForceLoad = forceLoad, ReplaceHistoryEntry = replaceHistoryEntry })); + .ShouldBeEquivalentTo(new NavigationHistory(uri, navigationOptions, NavigationState.Succeeded)); +#endif } [Fact(DisplayName = "NavigateTo with replaceHistoryEntry true replaces previous history entry")] @@ -212,9 +145,17 @@ public void Test201() sut.NavigateTo("/firstUrl"); sut.NavigateTo("/secondUrl", new NavigationOptions { ReplaceHistoryEntry = true }); +#if NET6_0 + sut.History.ShouldHaveSingleItem() + .ShouldBeEquivalentTo(new NavigationHistory("/secondUrl", + new NavigationOptions { ReplaceHistoryEntry = true })); +#elif NET7_0_OR_GREATER sut.History.ShouldHaveSingleItem() - .ShouldBeEquivalentTo(new NavigationHistory("/secondUrl", new NavigationOptions() { ReplaceHistoryEntry = true })); + .ShouldBeEquivalentTo(new NavigationHistory("/secondUrl", new NavigationOptions { ReplaceHistoryEntry = + true }, NavigationState.Succeeded)); +#endif } +#endif [Fact(DisplayName = "Navigate to an external url should set BaseUri")] public void Test008() @@ -251,7 +192,7 @@ public void Test010() cut.Find("button").Click(); cut.Instance.NavigationIntercepted.ShouldBeTrue(); - cut.WaitForAssertion(() => fakeNavigationManager.History.ShouldBeEmpty()); + fakeNavigationManager.History.Single().NavigationState.ShouldBe(NavigationState.Prevented); } [Fact(DisplayName = "Intercepting external url's should work")] @@ -265,6 +206,19 @@ public void Test011() fakeNavigationManager.History.ShouldNotBeEmpty(); } + [Fact(DisplayName = "Exception while intercepting is set on FakeNaviationManager")] + public void Test012() + { + var fakeNavigationManager = CreateFakeNavigationManager(); + var cut = RenderComponent(); + + cut.Find("button").Click(); + + var entry = fakeNavigationManager.History.Single(); + entry.Exception.ShouldBeOfType(); + entry.NavigationState.ShouldBe(NavigationState.Failed); + } + private class InterceptNavigateToCounterComponent : ComponentBase { protected override void BuildRenderTree(RenderTreeBuilder builder) @@ -277,7 +231,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseElement(); builder.AddMarkupContent(3, "\n\n"); builder.OpenComponent(4); - builder.AddAttribute(5, "OnBeforeInternalNavigation", TypeCheck(EventCallback.Factory.Create(this, + builder.AddAttribute(5, "OnBeforeInternalNavigation", TypeCheck( + EventCallback.Factory.Create(this, InterceptNavigation ))); builder.CloseComponent(); @@ -313,5 +268,35 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) [Inject] private NavigationManager NavigationManager { get; set; } = default!; } + + private class ThrowsExceptionInInterceptNavigationComponent : ComponentBase + { + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenElement(0, "button"); + builder.AddAttribute(1, "onclick", EventCallback.Factory.Create(this, + () => NavigationManager.NavigateTo("/counter") + )); + builder.AddContent(2, "Goto counter"); + builder.CloseElement(); + builder.AddMarkupContent(3, "\n\n"); + builder.OpenComponent(4); + builder.AddAttribute(5, "OnBeforeInternalNavigation", TypeCheck( + EventCallback.Factory.Create(this, + InterceptNavigation + ))); + builder.CloseComponent(); + } + + public bool NavigationIntercepted { get; set; } + + private void InterceptNavigation(LocationChangingContext context) + { + throw new NotSupportedException("Don't intercept"); + } + + [Inject] private NavigationManager NavigationManager { get; set; } = default!; + } #endif } + From 4a1a13a91d8d0e53885084e328d821f568c2b2fb Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 11 Aug 2022 14:47:18 +0200 Subject: [PATCH 06/12] fix: remove obsolete property for test --- .../TestDoubles/NavigationManager/FakeNavigationManagerTest.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index e26e90fd6..1149697e8 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -288,8 +288,6 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) builder.CloseComponent(); } - public bool NavigationIntercepted { get; set; } - private void InterceptNavigation(LocationChangingContext context) { throw new NotSupportedException("Don't intercept"); From ff32189dd5744be51914b51d68bcb6082c434607 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 11 Aug 2022 19:59:57 +0200 Subject: [PATCH 07/12] add: Changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15669deba..1b83c8bab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ All notable changes to **bUnit** will be documented in this file. The project ad By [@linkdotnet](https://github.com/linkdotnet) and [@egil](https://github.com/egil). +- Added support for `NavigationLock`, which allows user code to intercept and prevent navigation. By [@linkdotnet](https://github.com/linkdotnet) and [@egil](https://github.com/egil). + ### Fixed - `JSInterop.VerifyInvoke` reported the wrong number of actual invocations of a given identifier. Reported by [@otori](https://github.com/otori). Fixed by [@linkdotnet](https://github.com/linkdotnet). From e9661bbca369715a016b5ad04e6adc13bfe73f7d Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Thu, 11 Aug 2022 20:19:34 +0200 Subject: [PATCH 08/12] add: Documentation for NavigationLock --- .../test-doubles/fake-navigation-manager.md | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/docs/site/docs/test-doubles/fake-navigation-manager.md b/docs/site/docs/test-doubles/fake-navigation-manager.md index 540823b19..5c34d8ea0 100644 --- a/docs/site/docs/test-doubles/fake-navigation-manager.md +++ b/docs/site/docs/test-doubles/fake-navigation-manager.md @@ -71,3 +71,65 @@ Assert.Equal("http://localhost/foo", navMan.Uri); ``` If a component issues multiple `NavigateTo` calls, then it is possible to inspect the navigation history by accessing the property. It's a stack based structure, meaning the latest navigations will be first in the collection at index 0. + +## Asserting that a navigation was prevented with the `NavigationLock` component +The `NavigationLock` component, which was introduced with .net 7, gives the possibility to intercept the navigation and can even prevent it. bUnit will always create a history entry for prevented or even failed interceptions. This gets reflected in the property, as well as in case of an exception on the property. + +A component can look like this: +```razor +@inject NavigationManager NavigationManager + + + + + +@code { + private void InterceptNavigation(LocationChangingContext context) + { + context.PreventNavigation(); + } +} +``` + +A typical test, which asserts that the navigation got prevented, would look like this: +```csharp +using var ctx = new TestContext(); +var navMan = ctx.Services.GetRequiredService(); +var cut = ctx.RenderComponent(); + +cut.Find("button").Click(); + +// Assert that the navigation was prevented +var navigationHistory = navMan.History.Single(); +Assert.Equal(NavigationState.Prevented, navigationHistory.NavigationState); +``` + +## Simulate preventing navigation from a `` with the `NavigationLock` component +As `` navigation is not natively supported in bUnit, the `NavigationManager` can be used to simulate the exact behavior. + +```razor +Counter + + + +@code { + private void InterceptNavigation(LocationChangingContext context) + { + throw new Exception(); + } +} +``` + +The test utilizes the `NavigationManager` itself to achieve the same: +```csharp +using var ctx = new TestContext(); +var navMan = ctx.Services.GetRequiredService(); +var cut = ctx.RenderComponent(); + +navMan.NavigateTo("/counter"); + +// Assert that the navigation was prevented +var navigationHistory = navMan.History.Single(); +Assert.Equal(NavigationState.Failed, navigationHistory.NavigationState); +Assert.NotNull(navigationHistory.Exception); +``` \ No newline at end of file From 0873b57475d8d3b4d9f008ea204895b23ed66210 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Fri, 12 Aug 2022 19:50:57 +0200 Subject: [PATCH 09/12] refactor: Renamed Failed to Faulted for state --- docs/site/docs/test-doubles/fake-navigation-manager.md | 2 +- .../TestDoubles/NavigationManager/NavigationState.cs | 4 ++-- .../NavigationManager/FakeNavigationManagerTest.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/site/docs/test-doubles/fake-navigation-manager.md b/docs/site/docs/test-doubles/fake-navigation-manager.md index 5c34d8ea0..2cd2cee68 100644 --- a/docs/site/docs/test-doubles/fake-navigation-manager.md +++ b/docs/site/docs/test-doubles/fake-navigation-manager.md @@ -130,6 +130,6 @@ navMan.NavigateTo("/counter"); // Assert that the navigation was prevented var navigationHistory = navMan.History.Single(); -Assert.Equal(NavigationState.Failed, navigationHistory.NavigationState); +Assert.Equal(NavigationState.Faulted, navigationHistory.NavigationState); Assert.NotNull(navigationHistory.Exception); ``` \ No newline at end of file diff --git a/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs index 6a9768201..d42c70fed 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs @@ -17,8 +17,8 @@ public enum NavigationState Prevented, /// - /// An exception was thrown + /// Indicates, that an exception was thrown. /// - Failed + Faulted } #endif diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index 1149697e8..1ca3f254a 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -216,7 +216,7 @@ public void Test012() var entry = fakeNavigationManager.History.Single(); entry.Exception.ShouldBeOfType(); - entry.NavigationState.ShouldBe(NavigationState.Failed); + entry.NavigationState.ShouldBe(NavigationState.Faulted); } private class InterceptNavigateToCounterComponent : ComponentBase From 518e7cbc9eeb90c6dcb924bbcbf79f0ca2b598c6 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Mon, 15 Aug 2022 10:49:12 +0000 Subject: [PATCH 10/12] fix: small tweaks to code docs and names --- bunit.lutconfig | 6 ++++++ .../site/docs/test-doubles/fake-navigation-manager.md | 6 +++++- .../NavigationManager/FakeNavigationManager.cs | 8 ++++---- .../NavigationManager/NavigationHistory.cs | 11 ++++++++--- .../TestDoubles/NavigationManager/NavigationState.cs | 2 +- .../NavigationManager/FakeNavigationManagerTest.cs | 4 ++-- 6 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 bunit.lutconfig diff --git a/bunit.lutconfig b/bunit.lutconfig new file mode 100644 index 000000000..596a86030 --- /dev/null +++ b/bunit.lutconfig @@ -0,0 +1,6 @@ + + + true + true + 180000 + \ No newline at end of file diff --git a/docs/site/docs/test-doubles/fake-navigation-manager.md b/docs/site/docs/test-doubles/fake-navigation-manager.md index 2cd2cee68..a12f53b70 100644 --- a/docs/site/docs/test-doubles/fake-navigation-manager.md +++ b/docs/site/docs/test-doubles/fake-navigation-manager.md @@ -73,7 +73,8 @@ Assert.Equal("http://localhost/foo", navMan.Uri); If a component issues multiple `NavigateTo` calls, then it is possible to inspect the navigation history by accessing the property. It's a stack based structure, meaning the latest navigations will be first in the collection at index 0. ## Asserting that a navigation was prevented with the `NavigationLock` component -The `NavigationLock` component, which was introduced with .net 7, gives the possibility to intercept the navigation and can even prevent it. bUnit will always create a history entry for prevented or even failed interceptions. This gets reflected in the property, as well as in case of an exception on the property. + +The `NavigationLock` component, which was introduced with .NET 7, gives the possibility to intercept the navigation and can even prevent it. bUnit will always create a history entry for prevented or even failed interceptions. This gets reflected in the property, as well as in case of an exception on the property. A component can look like this: ```razor @@ -92,6 +93,7 @@ A component can look like this: ``` A typical test, which asserts that the navigation got prevented, would look like this: + ```csharp using var ctx = new TestContext(); var navMan = ctx.Services.GetRequiredService(); @@ -105,6 +107,7 @@ Assert.Equal(NavigationState.Prevented, navigationHistory.NavigationState); ``` ## Simulate preventing navigation from a `` with the `NavigationLock` component + As `` navigation is not natively supported in bUnit, the `NavigationManager` can be used to simulate the exact behavior. ```razor @@ -121,6 +124,7 @@ As `` navigation is not natively supported in bUnit, the `NavigationMana ``` The test utilizes the `NavigationManager` itself to achieve the same: + ```csharp using var ctx = new TestContext(); var navMan = ctx.Services.GetRequiredService(); diff --git a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs index a3c2b488b..a243100d5 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs @@ -69,7 +69,6 @@ protected override void NavigateToCore(string uri, bool forceLoad) #endif #if NET6_0_OR_GREATER - /// protected override void NavigateToCore(string uri, NavigationOptions options) { @@ -89,7 +88,7 @@ protected override void NavigateToCore(string uri, NavigationOptions options) #if NET7_0_OR_GREATER renderer.Dispatcher.InvokeAsync(async () => #else - renderer.Dispatcher.InvokeAsync( () => + renderer.Dispatcher.InvokeAsync(() => #endif { Uri = absoluteUri.OriginalString; @@ -102,7 +101,7 @@ protected override void NavigateToCore(string uri, NavigationOptions options) } catch (Exception exception) { - history.Push(new NavigationHistory(uri, options, NavigationState.Failed, exception)); + history.Push(new NavigationHistory(uri, options, NavigationState.Faulted, exception)); return; } @@ -138,7 +137,8 @@ protected override void NavigateToCore(string uri, NavigationOptions options) protected override void SetNavigationLockState(bool value) {} /// - protected override void HandleLocationChangingHandlerException(Exception ex, LocationChangingContext context) => throw ex; + protected override void HandleLocationChangingHandlerException(Exception ex, LocationChangingContext context) + => throw ex; #endif private URI GetNewAbsoluteUri(string uri) diff --git a/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs b/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs index 471b5c0c8..e6b86e73c 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/NavigationHistory.cs @@ -22,15 +22,19 @@ public sealed class NavigationHistory : IEquatable #if NET6_0_OR_GREATER public NavigationOptions Options { get; } #endif + #if NET7_0_OR_GREATER /// /// Gets the associated with this history entry. /// - public NavigationState NavigationState { get; } + public NavigationState State { get; } /// - /// Gets the possible exception, which was thrown in a event. + /// Gets the exception thrown from the handler, if any. /// + /// + /// Will not be null when is . + /// public Exception? Exception { get; } #endif @@ -60,6 +64,7 @@ public NavigationHistory(string uri, NavigationOptions options) Options = options; } #endif + #if NET7_0_OR_GREATER /// /// Initializes a new instance of the class. @@ -73,7 +78,7 @@ public NavigationHistory(string uri, NavigationOptions options, NavigationState { Uri = uri; Options = options; - NavigationState = navigationState; + State = navigationState; Exception = exception; } #endif diff --git a/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs index d42c70fed..4435ae4c9 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs @@ -17,7 +17,7 @@ public enum NavigationState Prevented, /// - /// Indicates, that an exception was thrown. + /// The OnBeforeInternalNavigation event handler throw an exception and the navigation did not complete. /// Faulted } diff --git a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs index 1ca3f254a..3709497c0 100644 --- a/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs +++ b/tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs @@ -192,7 +192,7 @@ public void Test010() cut.Find("button").Click(); cut.Instance.NavigationIntercepted.ShouldBeTrue(); - fakeNavigationManager.History.Single().NavigationState.ShouldBe(NavigationState.Prevented); + fakeNavigationManager.History.Single().State.ShouldBe(NavigationState.Prevented); } [Fact(DisplayName = "Intercepting external url's should work")] @@ -216,7 +216,7 @@ public void Test012() var entry = fakeNavigationManager.History.Single(); entry.Exception.ShouldBeOfType(); - entry.NavigationState.ShouldBe(NavigationState.Faulted); + entry.State.ShouldBe(NavigationState.Faulted); } private class InterceptNavigateToCounterComponent : ComponentBase From 09da1483bfc76c10fb2d31b6c46bf72df9cc901a Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Mon, 15 Aug 2022 11:28:52 +0000 Subject: [PATCH 11/12] fix: spelling --- src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs index 4435ae4c9..4f11ecb44 100644 --- a/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs +++ b/src/bunit.web/TestDoubles/NavigationManager/NavigationState.cs @@ -17,7 +17,7 @@ public enum NavigationState Prevented, /// - /// The OnBeforeInternalNavigation event handler throw an exception and the navigation did not complete. + /// The OnBeforeInternalNavigation event handler threw an exception and the navigation did not complete. /// Faulted } From 535aa8faef8a429e3345423b230b4640a6c82503 Mon Sep 17 00:00:00 2001 From: Egil Hansen Date: Thu, 15 Sep 2022 16:34:07 +0000 Subject: [PATCH 12/12] remve lutconfig --- bunit.lutconfig | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 bunit.lutconfig diff --git a/bunit.lutconfig b/bunit.lutconfig deleted file mode 100644 index 596a86030..000000000 --- a/bunit.lutconfig +++ /dev/null @@ -1,6 +0,0 @@ - - - true - true - 180000 - \ No newline at end of file