From f81d7ce79df1b8367f4368cae5f622bd7319daaf Mon Sep 17 00:00:00 2001 From: Joao Rua Date: Fri, 19 Apr 2024 09:14:48 +0100 Subject: [PATCH] login refactor --- .../Components/LoginTestFixture.cs | 17 +++--- COMET.Web.Common/Components/Login.razor | 13 +++-- COMET.Web.Common/Components/Login.razor.cs | 25 ++++----- .../AuthenticationService.cs | 56 ++++++------------- .../IAuthenticationService.cs | 7 ++- .../ViewModels/Components/ILoginViewModel.cs | 12 +++- .../ViewModels/Components/LoginViewModel.cs | 38 +++++++++---- 7 files changed, 84 insertions(+), 84 deletions(-) diff --git a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs index 2111230a..e46b4bd8 100644 --- a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs @@ -36,6 +36,8 @@ namespace COMET.Web.Common.Tests.Components using COMET.Web.Common.Test.Helpers; using COMET.Web.Common.ViewModels.Components; + using FluentResults; + using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Web; using Microsoft.Extensions.DependencyInjection; @@ -143,8 +145,7 @@ public async Task VerifyPerformLogin() var renderer = this.context.RenderComponent(); var editForm = renderer.FindComponent(); - this.authenticationService.Setup(x => x.Login(It.IsAny())) - .ReturnsAsync(AuthenticationStateKind.ServerFail); + this.authenticationService.Setup(x => x.Login(It.IsAny())).ReturnsAsync(Result.Ok); Assert.That(renderer.Instance.FieldsFocusedStatus, Is.EqualTo(new Dictionary() { @@ -158,22 +159,20 @@ public async Task VerifyPerformLogin() Assert.Multiple(() => { Assert.That(renderer.Instance.LoginButtonDisplayText, Is.EqualTo("Retry")); - Assert.That(renderer.Instance.ErrorMessage, Is.Not.Null); + Assert.That(renderer.Instance.ErrorMessages, Is.Not.Null); }); - this.authenticationService.Setup(x => x.Login(It.IsAny())) - .ReturnsAsync(AuthenticationStateKind.Fail); + this.authenticationService.Setup(x => x.Login(It.IsAny())).ReturnsAsync(Result.Ok); await renderer.InvokeAsync(editForm.Instance.OnValidSubmit.InvokeAsync); Assert.Multiple(() => { Assert.That(renderer.Instance.LoginButtonDisplayText, Is.EqualTo("Retry")); - Assert.That(renderer.Instance.ErrorMessage, Is.Not.Null); + Assert.That(renderer.Instance.ErrorMessages, Is.Not.Null); }); - this.authenticationService.Setup(x => x.Login(It.IsAny())) - .ReturnsAsync(AuthenticationStateKind.Success); + this.authenticationService.Setup(x => x.Login(It.IsAny())).ReturnsAsync(Result.Ok); this.viewModel.AuthenticationDto.SourceAddress = "http://localhost.com"; this.viewModel.AuthenticationDto.UserName = "user"; @@ -184,7 +183,7 @@ public async Task VerifyPerformLogin() Assert.Multiple(() => { Assert.That(renderer.Instance.LoginButtonDisplayText, Is.EqualTo("Connecting")); - Assert.That(renderer.Instance.ErrorMessage, Is.Empty); + Assert.That(renderer.Instance.ErrorMessages, Is.Empty); }); } } diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index b4ab8275..68a7bc3a 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -87,11 +87,16 @@ } - @if (!string.IsNullOrEmpty(this.ErrorMessage)) + @if (this.ErrorMessages.Any()) { -
- -
+
+
    + @foreach (var errrorMessage in this.ErrorMessages) + { +
  • @errrorMessage
  • + } +
+
}