513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
78 lines
3.0 KiB
C#
78 lines
3.0 KiB
C#
using System.Security.Claims;
|
|
using Bunit;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Options;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Communication;
|
|
using ZB.MOM.WW.ScadaBridge.Security;
|
|
using SiteForm = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Admin.SiteForm;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Admin;
|
|
|
|
/// <summary>
|
|
/// Drill-in test for the Site edit page. The chip
|
|
/// routes operators into the central Audit Log pre-filtered by SourceSiteId =
|
|
/// Site.SiteIdentifier (the same string the audit pipeline stamps onto every
|
|
/// site-sourced row). Create mode suppresses the link — there's no site yet.
|
|
/// </summary>
|
|
public class SiteFormAuditDrillinTests : BunitContext
|
|
{
|
|
private readonly ISiteRepository _siteRepo = Substitute.For<ISiteRepository>();
|
|
private readonly CommunicationService _comms;
|
|
|
|
/// <summary>Initializes the test context with a stubbed site repository, communication service and an administrator identity.</summary>
|
|
public SiteFormAuditDrillinTests()
|
|
{
|
|
_comms = new CommunicationService(
|
|
Options.Create(new CommunicationOptions()),
|
|
NullLogger<CommunicationService>.Instance);
|
|
Services.AddSingleton(_siteRepo);
|
|
Services.AddSingleton(_comms);
|
|
|
|
var claims = new[]
|
|
{
|
|
new Claim(JwtTokenService.UsernameClaimType, "admin"),
|
|
new Claim(JwtTokenService.RoleClaimType, "Administrator"),
|
|
};
|
|
var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"));
|
|
Services.AddSingleton<AuthenticationStateProvider>(new TestAuthStateProvider(user));
|
|
Services.AddAuthorizationCore();
|
|
Services.AddTestConfigurationMutations();
|
|
AuthorizationPolicies.AddScadaBridgeAuthorization(Services);
|
|
}
|
|
|
|
/// <summary>Verifies that the edit page links to recent audit activity filtered by the site identifier.</summary>
|
|
[Fact]
|
|
public void EditPage_HasRecentAuditActivityLink_WithSiteEqualToSiteIdentifier()
|
|
{
|
|
_siteRepo.GetSiteByIdAsync(3, Arg.Any<CancellationToken>())
|
|
.Returns(new Site("Plant A", "plant-a") { Id = 3 });
|
|
|
|
var cut = Render<SiteForm>(p => p.Add(c => c.Id, 3));
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
var link = cut.Find("a[data-test=\"audit-link\"]");
|
|
Assert.Equal("/audit/log?site=plant-a", link.GetAttribute("href"));
|
|
Assert.Contains("Recent audit activity", link.TextContent);
|
|
});
|
|
}
|
|
|
|
/// <summary>Verifies that the create page shows no recent audit activity link.</summary>
|
|
[Fact]
|
|
public void CreatePage_HasNoRecentAuditActivityLink()
|
|
{
|
|
var cut = Render<SiteForm>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Assert.Empty(cut.FindAll("a[data-test=\"audit-link\"]"));
|
|
});
|
|
}
|
|
}
|