-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathBunitAuthorizationExtensions.cs
More file actions
25 lines (23 loc) · 1012 Bytes
/
BunitAuthorizationExtensions.cs
File metadata and controls
25 lines (23 loc) · 1012 Bytes
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
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();
Services.AddSingleton<BunitSignOutSessionStateManager>();
#pragma warning disable CS0618
Services.AddSingleton<SignOutSessionStateManager>(s => s.GetRequiredService<BunitSignOutSessionStateManager>());
#pragma warning restore CS0618
var authCtx = new BunitAuthorizationContext(Services);
return authCtx;
}
}