From 763ff34e5f7ad2e39a8c680e745f7420e822bf9c Mon Sep 17 00:00:00 2001 From: Hocine Hacherouf Date: Tue, 18 Jul 2023 21:12:20 +0200 Subject: [PATCH] Update ut ProblemDetailsHandler_UnauthorizedHttpStatusCode_RedirectToLoginSnackBarIsCreatedAndProblemDetailsExceptionIsThrown --- .../Handlers/ProblemDetailsHandlerTests.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/IoTHub.Portal.Tests.Unit/Client/Handlers/ProblemDetailsHandlerTests.cs b/src/IoTHub.Portal.Tests.Unit/Client/Handlers/ProblemDetailsHandlerTests.cs index b6e2391e2..a113c6611 100644 --- a/src/IoTHub.Portal.Tests.Unit/Client/Handlers/ProblemDetailsHandlerTests.cs +++ b/src/IoTHub.Portal.Tests.Unit/Client/Handlers/ProblemDetailsHandlerTests.cs @@ -21,6 +21,7 @@ namespace IoTHub.Portal.Tests.Unit.Client.Handlers using Microsoft.Extensions.DependencyInjection; using MudBlazor; using System.Linq; + using Bunit; [TestFixture] public class ProblemDetailsHandlerTests : BlazorUnitTest @@ -152,7 +153,9 @@ public async Task ProblemDetailsHandler_UnauthorizedHttpStatusCode_RedirectToLog var httpClient = new HttpClient(problemDetailsHandler) { BaseAddress = new Uri("http://fake.com") - }; + }; + + var mudSnackbarProvider = RenderComponent(); // Act var result = () => httpClient.GetStringAsync(""); @@ -161,14 +164,16 @@ public async Task ProblemDetailsHandler_UnauthorizedHttpStatusCode_RedirectToLog var exceptionAssertions = await result.Should().ThrowAsync(); _ = exceptionAssertions.Which.ProblemDetailsWithExceptionDetails.Should().BeEquivalentTo(problemDetailsWithExceptionDetails); - var snackBars = snackBarService.ShownSnackbars.ToList(); - - _ = snackBars.Count.Should().Be(1); + _ = snackBarService.ShownSnackbars.Count().Should().Be(1); - var errorSnackBar = snackBars.First(); + var errorSnackBar = snackBarService.ShownSnackbars.First(); _ = errorSnackBar.Severity.Should().Be(Severity.Error); - _ = errorSnackBar.Message.Should().Be("You are not authorized"); + _ = errorSnackBar.Message.Should().Be("You are not authorized"); + + mudSnackbarProvider.Find("button").Click(); + + mudSnackbarProvider.WaitForAssertion(() => this.mockNavigationManager.Uri.Should().EndWith("/authentication/login?returnUrl=")); } } }