Skip to content

How to invoke AddTestAuthorization() when writing Tests in Razor Syntax? #271

Answered by egil
roysurles asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @roysurles

Thanks for reporting this. You are not doing anything wrong, its a small mistake in the extension method that registers the fake auth in BETA-11.

Here is a workaround for now:

<Fixture Test="CanAddFakeAuthToContextx" Description="Fake Auth can be added to Fixture">
	<ComponentUnderTest>
		<SimpleAuthView />
	</ComponentUnderTest>

	@code
	{
		void CanAddFakeAuthToContextx(Fixture fixture)
		{
			fixture.RenderTree.TryAdd<Microsoft.AspNetCore.Components.Authorization.CascadingAuthenticationState>();
			var authCtx = new TestAuthorizationContext();
			authCtx.SetNotAuthorized();
			authCtx.RegisterAuthorizationServices(fixture.Services);
			authCtx.SetAuthorized("TestUser", Au…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@roysurles
Comment options

Answer selected by egil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants