-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathInjectAuthServiceTest.cs
More file actions
38 lines (32 loc) · 1.04 KB
/
InjectAuthServiceTest.cs
File metadata and controls
38 lines (32 loc) · 1.04 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
28
29
30
31
32
33
34
35
36
37
38
using Bunit.TestDoubles.Authorization;
using System;
using Xunit;
namespace Bunit.Docs.Samples
{
public class InjectAuthServiceTest
{
[Fact(DisplayName = "Use AuthenticationStateProvider service with authenticated and authorized user")]
public void Test001()
{
// arrange
using var ctx = new TestContext();
var authContext = ctx.Services.AddTestAuthorization();
authContext.SetAuthorized("TestUserName", AuthorizationState.Authorized);
// act
var cut = ctx.RenderComponent<InjectAuthService>();
// assert
Assert.Contains("<p>User: TestUserName</p>", cut.Markup, StringComparison.InvariantCulture);
}
[Fact(DisplayName = "Use AuthenticationStateProvider service with unauthenticated and unauthorized user")]
public void Test002()
{
// arrange
using var ctx = new TestContext();
var authContext = ctx.Services.AddTestAuthorization();
// act
var cut = ctx.RenderComponent<InjectAuthService>();
// assert
Assert.DoesNotContain("User:", cut.Markup, StringComparison.InvariantCulture);
}
}
}