Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to **bUnit** will be documented in this file. The project ad

## [Unreleased]

### Fixed

- Do not set the `Uri` or `BaseUri` property on the `FakeNavigationManager` if navigation is prevented by a handler on `net7.0` or greater. Reported and fixed by [@ayyron-dev](https://github.com/ayyron-dev) in [#1647](https://github.com/bUnit-dev/bUnit/issues/1647)
- Use default renderer properties for AngleSharp. Reported by [@jtleaming](https://github.com/jtleaming) in [#1692].
- `FindComponents` throws an exception, when a base and derived class was searched for. Reported by [@BlueDragon709](https://github.com/BlueDragon709) in [#1691].

## [1.38.5] - 2025-01-12

### Added
Expand Down
26 changes: 13 additions & 13 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- Shared code analyzers used for all projects in the solution -->
<ItemGroup Condition="!$(MSBuildProjectName.EndsWith('samples'))">
<GlobalPackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" IncludeAssets="Runtime;Build;Native;contentFiles;Analyzers"/>
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167" PrivateAssets="All" IncludeAssets="Runtime;Build;Native;contentFiles;Analyzers"/>
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="10.5.0.109200" PrivateAssets="All" IncludeAssets="Runtime;Build;Native;contentFiles;Analyzers"/>
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Meziantou.Polyfill" Version="1.0.42" />
</ItemGroup>
Expand All @@ -28,7 +28,7 @@

<ItemGroup Label="System.Text.Json Vulnerability">
<!-- Due to a CVE in System.Text.Json we explicitly reference the latest version of System.Text.Json -->
<PackageVersion Include="System.Text.Json" Version="9.0.0"/>
<PackageVersion Include="System.Text.Json" Version="9.0.1"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
Expand Down Expand Up @@ -97,16 +97,16 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="9.0.0"/>

<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="9.0.0"/>
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.0"/>
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.0"/>
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.1"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1"/>
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="9.0.1"/>

<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="9.0.1"/>
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.1"/>
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.1"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.1"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.1"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="9.0.1"/>
</ItemGroup>

<ItemGroup Label="Test Dependencies">
Expand All @@ -122,7 +122,7 @@
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Shouldly" Version="4.2.1"/>
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.0"/>
<PackageVersion Include="Verify.Xunit" Version="28.8.1"/>
<PackageVersion Include="Verify.Xunit" Version="28.9.0"/>
<PackageVersion Include="Xunit.Combinatorial" Version="1.6.24"/>
<PackageVersion Include="coverlet.collector" Version="6.0.3" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.3" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ A huge thank you to the [sponsors of bUnit](https://github.com/sponsors/egil). T
<table border="0">
<tr>
<td align="center" width="120">
<a href="https://github.com/syncfusion">
<a href="https://www.syncfusion.com/blazor-components?utm_source=bunit&utm_medium=cpc&utm_campaign=bunit_blazor_bancy25">
<img class="avatar" src="https://avatars.githubusercontent.com/u/1699795?s=460" width="72" height="72" alt="@syncfusion" />
<br />
Syncfusion
Expand Down
8 changes: 7 additions & 1 deletion src/bunit.core/Rendering/TestRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,13 @@ private IRenderedComponentBase<TComponent> GetOrCreateRenderedComponent<TCompone
{
if (renderedComponents.TryGetValue(componentId, out var renderedComponent))
{
return (IRenderedComponentBase<TComponent>)renderedComponent;
if (renderedComponent is IRenderedComponentBase<TComponent> typedComponent)
{
return typedComponent;
}

renderedComponent.Dispose();
renderedComponents.Remove(componentId);
}

LoadRenderTreeFrames(componentId, framesCollection);
Expand Down
12 changes: 10 additions & 2 deletions src/bunit.web/Rendering/BunitHtmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections;
using System.Diagnostics;
using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
using Bunit.Diffing;
Expand Down Expand Up @@ -28,7 +29,8 @@ public sealed class BunitHtmlParser : IDisposable
/// with a AngleSharp context without a <see cref="TestRenderer"/> registered.
/// </summary>
public BunitHtmlParser()
: this(Configuration.Default.WithCss().With(new HtmlComparer())) { }
: this(Configuration.Default.WithCss()
.With(new HtmlComparer())) { }

/// <summary>
/// Initializes a new instance of the <see cref="BunitHtmlParser"/> class
Expand All @@ -43,7 +45,13 @@ public BunitHtmlParser(HtmlComparer htmlComparer, TestContextBase testContext)

private BunitHtmlParser(IConfiguration angleSharpConfiguration)
{
var config = angleSharpConfiguration.With(this);
var config = angleSharpConfiguration
.With(this)
.WithRenderDevice(new DefaultRenderDevice
{
ViewPortWidth = 1920,
ViewPortHeight = 1080,
});
context = BrowsingContext.New(config);
var parseOptions = new HtmlParserOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
var absoluteUri = GetNewAbsoluteUri(uri);
var changedBaseUri = HasDifferentBaseUri(absoluteUri);

if (changedBaseUri)
{
BaseUri = GetBaseUri(absoluteUri);
}

Uri = ToAbsoluteUri(uri).OriginalString;

if (options.ReplaceHistoryEntry && history.Count > 0)
history.Pop();

Expand All @@ -92,7 +85,6 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
testContextBase.Renderer.Dispatcher.InvokeAsync(() =>
#endif
{
Uri = absoluteUri.OriginalString;

#if NET7_0_OR_GREATER
var shouldContinueNavigation = false;
Expand All @@ -116,6 +108,12 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
history.Push(new NavigationHistory(uri, options));
#endif

if (changedBaseUri)
{
BaseUri = GetBaseUri(absoluteUri);
}

Uri = absoluteUri.OriginalString;

// Only notify of changes if user navigates within the same
// base url (domain). Otherwise, the user navigated away
Expand All @@ -125,17 +123,13 @@ protected override void NavigateToCore(string uri, NavigationOptions options)
{
NotifyLocationChanged(isInterceptedLink: false);
}
else
{
BaseUri = GetBaseUri(absoluteUri);
}
});
}
#endif

#if NET7_0_OR_GREATER
/// <inheritdoc/>
protected override void SetNavigationLockState(bool value) {}
protected override void SetNavigationLockState(bool value) { }

/// <inheritdoc/>
protected override void HandleLocationChangingHandlerException(Exception ex, LocationChangingContext context)
Expand Down
2 changes: 1 addition & 1 deletion tests/bunit.core.tests/Rendering/RenderModeTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
</ComponentWithChildContent>
</ComponentWithChildContent>);

act.ShouldThrow<RenderModeMisMatchException>(); // todo: figure out good exception to use
act.ShouldThrow<RenderModeMisMatchException>();
}
}
@code{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void Test013(string key)
{
var fakeState = this.AddFakePersistentComponentState();

fakeState.TryTake<string>(key, out var actual).ShouldBeFalse();
fakeState.TryTake<string>(key, out _).ShouldBeFalse();
}

[Fact(DisplayName = "TriggerOnPersisting triggers OnPersisting callbacks added to store")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Child components follow.

@code {
int numAdded = 0;
List<string> currentChildrenMessages = new List<string>();
private readonly List<string> currentChildrenMessages = new List<string>();

void AddChild()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/bunit.testassets/BlazorE2E/DataDashComponent.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="cool_beans" data-tab="@TabId">@TabId</div>

@code {
string TabId = "17";
private readonly string TabId = "17";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

@functions {
Dictionary<string, object> elementValues = new Dictionary<string, object>
private readonly Dictionary<string, object> elementValues = new Dictionary<string, object>
{
{ "bool", true },
{ "string", "middle-value" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Type here: <input @onkeypress=OnKeyPressed />
</ul>

@code {
List<string> keysPressed = new List<string>();
private readonly List<string> keysPressed = new List<string>();

void OnKeyPressed(KeyboardEventArgs eventArgs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#nullable disable
bool changeOutput;

string myMarkup = "<p class='markup-string-value'>This is a <em>markup string</em>.</p>";
private readonly string myMarkup = "<p class='markup-string-value'>This is a <em>markup string</em>.</p>";

void EmitMarkupBlock(RenderTreeBuilder builder)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@

@code {
#nullable disable
List<TodoItem> items = new List<TodoItem>
private readonly List<TodoItem> items = new List<TodoItem>
{
new TodoItem { Text = "Alpha" },
new TodoItem { Text = "Beta" },
new TodoItem { Text = "Gamma", IsDone = true },
new TodoItem { Text = "Delta", IsDone = true },
};

class TodoItem
private sealed class TodoItem
{
public bool IsDone { get; set; }
public string Text { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion tests/bunit.testassets/BlazorE2E/OrderedList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
@foreach (var item in Items)
{
@Template(new Context { Index = index++, Item = item, });
@Template(new Context { Index = index++, Item = item, })
}
</ol>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<button id="tick" @onclick="Tick">Tick</button>
<button id="tock" @onclick="Tock">Tock</button>
@code {
private TaskCompletionSource<object?> _tcs = new TaskCompletionSource<object?>();
private readonly TaskCompletionSource<object?> _tcs = new TaskCompletionSource<object?>();
public int Counter;

private Task Tick()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div class="my-component" style="width: 5%">
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
{
registeredTask = task;
delegatedTask = task == null ? null : DelegateTo(task);
RenderWhenDone();
_ = RenderWhenDone();
}

base.OnParametersSet();
}

private async void RenderWhenDone()
private async Task RenderWhenDone()
{
var task = delegatedTask;
if (task != null)
Expand All @@ -44,7 +44,7 @@

private static async Task<object?> DelegateTo(Task task)
{
await task;//.ConfigureAwait(false);
await task;
return null;
}
}
7 changes: 5 additions & 2 deletions tests/bunit.testassets/SampleComponents/RenderOnClick.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

@code {
public int RenderCount { get; private set; }

void IncreaseCount() { }

void IncreaseCount()
{
// Left empty on purpose
}

protected override void OnAfterRender(bool firstRender) => RenderCount++;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@code {
protected override void OnInitialized()
{
var localizedString = StringLocalizer["StringName"];
_ = StringLocalizer["StringName"];
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@typeparam T
@foreach (var d in Data)
{
@Template?.Invoke(d);
@Template?.Invoke(d)
}
@code
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
<p>Read the details carefully!</p>
}
<details id="details-toggle" @ontoggle="OnToggle">
<details id="details-toggle" @ontoggle="@OnToggle">
<summary>Summary</summary>
<p>Detailed content</p>
</details>
Expand Down
8 changes: 2 additions & 6 deletions tests/bunit.web.tests/Asserting/MarkupMatchesTests.razor
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
@using Bunit.TestAssets
@using Bunit.TestAssets.SampleComponents
@inherits TestContext
@code {
private readonly ITestOutputHelper outputHelper;

public MarkupMatchesTests(ITestOutputHelper outputHelper)
public MarkupMatchesTests()
{
this.outputHelper = outputHelper;
TestContext.DefaultWaitTimeout = TimeSpan.FromSeconds(30);
DefaultWaitTimeout = TimeSpan.FromSeconds(30);
}

[Fact]
Expand Down
Loading
Loading