public void RenderComponent_InitialState_HasExpectedValues() { var title = "Operation Render Test Component"; var operationSteps = new List <OperationStep> { new OperationStep(1, "Step1", () => { return(Task.FromResult(true)); }) }; var component = BUnitTestContext.RenderComponent <OperationRender>(parameters => parameters .Add(c => c.OperationSteps, operationSteps) .Add(c => c.DisplayName, title) ); // check the initial component state component.Should().NotBeNull(); component.RenderCount.Should().Be(1); component.Instance.Should().NotBeNull(); component.Instance.Status.Should().Be(OperationStatus.NotStarted); component.Find("icon").GetAttribute("color").Should().BeEmpty(); component.Find("icon").GetAttribute("value").Should().BeEmpty(); component.Find(".operationStatus").TextContent.Should().Be(OperationStatus.NotStarted.ToString()); component.Find("progress").GetAttribute("class").Should().BeEmpty(); component.Find("progress").GetAttribute("displayText").Should().BeNull(); component.Find("progress").GetAttribute("value").As <decimal>().Should().Be(0M); component.Find(".propertyChanges").TextContent.As <int>().Should().Be(0); component.Find(".resultText").TextContent.Should().Be(component.Instance.DisplayText.NotStarted); component.Find("title").TextContent.Should().Be(title); component.Find("ul").Children.Count().Should().Be(1); component.Find("ul").Children.All(c => c.TextContent.Contains(OperationStatus.NotStarted.ToString())).Should().BeTrue(); }
public void BlazorBreakdanceTestBase_Setup_CreatesTestContext_ConflictingServices() { BUnitTestContext.Should().NotBeNull(); RegisterServices.Should().NotBeNull(); BUnitTestContext.Services.Should().HaveCount(14); GetService <NavigationManager>().Should().NotBeNull().And.BeOfType(typeof(FakeNavigationManager)); GetServices <NavigationManager>().Should().HaveCount(1); GetService <TestableNavigationManager>().Should().NotBeNull(); }
public void Wizard_CanCreateDefaultOperation() { var componentWithOperationParam = BUnitTestContext.RenderComponent <Wizard>(parameters => parameters .Add(c => c.Operation, new Operation("Operation Provided", null, "Success!", "Failure!")) ); componentWithOperationParam.Instance.Operation.Title.Should().Be("Operation Provided"); var componentWithNoOperationParam = BUnitTestContext.RenderComponent <Wizard>(); componentWithNoOperationParam.Instance.Operation.Title.Should().Be("Default Operation"); }
public void Wizard_InitialState_HasExpectedDefaults() { var component = BUnitTestContext.RenderComponent <Wizard>(); var wizard = component.Instance; wizard.Panes.Should().NotBeNull(); wizard.Operation.Should().NotBeNull(); wizard.Operation.Title.Should().NotBeNullOrEmpty(); wizard.IsBackEnabled.Should().BeFalse(); wizard.IsNextEnabled.Should().BeTrue(); wizard.IsNextVisible.Should().BeFalse(); wizard.IsOperationStartVisible.Should().BeFalse(); wizard.IsFinishVisible.Should().BeTrue(); }
public void Wizard_PaneMovement_HasExpectedProperties() { var component = BUnitTestContext.RenderComponent <WizardRender>(); var wizard = component.Instance.Wizard; wizard.Panes.Should().NotBeEmpty(); wizard.Operation.Should().NotBeNull(); wizard.Operation.Title.Should().NotBeNullOrEmpty(); wizard.IsBackEnabled.Should().BeFalse(); wizard.IsNextEnabled.Should().BeTrue(); wizard.IsNextVisible.Should().BeTrue(); wizard.IsOperationStartVisible.Should().BeFalse(); wizard.IsFinishVisible.Should().BeFalse(); // trigger move to next content pane and re-evaluate component.Instance.Next(); wizard.IsBackEnabled.Should().BeTrue(); wizard.IsNextEnabled.Should().BeTrue(); wizard.IsNextVisible.Should().BeFalse(); wizard.IsOperationStartVisible.Should().BeTrue(); wizard.IsFinishVisible.Should().BeFalse(); // trigger back and re-evaluate component.Instance.Back(); wizard.IsBackEnabled.Should().BeFalse(); wizard.IsNextEnabled.Should().BeTrue(); wizard.IsNextVisible.Should().BeTrue(); wizard.IsOperationStartVisible.Should().BeFalse(); wizard.IsFinishVisible.Should().BeFalse(); // trigger reset and re-evaluate component.Instance.Reset(); wizard.IsBackEnabled.Should().BeFalse(); wizard.IsNextEnabled.Should().BeTrue(); wizard.IsNextVisible.Should().BeTrue(); wizard.IsOperationStartVisible.Should().BeFalse(); wizard.IsFinishVisible.Should().BeFalse(); // trigger navigation to final panel (2 steps) and re-evaluate component.Instance.Next(); component.Instance.Next(); wizard.IsBackEnabled.Should().BeTrue(); wizard.IsNextEnabled.Should().BeTrue(); wizard.IsNextVisible.Should().BeFalse(); wizard.IsOperationStartVisible.Should().BeTrue(); wizard.IsFinishVisible.Should().BeFalse(); }
public void BlazorBreakdanceTestBase_TestSetup_CreatesTestContext_Services() { //RWM: We're not *quite* setting this up properly, because we want to test the state both before and after calling TestSetup(); TestHost.Should().BeNull(); BUnitTestContext.Should().BeNull(); RegisterServices.Should().BeNull(); RegisterServices = services => { services.AddScoped <NavigationManager>(sp => new TestableNavigationManager()); }; TestSetup(); TestHost.Should().NotBeNull(); BUnitTestContext.Should().NotBeNull(); RegisterServices.Should().NotBeNull(); BUnitTestContext.Services.Should().HaveCount(14); GetService <NavigationManager>().Should().NotBeNull().And.BeOfType(typeof(TestableNavigationManager)); GetServices <NavigationManager>().Should().HaveCount(2); }
public void BlazorBreakdanceTestBase_Setup_CreatesTestContext_NoServices() { //RWM: We're not *quite* setting this up properly, because we want to test the state both before and after calling TestSetup(); TestHost.Should().BeNull(); BUnitTestContext.Should().BeNull(); RegisterServices.Should().BeNull(); GetService <IConfiguration>().Should().BeNull(); TestSetup(); TestHost.Should().NotBeNull(); BUnitTestContext.Should().NotBeNull(); RegisterServices.Should().BeNull(); #if NET6_0_OR_GREATER TestHost.Services.GetAllServiceDescriptors().Should().HaveCount(33); #endif #if NET5_0 TestHost.Services.GetAllServiceDescriptors().Should().HaveCount(32); #endif BUnitTestContext.Services.Should().HaveCount(13); GetService <NavigationManager>().Should().NotBeNull().And.BeOfType(typeof(FakeNavigationManager)); BUnitTestContext.Services.GetService <IConfiguration>().Should().NotBeNull(); }
public void BlazorBreakdanceTestBase_GetServices_ReturnsServiceOnlyInTestContext() { //RWM: We're not *quite* setting this up properly, because we want to test the state both before and after calling TestSetup(); TestHost.Should().BeNull(); BUnitTestContext.Should().BeNull(); RegisterServices.Should().BeNull(); TestHostBuilder.ConfigureServices((context, services) => services.AddSingleton <DummyService>()); TestSetup(); TestHost.Should().NotBeNull(); BUnitTestContext.Should().NotBeNull(); RegisterServices.Should().BeNull(); BUnitTestContext.Services.Should().HaveCount(13); BUnitTestContext.Services.GetService <DummyService>().Should().BeNull(); #if NET6_0_OR_GREATER TestHost.Services.GetAllServiceDescriptors().Should().HaveCount(34); #endif #if NET5_0 TestHost.Services.GetAllServiceDescriptors().Should().HaveCount(33); #endif TestHost.Services.GetService <DummyService>().Should().NotBeNull(); GetService <DummyService>().Should().NotBeNull(); }
/// <summary> /// Disposes of the <see cref="BUnitTestContext"/>. /// </summary> public override void TestTearDown() { base.TestTearDown(); BUnitTestContext?.Dispose(); }
public void Operation_OnSuccess_HasExpectedValues() { var title = "Operation Render Test Component"; var canCompleteStep1 = false; var canCompleteStep2 = false; var operationSteps = new List <OperationStep> { new OperationStep(1, "Step 1", () => { SpinWait.SpinUntil(() => { return(canCompleteStep1); }, 30000); return(Task.FromResult(true)); }), new OperationStep(2, "Step 2", () => { SpinWait.SpinUntil(() => { return(canCompleteStep2); }, 30000); return(Task.FromResult(true)); }) }; var component = BUnitTestContext.RenderComponent <OperationRender>(parameters => parameters .Add(c => c.OperationSteps, operationSteps) .Add(c => c.DisplayName, title) ); // check the initial component state component.Should().NotBeNull(); component.RenderCount.Should().Be(1); component.Instance.Should().NotBeNull(); component.Instance.Status.Should().Be(OperationStatus.NotStarted); component.Find("icon").GetAttribute("color").Should().BeEmpty(); component.Find("icon").GetAttribute("value").Should().BeEmpty(); component.Find(".operationStatus").TextContent.Should().Be(OperationStatus.NotStarted.ToString()); component.Find("progress").GetAttribute("class").Should().BeEmpty(); component.Find("progress").GetAttribute("displayText").Should().BeNull(); component.Find("progress").GetAttribute("value").As <decimal>().Should().Be(0M); component.Find(".propertyChanges").TextContent.As <int>().Should().Be(0); component.Find(".resultText").TextContent.Should().Be(component.Instance.DisplayText.NotStarted); component.Find("title").TextContent.Should().Be(title); component.Find("ul").Children.Count().Should().Be(2); component.Find("ul").Children.All(c => c.TextContent.Contains(OperationStatus.NotStarted.ToString())).Should().BeTrue(); // start the operation component.Instance.Start(); var hasStartedOperation = SpinWait.SpinUntil(() => { return(component.Instance.Status == OperationStatus.InProgress); }, 30000); hasStartedOperation.Should().BeTrue(); // check for in-progress state (step 1) Thread.Sleep(500); // half-second pause for the properties to update before we check them component.Find("icon").GetAttribute("color").Should().Be("text-warning"); component.Find("icon").GetAttribute("value").Should().Be("fa-hourglass fa-pulse"); component.Find(".operationStatus").TextContent.Should().Be(OperationStatus.InProgress.ToString()); component.Find("progress").GetAttribute("class").Should().Be("bg-warning"); component.Find("progress").GetAttribute("displayText").Should().Be("Step 1"); component.Find("progress").GetAttribute("value").Should().Be("0.25"); component.Find(".propertyChanges").TextContent.Should().Be($"{component.RenderCount - 1}"); component.Find(".resultText").TextContent.Should().Be(component.Instance.DisplayText.InProgress); component.Find("ul").Children.FirstOrDefault(c => c.GetAttribute("id") == "step_1").TextContent.Contains(OperationStepStatus.InProgress.ToString()); component.Find("ul").Children.FirstOrDefault(c => c.GetAttribute("id") == "step_2").TextContent.Contains(OperationStepStatus.NotStarted.ToString()); // allow step 1 to complete canCompleteStep1 = true; canCompleteStep2 = true; // wait until the operation has completed var hasCompletedOperation = SpinWait.SpinUntil(() => { return(component.Instance.Status > OperationStatus.InProgress); }, 30000); hasCompletedOperation.Should().BeTrue(); // check the final state of the operation Thread.Sleep(500); // half-second pause for the properties to update before we check them component.Find("icon").GetAttribute("color").Should().Be("text-success"); component.Find("icon").GetAttribute("value").Should().Be("fa-thumbs-up"); component.Find(".operationStatus").TextContent.Should().Be(OperationStatus.Succeeded.ToString()); component.Find("progress").GetAttribute("class").Should().Be("bg-success"); component.Find("progress").GetAttribute("displayText").Should().BeEmpty(); component.Find("progress").GetAttribute("value").Should().Be("1"); component.Find(".propertyChanges").TextContent.Should().Be($"{component.RenderCount - 1}"); component.Find(".resultText").TextContent.Should().Be(component.Instance.DisplayText.Success); component.Find("ul").Children.All(c => c.TextContent.Contains(OperationStepStatus.Succeeded.ToString())).Should().BeTrue(); }