feat(audit)!: ScadaBridge C3 — swap to canonical ZB.MOM.WW.Audit.AuditEvent across seams/emitters/DTO/redactor wiring; transitional 24-col storage shim (Task 2.5)

This commit is contained in:
Joseph Doherty
2026-06-02 12:37:50 -04:00
parent 5aaf9e2923
commit db707bb0de
127 changed files with 2240 additions and 3886 deletions
@@ -2,8 +2,8 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using ZB.MOM.WW.Audit;
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Audit;
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Health;
using ZB.MOM.WW.ScadaBridge.Commons.Types;
@@ -36,18 +36,31 @@ public class AuditLogQueryServiceTests
var repo = Substitute.For<IAuditLogRepository>();
var filter = new AuditLogQueryFilter(Channels: new[] { AuditChannel.ApiOutbound });
var paging = new AuditLogPaging(PageSize: 25);
var expected = new List<AuditEvent>
// C3 (Task 2.5): the repository returns canonical ZB.MOM.WW.Audit.AuditEvent rows;
// the service decomposes each into a flat AuditEventView for the UI.
var eventId = Guid.NewGuid();
var repoRows = new List<AuditEvent>
{
new() { EventId = Guid.NewGuid(), OccurredAtUtc = DateTime.UtcNow, Channel = AuditChannel.ApiOutbound, Kind = AuditKind.ApiCall, Status = AuditStatus.Delivered }
ScadaBridgeAuditEventFactory.Create(
channel: AuditChannel.ApiOutbound,
kind: AuditKind.ApiCall,
status: AuditStatus.Delivered,
eventId: eventId),
};
repo.QueryAsync(filter, paging, Arg.Any<CancellationToken>())
.Returns(Task.FromResult<IReadOnlyList<AuditEvent>>(expected));
.Returns(Task.FromResult<IReadOnlyList<AuditEvent>>(repoRows));
var sut = new AuditLogQueryService(repo, EmptyAggregator());
var result = await sut.QueryAsync(filter, paging);
Assert.Same(expected, result);
// The service projects canonical → AuditEventView (a new list), so assert on
// the decomposed content rather than reference identity.
var view = Assert.Single(result);
Assert.Equal(eventId, view.EventId);
Assert.Equal(AuditChannel.ApiOutbound, view.Channel);
Assert.Equal(AuditKind.ApiCall, view.Kind);
Assert.Equal(AuditStatus.Delivered, view.Status);
await repo.Received(1).QueryAsync(filter, paging, Arg.Any<CancellationToken>());
}