refactor(auditlog): consolidate AuditEvent DTO mappers into Communication
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using Akka.TestKit.Xunit2;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ScadaLink.AuditLog.Tests.Integration.Infrastructure;
|
||||
using ScadaLink.AuditLog.Telemetry;
|
||||
using ScadaLink.Commons.Entities.Audit;
|
||||
using ScadaLink.Commons.Messages.Integration;
|
||||
using ScadaLink.Commons.Types;
|
||||
@@ -55,7 +54,7 @@ public class CombinedTelemetryIdempotencyTests : TestKit, IClassFixture<MsSqlMig
|
||||
{
|
||||
var dto = new CachedTelemetryPacket
|
||||
{
|
||||
AuditEvent = AuditEventMapper.ToDto(new AuditEvent
|
||||
AuditEvent = AuditEventDtoMapper.ToDto(new AuditEvent
|
||||
{
|
||||
EventId = eventId,
|
||||
OccurredAtUtc = nowUtc,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using ScadaLink.AuditLog.Site.Telemetry;
|
||||
using ScadaLink.AuditLog.Telemetry;
|
||||
using ScadaLink.Commons.Interfaces.Services;
|
||||
using ScadaLink.Commons.Messages.Integration;
|
||||
using ScadaLink.Commons.Types;
|
||||
@@ -88,7 +87,7 @@ public sealed class CombinedTelemetryDispatcher : ICachedCallTelemetryForwarder
|
||||
{
|
||||
return new CachedTelemetryPacket
|
||||
{
|
||||
AuditEvent = AuditEventMapper.ToDto(telemetry.Audit),
|
||||
AuditEvent = AuditEventDtoMapper.ToDto(telemetry.Audit),
|
||||
Operational = ToOperationalDto(telemetry.Operational),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Akka.Actor;
|
||||
using ScadaLink.AuditLog.Site.Telemetry;
|
||||
using ScadaLink.AuditLog.Telemetry;
|
||||
using ScadaLink.Commons.Entities.Audit;
|
||||
using ScadaLink.Commons.Messages.Audit;
|
||||
using ScadaLink.Commons.Types;
|
||||
@@ -88,7 +87,7 @@ public sealed class DirectActorSiteStreamAuditClient : ISiteStreamAuditClient
|
||||
var events = new List<AuditEvent>(batch.Events.Count);
|
||||
foreach (var dto in batch.Events)
|
||||
{
|
||||
events.Add(AuditEventMapper.FromDto(dto));
|
||||
events.Add(AuditEventDtoMapper.FromDto(dto));
|
||||
}
|
||||
|
||||
// Ask the central actor; the reply carries the accepted EventIds.
|
||||
@@ -114,7 +113,7 @@ public sealed class DirectActorSiteStreamAuditClient : ISiteStreamAuditClient
|
||||
/// back into the proto ack.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses the shared <see cref="AuditEventMapper.FromDto"/> for the audit half;
|
||||
/// Uses the shared <see cref="AuditEventDtoMapper.FromDto"/> for the audit half;
|
||||
/// the SiteCall DTO is decoded inline because the AuditLog mapper does not
|
||||
/// (and should not) know about <see cref="SiteCallOperationalDto"/> — the
|
||||
/// production gRPC server (Bundle D) uses the same inline shape.
|
||||
@@ -132,7 +131,7 @@ public sealed class DirectActorSiteStreamAuditClient : ISiteStreamAuditClient
|
||||
var entries = new List<CachedTelemetryEntry>(batch.Packets.Count);
|
||||
foreach (var packet in batch.Packets)
|
||||
{
|
||||
var audit = AuditEventMapper.FromDto(packet.AuditEvent);
|
||||
var audit = AuditEventDtoMapper.FromDto(packet.AuditEvent);
|
||||
var siteCall = MapSiteCallFromDto(packet.Operational);
|
||||
entries.Add(new CachedTelemetryEntry(audit, siteCall));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ using Akka.Actor;
|
||||
using Akka.TestKit.Xunit2;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ScadaLink.AuditLog.Site.Telemetry;
|
||||
using ScadaLink.AuditLog.Telemetry;
|
||||
using ScadaLink.Commons.Entities.Audit;
|
||||
using ScadaLink.Commons.Messages.Audit;
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
@@ -46,7 +45,7 @@ public class ClusterClientSiteAuditClientTests : TestKit
|
||||
var batch = new AuditEventBatch();
|
||||
foreach (var e in events)
|
||||
{
|
||||
batch.Events.Add(AuditEventMapper.ToDto(e));
|
||||
batch.Events.Add(AuditEventDtoMapper.ToDto(e));
|
||||
}
|
||||
return batch;
|
||||
}
|
||||
@@ -158,7 +157,7 @@ public class ClusterClientSiteAuditClientTests : TestKit
|
||||
{
|
||||
batch.Packets.Add(new CachedTelemetryPacket
|
||||
{
|
||||
AuditEvent = AuditEventMapper.ToDto(e),
|
||||
AuditEvent = AuditEventDtoMapper.ToDto(e),
|
||||
Operational = NewOperationalDto(),
|
||||
});
|
||||
}
|
||||
@@ -190,7 +189,7 @@ public class ClusterClientSiteAuditClientTests : TestKit
|
||||
var batch = new CachedTelemetryBatch();
|
||||
batch.Packets.Add(new CachedTelemetryPacket
|
||||
{
|
||||
AuditEvent = AuditEventMapper.ToDto(NewEvent()),
|
||||
AuditEvent = AuditEventDtoMapper.ToDto(NewEvent()),
|
||||
Operational = NewOperationalDto(),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ScadaLink.AuditLog.Telemetry;
|
||||
using ScadaLink.Commons.Entities.Audit;
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
using ScadaLink.Communication.Grpc;
|
||||
|
||||
namespace ScadaLink.AuditLog.Tests.Telemetry;
|
||||
namespace ScadaLink.Communication.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Round-trip + edge tests for the <see cref="AuditEventMapper"/> that bridges
|
||||
/// Round-trip + edge tests for the <see cref="AuditEventDtoMapper"/> that bridges
|
||||
/// <see cref="AuditEvent"/> (Commons) ↔ <see cref="AuditEventDto"/> (proto).
|
||||
/// ForwardState is site-local and IngestedAtUtc is central-set, so neither survives
|
||||
/// the proto round-trip.
|
||||
/// </summary>
|
||||
public class AuditEventMapperTests
|
||||
public class AuditEventDtoMapperTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToDto_FromDto_Roundtrip_FullyPopulated_PreservesAllFields()
|
||||
@@ -47,8 +46,8 @@ public class AuditEventMapperTests
|
||||
ForwardState = AuditForwardState.Pending
|
||||
};
|
||||
|
||||
var dto = AuditEventMapper.ToDto(original);
|
||||
var roundTripped = AuditEventMapper.FromDto(dto);
|
||||
var dto = AuditEventDtoMapper.ToDto(original);
|
||||
var roundTripped = AuditEventDtoMapper.FromDto(dto);
|
||||
|
||||
Assert.Equal(original.EventId, roundTripped.EventId);
|
||||
Assert.Equal(original.OccurredAtUtc, roundTripped.OccurredAtUtc);
|
||||
@@ -88,7 +87,7 @@ public class AuditEventMapperTests
|
||||
// all string? fields left null; CorrelationId null
|
||||
};
|
||||
|
||||
var dto = AuditEventMapper.ToDto(evt);
|
||||
var dto = AuditEventDtoMapper.ToDto(evt);
|
||||
|
||||
Assert.Equal(string.Empty, dto.CorrelationId);
|
||||
Assert.Equal(string.Empty, dto.SourceSiteId);
|
||||
@@ -126,7 +125,7 @@ public class AuditEventMapperTests
|
||||
Extra = string.Empty
|
||||
};
|
||||
|
||||
var evt = AuditEventMapper.FromDto(dto);
|
||||
var evt = AuditEventDtoMapper.FromDto(dto);
|
||||
|
||||
Assert.Null(evt.CorrelationId);
|
||||
Assert.Null(evt.SourceSiteId);
|
||||
@@ -154,8 +153,8 @@ public class AuditEventMapperTests
|
||||
Status = AuditStatus.Delivered
|
||||
};
|
||||
|
||||
var dto = AuditEventMapper.ToDto(evt);
|
||||
var roundTripped = AuditEventMapper.FromDto(dto);
|
||||
var dto = AuditEventDtoMapper.ToDto(evt);
|
||||
var roundTripped = AuditEventDtoMapper.FromDto(dto);
|
||||
|
||||
Assert.Equal(DateTimeKind.Utc, roundTripped.OccurredAtUtc.Kind);
|
||||
Assert.Equal(occurredAt, roundTripped.OccurredAtUtc);
|
||||
@@ -175,7 +174,7 @@ public class AuditEventMapperTests
|
||||
DurationMs = null
|
||||
};
|
||||
|
||||
var dto = AuditEventMapper.ToDto(evt);
|
||||
var dto = AuditEventDtoMapper.ToDto(evt);
|
||||
|
||||
Assert.Null(dto.HttpStatus);
|
||||
Assert.Null(dto.DurationMs);
|
||||
@@ -197,7 +196,7 @@ public class AuditEventMapperTests
|
||||
Assert.Null(dto.HttpStatus);
|
||||
Assert.Null(dto.DurationMs);
|
||||
|
||||
var evt = AuditEventMapper.FromDto(dto);
|
||||
var evt = AuditEventDtoMapper.FromDto(dto);
|
||||
|
||||
Assert.Null(evt.HttpStatus);
|
||||
Assert.Null(evt.DurationMs);
|
||||
@@ -215,7 +214,7 @@ public class AuditEventMapperTests
|
||||
Status = AuditStatus.Parked
|
||||
};
|
||||
|
||||
var dto = AuditEventMapper.ToDto(evt);
|
||||
var dto = AuditEventDtoMapper.ToDto(evt);
|
||||
|
||||
Assert.Equal("ApiOutbound", dto.Channel);
|
||||
Assert.Equal("ApiCallCached", dto.Kind);
|
||||
Reference in New Issue
Block a user