Skip to content

Commit 09b7a24

Browse files
committed
Adding changelog, updating FakeNavigatoinManager to not change baseuri on prevention; updating test case to match.
1 parent 3dcbf02 commit 09b7a24

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Do not set the `Uri` property on the `FakeNavigationManager` if navigation is prevented by a handler on `net7.0` or greater.
12+
913
## [1.38.5] - 2025-01-12
1014

1115
### Added

src/bunit.web/TestDoubles/NavigationManager/FakeNavigationManager.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
7575
var absoluteUri = GetNewAbsoluteUri(uri);
7676
var changedBaseUri = HasDifferentBaseUri(absoluteUri);
7777

78-
if (changedBaseUri)
79-
{
80-
BaseUri = GetBaseUri(absoluteUri);
81-
}
82-
8378
if (options.ReplaceHistoryEntry && history.Count > 0)
8479
history.Pop();
8580

@@ -109,15 +104,16 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
109104
{
110105
return;
111106
}
112-
else
113-
{
114-
Uri = ToAbsoluteUri(uri).OriginalString;
115-
}
116107
#else
117108
history.Push(new NavigationHistory(uri, options));
118-
Uri = absoluteUri.OriginalString;
119109
#endif
120110

111+
if (changedBaseUri)
112+
{
113+
BaseUri = GetBaseUri(absoluteUri);
114+
}
115+
116+
Uri = absoluteUri.OriginalString;
121117

122118
// Only notify of changes if user navigates within the same
123119
// base url (domain). Otherwise, the user navigated away
@@ -127,10 +123,6 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
127123
{
128124
NotifyLocationChanged(isInterceptedLink: false);
129125
}
130-
else
131-
{
132-
BaseUri = GetBaseUri(absoluteUri);
133-
}
134126
});
135127
}
136128
#endif

tests/bunit.web.tests/TestDoubles/NavigationManager/FakeNavigationManagerTest.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ public void Test007()
107107
}
108108

109109
#if !NET6_0_OR_GREATER
110-
[Theory(DisplayName = "NavigateTo(uri, forceLoad) is saved in history")]
111-
[InlineData("/uri", false)]
112-
[InlineData("/anotherUri", true)]
113-
public void Test100(string uri, bool forceLoad)
114-
{
115-
var sut = CreateFakeNavigationManager();
110+
[Theory(DisplayName = "NavigateTo(uri, forceLoad) is saved in history")]
111+
[InlineData("/uri", false)]
112+
[InlineData("/anotherUri", true)]
113+
public void Test100(string uri, bool forceLoad)
114+
{
115+
var sut = CreateFakeNavigationManager();
116116

117-
sut.NavigateTo(uri, forceLoad);
117+
sut.NavigateTo(uri, forceLoad);
118118

119-
sut.History.ShouldHaveSingleItem()
120-
.ShouldBeEquivalentTo(new NavigationHistory(uri, new NavigationOptions(forceLoad)));
121-
}
119+
sut.History.ShouldHaveSingleItem()
120+
.ShouldBeEquivalentTo(new NavigationHistory(uri, new NavigationOptions(forceLoad)));
121+
}
122122
#endif
123123
#if NET6_0_OR_GREATER
124124
[Theory(DisplayName = "NavigateTo(uri, forceLoad, replaceHistoryEntry) is saved in history")]
@@ -297,18 +297,22 @@ public void Test017()
297297
sut.HistoryEntryState.ShouldBe(null);
298298
}
299299

300-
[Fact(DisplayName = "Preventing Navigation does not change Uri")]
301-
public void Test018()
300+
[Theory(DisplayName = "Preventing Navigation does not change Uri or BaseUri")]
301+
[InlineData("/prevented-path")]
302+
[InlineData("https://bunit.dev/uri")]
303+
public void Test018(string navToUri)
302304
{
303305
var sut = CreateFakeNavigationManager();
304-
string expectedUri = new Uri(new Uri(sut.BaseUri, UriKind.Absolute), new Uri("/expected-path", UriKind.Relative)).AbsoluteUri;
306+
Uri expectedUri = new Uri(new Uri(sut.BaseUri, UriKind.Absolute), new Uri("/expected-path", UriKind.Relative));
307+
string expectedBaseUri = sut.BaseUri;
305308

306-
sut.NavigateTo("/expected-path");
309+
sut.NavigateTo(expectedUri.AbsoluteUri);
307310
using var handler = sut.RegisterLocationChangingHandler(LocationChangingHandler);
308-
sut.NavigateTo("/prevented-path");
311+
sut.NavigateTo(navToUri);
309312

310313
sut.History.First().State.ShouldBe(NavigationState.Prevented);
311-
sut.Uri.ShouldBe(expectedUri);
314+
sut.BaseUri.ShouldBe(expectedBaseUri);
315+
sut.Uri.ShouldBe(expectedUri.AbsoluteUri);
312316

313317
ValueTask LocationChangingHandler(LocationChangingContext arg)
314318
{

0 commit comments

Comments
 (0)