<%# Copyright 2019-2025 the original author or authors from the JHipster project. This file is part of the JHipster project, see https://www.jhipster.tech/ for more information. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -%> using System.Collections.Generic; using System.Security.Claims; using Blazored.Modal.Services; using Bunit; using <%= namespace %>.Client.Pages; using <%= namespace %>.Client.Test.Helpers; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.DependencyInjection; using Moq; using Xunit; namespace <%= namespace %>.Client.Test; public class IndexTest : TestContext { [Fact] public void Should_CallSignInMethod_When_SignInWasClick() { //Arrange var modalService = new Mock(); Services.AddSingleton(modalService.Object); Services.AddMockUnAuthenticateAuthorization(); var authenticationStateProvider = Services.GetService(); var index = RenderComponent(ComponentParameterFactory.CascadingValue(authenticationStateProvider.GetAuthenticationStateAsync()), ComponentParameterFactory.CascadingValue(modalService.Object)); // Act index.Find(".alert-link").Click(); // Assert modalService.Verify(mock => mock.Show(It.IsAny()), Times.Once()); } [Fact] public void Should_DisplayUserLogin_When_UserIsAuthenticated() { //Arrange var modalService = new Mock(); Services.AddSingleton(modalService.Object); var claims = new List(); claims.Add(new Claim(ClaimTypes.NameIdentifier, "UserTestLogin")); var claimIdentity = new ClaimsIdentity(claims); Services.AddMockAuthenticatedAuthorization(claimIdentity); var authenticationStateProvider = Services.GetService(); var index = RenderComponent(ComponentParameterFactory.CascadingValue(authenticationStateProvider.GetAuthenticationStateAsync())); // Act var homeLoggedMessage = index.Find("#home-logged-message"); // Assert homeLoggedMessage.MarkupMatches(@"You are logged in as user ""UserTestLogin""."); } }