-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathBunitAuthorizationExtensions.cs
More file actions
27 lines (25 loc) · 1.02 KB
/
BunitAuthorizationExtensions.cs
File metadata and controls
27 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using Bunit.TestDoubles;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
namespace Bunit;
public partial class BunitContext
{
/// <summary>
/// Adds the appropriate Blazor authentication and authorization services to the <see cref="BunitServiceProvider"/> to enable
/// an authenticated user, as well as adding the <see cref="CascadingAuthenticationState"/> component to the
/// test contexts render tree.
/// </summary>
[RemovedInFutureVersion("SignOutSessionStateManager should be removed from the container.")]
public BunitAuthorizationContext AddAuthorization()
{
Services.AddCascadingAuthenticationState();
#if !NET11_0_OR_GREATER
Services.AddSingleton<BunitSignOutSessionStateManager>();
#pragma warning disable CS0618
Services.AddSingleton<SignOutSessionStateManager>(s => s.GetRequiredService<BunitSignOutSessionStateManager>());
#pragma warning restore CS0618
#endif
var authCtx = new BunitAuthorizationContext(Services);
return authCtx;
}
}