Skip to content

Commit a0955a0

Browse files
committed
refactor: to file scoped namespaces
1 parent fc624b8 commit a0955a0

3 files changed

Lines changed: 66 additions & 70 deletions

File tree

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
using Bunit.Rendering;
22

3-
namespace Bunit.TestDoubles
3+
namespace Bunit.TestDoubles;
4+
5+
/// <summary>
6+
/// Represents a fake <see cref="NavigationManager"/> that captures calls to
7+
/// <see cref="NavigationManager.NavigateTo(string, bool)"/> for testing purposes.
8+
/// </summary>
9+
public sealed class FakeNavigationManager : NavigationManager
410
{
11+
private readonly ITestRenderer renderer;
12+
private readonly Stack<NavigationHistory> history = new();
13+
514
/// <summary>
6-
/// Represents a fake <see cref="NavigationManager"/> that captures calls to
7-
/// <see cref="NavigationManager.NavigateTo(string, bool)"/> for testing purposes.
15+
/// The navigation history captured by the <see cref="FakeNavigationManager"/>.
16+
/// This is a stack based collection, so the first element is the latest/current navigation target.
817
/// </summary>
9-
public sealed class FakeNavigationManager : NavigationManager
10-
{
11-
private readonly ITestRenderer renderer;
12-
private readonly Stack<NavigationHistory> history = new();
18+
/// <remarks>
19+
/// The initial Uri is not added to the history.
20+
/// </remarks>
21+
public IReadOnlyCollection<NavigationHistory> History => history;
1322

14-
/// <summary>
15-
/// The navigation history captured by the <see cref="FakeNavigationManager"/>.
16-
/// This is a stack based collection, so the first element is the latest/current navigation target.
17-
/// </summary>
18-
/// <remarks>
19-
/// The initial Uri is not added to the history.
20-
/// </remarks>
21-
public IReadOnlyCollection<NavigationHistory> History => history;
22-
23-
/// <summary>
24-
/// Initializes a new instance of the <see cref="FakeNavigationManager"/> class.
25-
/// </summary>
26-
[SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "By design. Fake navigation manager defaults to local host as base URI.")]
27-
public FakeNavigationManager(ITestRenderer renderer)
28-
{
29-
this.renderer = renderer ?? throw new ArgumentNullException(nameof(renderer));
30-
Initialize("http://localhost/", "http://localhost/");
31-
}
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="FakeNavigationManager"/> class.
25+
/// </summary>
26+
[SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "By design. Fake navigation manager defaults to local host as base URI.")]
27+
public FakeNavigationManager(ITestRenderer renderer)
28+
{
29+
this.renderer = renderer ?? throw new ArgumentNullException(nameof(renderer));
30+
Initialize("http://localhost/", "http://localhost/");
31+
}
3232

3333
#if !NET6_0_OR_GREATER
34-
/// <inheritdoc/>
35-
protected override void NavigateToCore(string uri, bool forceLoad)
34+
/// <inheritdoc/>
35+
protected override void NavigateToCore(string uri, bool forceLoad)
36+
{
37+
Uri = ToAbsoluteUri(uri).OriginalString;
38+
history.Push(new NavigationHistory(uri, new NavigationOptions(forceLoad)));
39+
40+
renderer.Dispatcher.InvokeAsync(() =>
3641
{
3742
Uri = ToAbsoluteUri(uri).OriginalString;
38-
history.Push(new NavigationHistory(uri, new NavigationOptions(forceLoad)));
39-
40-
renderer.Dispatcher.InvokeAsync(() =>
41-
{
42-
Uri = ToAbsoluteUri(uri).OriginalString;
43-
NotifyLocationChanged(isInterceptedLink: false);
44-
});
45-
}
43+
NotifyLocationChanged(isInterceptedLink: false);
44+
});
45+
}
4646
#endif
4747

4848
#if NET6_0_OR_GREATER
@@ -64,5 +64,4 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
6464
});
6565
}
6666
#endif
67-
}
6867
}
Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
namespace Bunit.TestDoubles
1+
namespace Bunit.TestDoubles;
2+
3+
/// <summary>
4+
/// Represents a navigation to a <seealso cref="Uri"/> with a set of specific navigation <seealso cref="Options"/>.
5+
/// </summary>
6+
public sealed class NavigationHistory : IEquatable<NavigationHistory>
27
{
38
/// <summary>
4-
/// Represents a navigation to a <seealso cref="Uri"/> with a set of specific navigation <seealso cref="Options"/>.
9+
/// Gets the <see cref="Uri"/> that was navigated to.
510
/// </summary>
6-
public sealed class NavigationHistory : IEquatable<NavigationHistory>
7-
{
8-
/// <summary>
9-
/// Gets the <see cref="Uri"/> that was navigated to.
10-
/// </summary>
11-
[SuppressMessage("Design", "CA1056:URI-like properties should not be strings", Justification = "Using string to align with NavigationManager")]
12-
public string Uri { get; }
11+
[SuppressMessage("Design", "CA1056:URI-like properties should not be strings", Justification = "Using string to align with NavigationManager")]
12+
public string Uri { get; }
1313

14-
/// <summary>
15-
/// Gets the options that was specified when the <see name="Uri"/> was navigated to.
16-
/// </summary>
14+
/// <summary>
15+
/// Gets the options that was specified when the <see name="Uri"/> was navigated to.
16+
/// </summary>
1717
#if !NET6_0_OR_GREATER
18-
public Bunit.TestDoubles.NavigationOptions Options { get; }
18+
public Bunit.TestDoubles.NavigationOptions Options { get; }
1919
#endif
2020
#if NET6_0_OR_GREATER
2121
public Microsoft.AspNetCore.Components.NavigationOptions Options { get; }
2222
#endif
2323

24-
/// <summary>
25-
/// Initializes a new instance of the <see cref="NavigationHistory"/> class.
26-
/// </summary>
27-
/// <param name="uri"></param>
28-
/// <param name="options"></param>
29-
[SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Using string to align with NavigationManager")]
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="NavigationHistory"/> class.
26+
/// </summary>
27+
/// <param name="uri"></param>
28+
/// <param name="options"></param>
29+
[SuppressMessage("Design", "CA1054:URI-like parameters should not be strings", Justification = "Using string to align with NavigationManager")]
3030
#if !NET6_0_OR_GREATER
31-
public NavigationHistory(string uri, Bunit.TestDoubles.NavigationOptions options)
32-
{
33-
Uri = uri;
34-
Options = options;
35-
}
31+
public NavigationHistory(string uri, Bunit.TestDoubles.NavigationOptions options)
32+
{
33+
Uri = uri;
34+
Options = options;
35+
}
3636
#endif
3737
#if NET6_0_OR_GREATER
3838
public NavigationHistory(string uri, Microsoft.AspNetCore.Components.NavigationOptions options)
@@ -42,10 +42,10 @@ public NavigationHistory(string uri, Microsoft.AspNetCore.Components.NavigationO
4242
}
4343
#endif
4444

45-
/// <inheritdoc/>
45+
/// <inheritdoc/>
4646
#if !NET6_0_OR_GREATER
47-
public bool Equals(NavigationHistory? other)
48-
=> other is not null && string.Equals(Uri, other.Uri, StringComparison.Ordinal) && Options.Equals(other.Options);
47+
public bool Equals(NavigationHistory? other)
48+
=> other is not null && string.Equals(Uri, other.Uri, StringComparison.Ordinal) && Options.Equals(other.Options);
4949
#endif
5050
#if NET6_0_OR_GREATER
5151
public bool Equals(NavigationHistory? other)
@@ -55,10 +55,9 @@ public bool Equals(NavigationHistory? other)
5555
&& Options.ReplaceHistoryEntry == other.Options.ReplaceHistoryEntry;
5656
#endif
5757

58-
/// <inheritdoc/>
59-
public override bool Equals(object? obj) => obj is NavigationHistory other && Equals(other);
58+
/// <inheritdoc/>
59+
public override bool Equals(object? obj) => obj is NavigationHistory other && Equals(other);
6060

61-
/// <inheritdoc/>
62-
public override int GetHashCode() => HashCode.Combine(Uri, Options);
63-
}
61+
/// <inheritdoc/>
62+
public override int GetHashCode() => HashCode.Combine(Uri, Options);
6463
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#if !NET6_0_OR_GREATER
2-
using System;
3-
42
namespace Bunit.TestDoubles;
53

64
/// <summary>

0 commit comments

Comments
 (0)