File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
src/bunit.web/TestDoubles/Authorization
tests/bunit.web.tests/TestDoubles/Authorization Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,9 @@ public static class FakeAuthorizationExtensions
1313 /// an authenticated user, as well as adding the <see cref="CascadingAuthenticationState"/> component to the
1414 /// test contexts render tree.
1515 /// </summary>
16- public static TestAuthorizationContext AddTestAuthorization ( this TestContext context )
16+ public static TestAuthorizationContext AddTestAuthorization ( this TestContextBase context )
1717 {
1818 context . RenderTree . TryAdd < CascadingAuthenticationState > ( ) ;
19-
2019 var authCtx = new TestAuthorizationContext ( ) ;
2120 authCtx . SetNotAuthorized ( ) ;
2221 authCtx . RegisterAuthorizationServices ( context . Services ) ;
Original file line number Diff line number Diff line change 1+ @inherits TestComponentBase
2+
3+ <Fixture Test =" CanAddFakeAuthToContext" Description =" Fake Auth can be added to Fixture" >
4+ <ComponentUnderTest >
5+ <SimpleAuthView />
6+ </ComponentUnderTest >
7+
8+ @code
9+ {
10+ void CanAddFakeAuthToContext (Fixture fixture )
11+ {
12+ var authContext = fixture .AddTestAuthorization ();
13+ authContext .SetAuthorized (" TestUser" , AuthorizationState .Authorized );
14+
15+ var cut = fixture .GetComponentUnderTest <SimpleAuthView >();
16+
17+ cut .MarkupMatches (" Authorized!" );
18+ }
19+ }
20+ </Fixture >
21+
22+ <SnapshotTest Setup =" SetupFakeAuthToContext" Description =" Fake Auth can be added to SnapshotTest" >
23+ <TestInput ><SimpleAuthView /></TestInput >
24+ <ExpectedOutput >Authorized!</ExpectedOutput >
25+
26+ @code
27+ {
28+ void SetupFakeAuthToContext (SnapshotTest ctx )
29+ {
30+ var authContext = ctx .AddTestAuthorization ();
31+ authContext .SetAuthorized (" TestUser" , AuthorizationState .Authorized );
32+ }
33+ }
34+ </SnapshotTest >
You can’t perform that action at this time.
0 commit comments