public void RendersAuthorizingUntilAuthorizationCompleted() { // Arrange var @event = new ManualResetEventSlim(); var authorizationService = new TestAuthorizationService(); authorizationService.NextResult = AuthorizationResult.Success(); var renderer = CreateTestRenderer(authorizationService); renderer.OnUpdateDisplayComplete = () => { @event.Set(); }; var rootComponent = WrapInAuthorizeView( authorizing: builder => builder.AddContent(0, "Auth pending..."), authorized: context => builder => builder.AddContent(0, $"Hello, {context.User.Identity.Name}!")); var authTcs = new TaskCompletionSource <AuthenticationState>(); rootComponent.AuthenticationState = authTcs.Task; // Act/Assert 1: Auth pending renderer.AssignRootComponentId(rootComponent); rootComponent.TriggerRender(); var batch1 = renderer.Batches.Single(); var authorizeViewComponentId = batch1.GetComponentFrames <AuthorizeView>().Single().ComponentId; var diff1 = batch1.DiffsByComponentId[authorizeViewComponentId].Single(); Assert.Collection(diff1.Edits, edit => { Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type); AssertFrame.Text( batch1.ReferenceFrames[edit.ReferenceFrameIndex], "Auth pending..."); }); // Act/Assert 2: Auth process completes asynchronously @event.Reset(); authTcs.SetResult(CreateAuthenticationState("Monsieur").Result); // We need to wait here because the continuations of SetResult will be scheduled to run asynchronously. @event.Wait(Timeout); Assert.Equal(2, renderer.Batches.Count); var batch2 = renderer.Batches[1]; var diff2 = batch2.DiffsByComponentId[authorizeViewComponentId].Single(); Assert.Collection(diff2.Edits, edit => { Assert.Equal(RenderTreeEditType.RemoveFrame, edit.Type); Assert.Equal(0, edit.SiblingIndex); }, edit => { Assert.Equal(RenderTreeEditType.PrependFrame, edit.Type); Assert.Equal(0, edit.SiblingIndex); AssertFrame.Text( batch2.ReferenceFrames[edit.ReferenceFrameIndex], "Hello, Monsieur!"); }); // Assert: The IAuthorizationService was given expected criteria Assert.Collection(authorizationService.AuthorizeCalls, call => { Assert.Equal("Monsieur", call.user.Identity.Name); Assert.Null(call.resource); Assert.Collection(call.requirements, req => Assert.IsType <DenyAnonymousAuthorizationRequirement>(req)); }); }
public static void Attribute(RenderTreeFrame frame, string attributeName, Action <object> attributeValidator, int?sequence = null) { AssertFrame.Attribute(frame, attributeName, sequence); attributeValidator(frame.AttributeValue); }
public static void ComponentWithInstance <T>(RenderTreeFrame frame, int componentId, int?subtreeLength = null, int?sequence = null) where T : IComponent { AssertFrame.Component <T>(frame, subtreeLength, sequence); Assert.IsType <T>(frame.Component); Assert.Equal(componentId, frame.ComponentId); }
public static void Attribute(RenderTreeFrame frame, string attributeName, object attributeValue, int?sequence = null) { AssertFrame.Attribute(frame, attributeName, sequence); Assert.Equal(attributeValue, frame.AttributeValue); }
public static void Attribute(RenderTreeFrame frame, string attributeName, Type valueType, int?sequence = null) { AssertFrame.Attribute(frame, attributeName, sequence); Assert.IsType(valueType, frame.AttributeValue); }
public static void Attribute(RenderTreeFrame frame, string attributeName, Action <UIEventArgs> attributeEventHandlerValue, int?sequence = null) { AssertFrame.Attribute(frame, attributeName, sequence); Assert.Equal(attributeEventHandlerValue, frame.AttributeValue); }
public static void Attribute(RenderTreeFrame frame, string attributeName, int?sequence = null) { Assert.Equal(RenderTreeFrameType.Attribute, frame.FrameType); Assert.Equal(attributeName, frame.AttributeName); AssertFrame.Sequence(frame, sequence); }
public static void ComponentReferenceCapture(RenderTreeFrame frame, Action <object> action, int?sequence = null) { Assert.Equal(RenderTreeFrameType.ComponentReferenceCapture, frame.FrameType); Assert.Same(action, frame.ComponentReferenceCaptureAction); AssertFrame.Sequence(frame, sequence); }
public static void Whitespace(RenderTreeFrame frame, int?sequence = null) { Assert.Equal(RenderTreeFrameType.Text, frame.FrameType); AssertFrame.Sequence(frame, sequence); Assert.True(string.IsNullOrWhiteSpace(frame.TextContent)); }
public static void Region(RenderTreeFrame frame, int subtreeLength, int?sequence = null) { Assert.Equal(RenderTreeFrameType.Region, frame.FrameType); Assert.Equal(subtreeLength, frame.RegionSubtreeLength); AssertFrame.Sequence(frame, sequence); }