Skip to content

Commit

Permalink
Update ut ProblemDetailsHandler_UnauthorizedHttpStatusCode_RedirectTo…
Browse files Browse the repository at this point in the history
…LoginSnackBarIsCreatedAndProblemDetailsExceptionIsThrown
  • Loading branch information
hocinehacherouf committed Jul 18, 2023
1 parent 721d021 commit 763ff34
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -152,7 +153,9 @@ public async Task ProblemDetailsHandler_UnauthorizedHttpStatusCode_RedirectToLog
var httpClient = new HttpClient(problemDetailsHandler)
{
BaseAddress = new Uri("http://fake.com")
};
};

var mudSnackbarProvider = RenderComponent<MudSnackbarProvider>();

// Act
var result = () => httpClient.GetStringAsync("");
Expand All @@ -161,14 +164,16 @@ public async Task ProblemDetailsHandler_UnauthorizedHttpStatusCode_RedirectToLog
var exceptionAssertions = await result.Should().ThrowAsync<ProblemDetailsException>();
_ = 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="));
}
}
}

0 comments on commit 763ff34

Please sign in to comment.