diff --git a/EstateManagementUI.BlazorServer.Tests/Pages/CounterPageTests.cs b/EstateManagementUI.BlazorServer.Tests/Pages/CounterPageTests.cs deleted file mode 100644 index 8769a007..00000000 --- a/EstateManagementUI.BlazorServer.Tests/Pages/CounterPageTests.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Bunit; -using EstateManagementUI.BlazorServer.Components.Pages; -using Shouldly; - -namespace EstateManagementUI.BlazorServer.Tests.Pages; - -public class CounterPageTests : TestContext -{ - [Fact] - public void Counter_RendersCorrectly() - { - // Act - var cut = RenderComponent(); - - // Assert - cut.Find("h1").TextContent.ShouldBe("Counter"); - cut.Find("p[role='status']").TextContent.ShouldBe("Current count: 0"); - cut.Find("button").TextContent.Trim().ShouldBe("Click me"); - } - - [Fact] - public void Counter_IncrementButton_IncrementsCount() - { - // Arrange - var cut = RenderComponent(); - var button = cut.Find("button"); - - // Act - button.Click(); - - // Assert - cut.Find("p[role='status']").TextContent.ShouldBe("Current count: 1"); - } - - [Fact] - public void Counter_MultipleClicks_IncrementsCorrectly() - { - // Arrange - var cut = RenderComponent(); - var button = cut.Find("button"); - - // Act - button.Click(); - button.Click(); - button.Click(); - - // Assert - cut.Find("p[role='status']").TextContent.ShouldBe("Current count: 3"); - } - - [Fact] - public void Counter_HasCorrectPageTitle() - { - // Act - var cut = RenderComponent(); - - // Assert - var pageTitle = cut.FindComponent(); - pageTitle.Instance.ChildContent.ShouldNotBeNull(); - } -} diff --git a/EstateManagementUI.BlazorServer/Components/Layout/RoleSwitcher.razor b/EstateManagementUI.BlazorServer/Components/Layout/RoleSwitcher.razor index bcdd88f4..40d082d6 100644 --- a/EstateManagementUI.BlazorServer/Components/Layout/RoleSwitcher.razor +++ b/EstateManagementUI.BlazorServer/Components/Layout/RoleSwitcher.razor @@ -5,7 +5,7 @@ @inject IPermissionService PermissionService @inject IPermissionKeyProvider PermissionKeyProvider -@if (isTestMode) +@if (testMode == TestMode.Full || testMode == TestMode.AuthenticationOnly) {
- -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/EstateManagementUI.BlazorServer/Program.cs b/EstateManagementUI.BlazorServer/Program.cs index 4db12e7b..3d25ea30 100644 --- a/EstateManagementUI.BlazorServer/Program.cs +++ b/EstateManagementUI.BlazorServer/Program.cs @@ -66,7 +66,10 @@ JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); // Check if running in test mode -var testMode = builder.Configuration.GetValue("AppSettings:TestMode", false); +var testModeConfig = builder.Configuration.GetValue("AppSettings:TestMode", "Disabled"); +// Convert to enum +var testMode = Enum.Parse(testModeConfig, ignoreCase: true); + Console.WriteLine($"Application running in Test Mode: {testMode}"); // Add services to the container. @@ -83,7 +86,7 @@ }); // Configure authentication based on mode -if (testMode) +if (testMode == TestMode.AuthenticationOnly || testMode == TestMode.Full) { // Test mode: Use test authentication handler to bypass OIDC builder.Services.AddAuthentication(options => @@ -167,6 +170,7 @@ NameClaimType = "name", RoleClaimType = "role" }; + options.ClaimActions.MapAllExcept("iss", "nbf", "exp", "aud", "nonce", "iat", "c_hash"); // Set MetadataAddress to use the authority address options.MetadataAddress = $"{authorityAddress}/.well-known/openid-configuration"; @@ -200,7 +204,7 @@ Console.WriteLine("Registered Permission services"); // Register MediatR service based on test mode -if (testMode) +if (testMode == TestMode.BackedByTestDataStore || testMode == TestMode.Full) { Console.WriteLine("Registering TestMediatorService with in-memory test data store"); builder.Services.AddSingleton(); @@ -236,13 +240,19 @@ .AddInteractiveServerRenderMode(); // Add login endpoint - behavior depends on test mode -if (testMode) +if (testMode == TestMode.AuthenticationOnly || testMode == TestMode.Full) { app.MapGet("/login", (HttpContext context) => { // In test mode, redirect directly to home since authentication is automatic return Results.Redirect("/"); }).AllowAnonymous(); + + app.MapGet("/logout", (HttpContext context) => + { + // In test mode, just redirect to home + return Results.Redirect("/"); + }).RequireAuthorization(); } else { @@ -260,19 +270,7 @@ authenticationSchemes: new[] { OpenIdConnectDefaults.AuthenticationScheme } ); }).AllowAnonymous(); -} -// Add logout endpoint - behavior depends on test mode -if (testMode) -{ - app.MapGet("/logout", (HttpContext context) => - { - // In test mode, just redirect to home - return Results.Redirect("/"); - }).RequireAuthorization(); -} -else -{ app.MapGet("/logout", async (HttpContext context) => { await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme); @@ -282,3 +280,11 @@ } app.Run(); + + +enum TestMode { + Disabled, + AuthenticationOnly, + BackedByTestDataStore, + Full +} \ No newline at end of file diff --git a/EstateManagementUI.BlazorServer/appsettings.json b/EstateManagementUI.BlazorServer/appsettings.json index f5f9ebc1..6a3cdd4c 100644 --- a/EstateManagementUI.BlazorServer/appsettings.json +++ b/EstateManagementUI.BlazorServer/appsettings.json @@ -9,13 +9,13 @@ "AppSettings": { "SecurityServiceLocalPort": null, "SecurityServicePort": null, - "HttpClientIgnoreCertificateErrors": false, - "TestMode": true + "HttpClientIgnoreCertificateErrors": false, + "TestMode": "BackedByTestDataStore" }, "Authentication": { "Authority": "https://localhost:5001", - "ClientId": "estateUIClient", - "ClientSecret": "Secret1", + "ClientId": "managementUIClient", + "ClientSecret": "d192cbc46d834d0da90e8a9d50ded543", "CallbackPath": "/signin-oidc", "ResponseType": "code id_token", "Scopes": [