diff --git a/Directory.Packages.props b/Directory.Packages.props
index 56664c00a..e1a2009d4 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -72,18 +72,18 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/bunit/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs b/src/bunit/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs
index 2fb2abd73..a771cd259 100644
--- a/src/bunit/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs
+++ b/src/bunit/JSInterop/InvocationHandlers/Implementation/VirtualizeJSRuntimeInvocationHandler.cs
@@ -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;
@@ -35,10 +35,15 @@ internal VirtualizeJSRuntimeInvocationHandler()
///
protected internal override Task 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]!);
@@ -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 */
+#endif
+
};
+
onSpacerBeforeVisibleMethodInfo.Invoke(virtualizeJsInterop, parameters);
}
}
diff --git a/src/bunit/TestDoubles/Authorization/BunitAuthenticationStateProvider.cs b/src/bunit/TestDoubles/Authorization/BunitAuthenticationStateProvider.cs
index 83afac68e..a29a89bf4 100644
--- a/src/bunit/TestDoubles/Authorization/BunitAuthenticationStateProvider.cs
+++ b/src/bunit/TestDoubles/Authorization/BunitAuthenticationStateProvider.cs
@@ -24,7 +24,10 @@ public BunitAuthenticationStateProvider(
IEnumerable? roles = null,
IEnumerable? claims = null,
string? authenticationType = null)
- => SetAuthenticatedState(userName, roles, claims, authenticationType);
+ {
+ AuthenticationStateChanged += OnAuthenticationStateChanged;
+ SetAuthenticatedState(userName, roles, claims, authenticationType);
+ }
///
/// Initializes a new instance of the class.
@@ -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 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.
+
+ }
}
diff --git a/src/bunit/TestDoubles/Authorization/BunitAuthorizationContext.cs b/src/bunit/TestDoubles/Authorization/BunitAuthorizationContext.cs
index 25942ac0a..90febd8a8 100644
--- a/src/bunit/TestDoubles/Authorization/BunitAuthorizationContext.cs
+++ b/src/bunit/TestDoubles/Authorization/BunitAuthorizationContext.cs
@@ -5,8 +5,7 @@
namespace Bunit.TestDoubles;
///
-/// Root authorization service that manages different authentication/authorization state
-/// in the system.
+/// Root authorization service that manages different authentication/authorization state in the system.
///
public class BunitAuthorizationContext
{
diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props
index cf491ca78..0b5093695 100644
--- a/tests/Directory.Build.props
+++ b/tests/Directory.Build.props
@@ -14,9 +14,9 @@
true
Exe
-
+
-
diff --git a/tests/bunit.testassets/BlazorE2E/ElementRefComponent.razor b/tests/bunit.testassets/BlazorE2E/ElementRefComponent.razor
index b3f52d69d..bbaefb042 100644
--- a/tests/bunit.testassets/BlazorE2E/ElementRefComponent.razor
+++ b/tests/bunit.testassets/BlazorE2E/ElementRefComponent.razor
@@ -31,6 +31,6 @@
async Task MakeInteropCall()
{
- await JSRuntime.InvokeVoidAsync("setElementValue", _myInput, $"Clicks: {++_count}");
+ await JSRuntime.InvokeVoidAsync("setElementValue", _myInput, $"Clicks: {++_count}");
}
}
diff --git a/tests/bunit.testassets/SampleComponents/MultipleStateHasChangedInOnParametersSet.cs b/tests/bunit.testassets/SampleComponents/MultipleStateHasChangedInOnParametersSet.cs
index 5e64874da..29ef33356 100644
--- a/tests/bunit.testassets/SampleComponents/MultipleStateHasChangedInOnParametersSet.cs
+++ b/tests/bunit.testassets/SampleComponents/MultipleStateHasChangedInOnParametersSet.cs
@@ -5,6 +5,7 @@ public class MultipleStateHasChangedInOnParametersSet : ComponentBase
[Parameter]
public int Value { get; set; }
+#pragma warning disable BL0012
protected override void OnParametersSet()
{
base.OnParametersSet();
@@ -12,5 +13,6 @@ protected override void OnParametersSet()
StateHasChanged();
StateHasChanged();
}
+#pragma warning restore BL0012
}
diff --git a/tests/bunit.testassets/SampleComponents/SimpleAuthViewWithClaims.razor b/tests/bunit.testassets/SampleComponents/SimpleAuthViewWithClaims.razor
index d889342d0..9e821bc95 100644
--- a/tests/bunit.testassets/SampleComponents/SimpleAuthViewWithClaims.razor
+++ b/tests/bunit.testassets/SampleComponents/SimpleAuthViewWithClaims.razor
@@ -15,18 +15,18 @@
}
-@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;
+ }
}
diff --git a/tests/bunit.testassets/SampleComponents/SimpleWithHttpClient.razor b/tests/bunit.testassets/SampleComponents/SimpleWithHttpClient.razor
index b3ec30bf0..97468e805 100644
--- a/tests/bunit.testassets/SampleComponents/SimpleWithHttpClient.razor
+++ b/tests/bunit.testassets/SampleComponents/SimpleWithHttpClient.razor
@@ -1,4 +1,4 @@
-@inject HttpClient HttpClient
+@inject HttpClient HttpClient
SimpleWithHttpClient
@@ -7,6 +7,5 @@
protected override async Task OnInitializedAsync()
{
await HttpClient.GetAsync("/api/weather");
- StateHasChanged();
}
}
diff --git a/tests/bunit.testassets/SampleComponents/SimpleWithJSRuntimeDep.razor b/tests/bunit.testassets/SampleComponents/SimpleWithJSRuntimeDep.razor
index 4c8f6d1d0..76949690b 100644
--- a/tests/bunit.testassets/SampleComponents/SimpleWithJSRuntimeDep.razor
+++ b/tests/bunit.testassets/SampleComponents/SimpleWithJSRuntimeDep.razor
@@ -1,4 +1,4 @@
-@inject IJSRuntime jsRuntime
+@inject IJSRuntime jsRuntime
@name
@code{
string name = string.Empty;
@@ -7,8 +7,14 @@
{
if (firstRender)
{
- name = await jsRuntime.InvokeAsync("getdata");
- StateHasChanged();
+ try {
+ name = await jsRuntime.InvokeAsync("getdata");
+ StateHasChanged();
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error invoking JS: {ex.Message}");
+ }
}
}
-}
\ No newline at end of file
+}
diff --git a/tests/bunit.testassets/bunit.testassets.csproj b/tests/bunit.testassets/bunit.testassets.csproj
index 305d09964..46b7a8fc8 100644
--- a/tests/bunit.testassets/bunit.testassets.csproj
+++ b/tests/bunit.testassets/bunit.testassets.csproj
@@ -1,4 +1,4 @@
-
+
net8.0;net9.0;net10.0;net11.0
@@ -11,6 +11,7 @@
false
false
true
+ BL0013;BL0016
diff --git a/tests/bunit.tests/bunit.tests.csproj b/tests/bunit.tests/bunit.tests.csproj
index 638453b1a..ada564e14 100644
--- a/tests/bunit.tests/bunit.tests.csproj
+++ b/tests/bunit.tests/bunit.tests.csproj
@@ -4,15 +4,16 @@
net8.0;net9.0;net10.0;net11.0
Bunit
Bunit.Tests
+ BL0016
-
+
-
+
\ No newline at end of file