Skip to content
Open
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
24 changes: 12 additions & 12 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net11.0'">
<PackageVersion Include="Microsoft.Extensions.Logging" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="11.0.0-preview.6.26359.118"/>

<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="11.0.0-preview.6.26359.118"/>

<PackageVersion Include="System.Text.Json" Version="11.0.0-preview.6.26359.118"/>
<PackageVersion Include="Microsoft.Extensions.Logging" Version="11.0.0-rc.1.26425.128"/>
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="11.0.0-rc.1.26425.128"/>
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="11.0.0-rc.1.26425.128"/>

<PackageVersion Include="Microsoft.AspNetCore.Components.Authorization" Version="11.0.0-rc.1.26425.128"/>
<PackageVersion Include="Microsoft.Extensions.Localization.Abstractions" Version="11.0.0-rc.1.26425.128"/>
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="11.0.0-rc.1.26425.128"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="11.0.0-rc.1.26425.128"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="11.0.0-rc.1.26425.128"/>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="11.0.0-rc.1.26425.128"/>

<PackageVersion Include="System.Text.Json" Version="11.0.0-rc.1.26425.128"/>
</ItemGroup>

<ItemGroup Label="Test Dependencies">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Components.Web.Virtualization;
using System.Diagnostics;
using System.Reflection;
using Microsoft.AspNetCore.Components.Web.Virtualization;

namespace Bunit.JSInterop.InvocationHandlers.Implementation;

Expand Down Expand Up @@ -35,10 +35,15 @@ internal VirtualizeJSRuntimeInvocationHandler()
/// <inheritdoc/>
protected internal override Task<Microsoft.JSInterop.Infrastructure.IJSVoidResult> HandleAsync(JSRuntimeInvocation invocation)
{
if (!invocation.Identifier.Equals(JsFunctionsPrefix + "dispose", StringComparison.Ordinal))
if (!invocation.Identifier.Equals(JsFunctionsPrefix + "dispose", StringComparison.Ordinal) &&
!invocation.Identifier.Equals(JsFunctionsPrefix + "refreshObservers", StringComparison.Ordinal))
{
Debug.Assert(invocation.Identifier.Equals(JsFunctionsPrefix + "init", StringComparison.Ordinal));
#if NET11_0_OR_GREATER
Debug.Assert(invocation.Arguments.Count == 4);
#else
Debug.Assert(invocation.Arguments.Count == 3);
#endif
Debug.Assert(invocation.Arguments[0] is not null);

InvokeOnSpacerBeforeVisible(invocation.Arguments[0]!);
Expand All @@ -58,7 +63,12 @@ private static void InvokeOnSpacerBeforeVisible(object dotNetObjectReference)
0f, /* spacerSize */
0f, /* spacerSeparation */
1_000_000_000f, /* containerSize - very large number to ensure all items are loaded at once */
#if NET11_0_OR_GREATER
0, /* UserScroll <see cref="SpacerVisibilityReason" /> */
#endif
Comment thread
vnbaaij marked this conversation as resolved.

};

onSpacerBeforeVisibleMethodInfo.Invoke(virtualizeJsInterop, parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public BunitAuthenticationStateProvider(
IEnumerable<string>? roles = null,
IEnumerable<Claim>? claims = null,
string? authenticationType = null)
=> SetAuthenticatedState(userName, roles, claims, authenticationType);
{
AuthenticationStateChanged += OnAuthenticationStateChanged;
SetAuthenticatedState(userName, roles, claims, authenticationType);
}

/// <summary>
/// Initializes a new instance of the <see cref="BunitAuthenticationStateProvider"/> class.
Expand Down Expand Up @@ -135,4 +138,13 @@ private static AuthenticationState CreateUnauthenticationState()
var principal = new ClaimsPrincipal(new ClaimsIdentity());
return new AuthenticationState(principal);
}

#pragma warning disable AsyncFixer03 // Fire-and-forget async-void methods or delegates
private async void OnAuthenticationStateChanged(Task<AuthenticationState> task)
#pragma warning restore AsyncFixer03 // Fire-and-forget async-void methods or delegates
{
// Exists just to prevent BL0013 'BunitAuthenticationStateProvider' calls GetAuthenticationStateAsync on AuthenticationStateProvider
// without subscribing to the AuthenticationStateChanged event. This may result in using stale authentication state.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
namespace Bunit.TestDoubles;

/// <summary>
/// Root authorization service that manages different authentication/authorization state
/// in the system.
/// Root authorization service that manages different authentication/authorization state in the system.
/// </summary>
public class BunitAuthorizationContext
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<OutputType>Exe</OutputType>
</PropertyGroup>

<PropertyGroup>
<!--
<!--
Because of a CVE in System.Text.Json we get NU1903.
As this is a test project, we can ignore this warning for the time being.
-->
Expand Down
2 changes: 1 addition & 1 deletion tests/bunit.testassets/BlazorE2E/ElementRefComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@

async Task MakeInteropCall()
{
await JSRuntime.InvokeVoidAsync("setElementValue", _myInput, $"Clicks: {++_count}");
await JSRuntime.InvokeVoidAsync("setElementValue", _myInput, $"Clicks: {++_count}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ public class MultipleStateHasChangedInOnParametersSet : ComponentBase
[Parameter]
public int Value { get; set; }

#pragma warning disable BL0012
protected override void OnParametersSet()
{
base.OnParametersSet();
StateHasChanged();
StateHasChanged();
StateHasChanged();
}
#pragma warning restore BL0012
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
}
</AuthorizeView>

@code {
string userName = "";
string? userEmail = "";
string? userId = "";
bool hasUserEmail => userEmail != null;
bool hasUserId => userId != null;
@code {
string userName = "";
string? userEmail = "";
string? userId = "";
bool hasUserEmail => userEmail != null;
bool hasUserId => userId != null;

protected override async Task OnParametersSetAsync()
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
userName = state?.User?.Identity?.Name ?? string.Empty;
userEmail = state?.User?.FindFirst(ClaimTypes.Email)?.Value;
userId = state?.User?.FindFirst(ClaimTypes.Sid)?.Value;
}
protected override async Task OnParametersSetAsync()
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
userName = state?.User?.Identity?.Name ?? string.Empty;
userEmail = state?.User?.FindFirst(ClaimTypes.Email)?.Value;
userId = state?.User?.FindFirst(ClaimTypes.Sid)?.Value;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject HttpClient HttpClient
@inject HttpClient HttpClient


<h3>SimpleWithHttpClient</h3>
Expand All @@ -7,6 +7,5 @@
protected override async Task OnInitializedAsync()
{
await HttpClient.GetAsync("/api/weather");
StateHasChanged();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@inject IJSRuntime jsRuntime
@inject IJSRuntime jsRuntime
<p>@name</p>
@code{
string name = string.Empty;
Expand All @@ -7,8 +7,14 @@
{
if (firstRender)
{
name = await jsRuntime.InvokeAsync<string>("getdata");
StateHasChanged();
try {
name = await jsRuntime.InvokeAsync<string>("getdata");
StateHasChanged();
}
catch (Exception ex)
{
Console.WriteLine($"Error invoking JS: {ex.Message}");
}
}
}
}
}
3 changes: 2 additions & 1 deletion tests/bunit.testassets/bunit.testassets.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
Expand All @@ -11,6 +11,7 @@
<IsTestProject>false</IsTestProject>
<EmitCompilerGeneratedFiles>false</EmitCompilerGeneratedFiles>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<NoWarn>BL0013;BL0016</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions tests/bunit.tests/bunit.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<RootNamespace>Bunit</RootNamespace>
<AssemblyName>Bunit.Tests</AssemblyName>
<NoWarn>BL0016</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\bunit\bunit.csproj" />
<ProjectReference Include="..\..\src\bunit\bunit.csproj" />
<ProjectReference Include="..\bunit.testassets\bunit.testassets.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="../xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>