rename: prefix gateway projects/namespaces with ZB.MOM.WW + sln→slnx
Apply the ZB.MOM.WW. prefix to all gateway-side projects, folders,
.csproj/.sln contents, C# namespaces, using directives, generated proto
C# (csharp_namespace + checked-in generated files), InternalsVisibleTo
attributes, project-name string literals (LoadProject, .sln lookups,
worker exe paths, staticwebassets manifest), and the install/script/doc
references that point at any of the above. Migrate the solution from
.sln to .slnx via `dotnet sln migrate` and delete the old file.
External-runtime identifiers are intentionally NOT prefixed so external
configuration keeps working:
- GatewayMetrics.cs MeterName ("MxGateway.Server")
- DashboardAuthenticationDefaults Scheme/Policy ("MxGateway.Dashboard")
- GatewayRequestLoggingMiddleware logger category ("MxGateway.Request")
- StaRuntime thread name ("MxGateway.Worker.STA")
- appsettings.json root section "MxGateway" + env-var prefix
MxGateway__... and secret-name MxGateway:ApiKeyPepper
- C:\ProgramData\MxGateway\ data dir paths
Also fixes two tests that were not rename-related but became visible
while validating the rename:
- WorkerLiveMxAccessSmokeTests.ShutDownAsync: cancellation that the
gateway service correctly maps to RpcException(Cancelled) per gRPC
convention was being misclassified as a stream fault. Added a sibling
catch on RpcException with StatusCode.Cancelled.
- IntegrationTestEnvironment.ResolveRepositoryRoot: extracted IsRepositoryRoot
and made it accept either a .git marker OR a .sln/.slnx next to src/
so the worker-exe walker works in non-git working copies.
clients/proto/proto-inputs.json's protoRoot updated to point at
src/ZB.MOM.WW.MxGateway.Contracts/Protos.
Verified by `dotnet build` and a full `dotnet test` of the .slnx with
MXGATEWAY_RUN_LIVE_{MXACCESS,LDAP,GALAXY}_TESTS=1:
Tests: 472/472 pass
Worker.Tests: 280/280 pass (4 dev-rig [Fact(Skip=...)] skipped)
IntegrationTests: 18/18 pass
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||
using ZB.MOM.WW.MxGateway.Worker.MxAccess;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Worker.Tests.MxAccess;
|
||||
|
||||
public sealed class MxAccessEventMapperTests
|
||||
{
|
||||
private readonly MxAccessEventMapper mapper = new();
|
||||
|
||||
/// <summary>Verifies that creating an OnDataChange event converts value, timestamp, quality, and statuses.</summary>
|
||||
[Fact]
|
||||
public void CreateOnDataChange_ConvertsValueTimestampQualityAndStatuses()
|
||||
{
|
||||
DateTime timestamp = new(2026, 4, 26, 12, 30, 0, DateTimeKind.Utc);
|
||||
FakeStatus[] statuses =
|
||||
{
|
||||
new()
|
||||
{
|
||||
success = -1,
|
||||
category = 0,
|
||||
detectedBy = 5,
|
||||
detail = 0,
|
||||
},
|
||||
};
|
||||
|
||||
MxEvent mxEvent = mapper.CreateOnDataChange(
|
||||
"session-1",
|
||||
serverHandle: 12,
|
||||
itemHandle: 34,
|
||||
value: 42,
|
||||
quality: 192,
|
||||
timestamp: timestamp,
|
||||
statuses: statuses);
|
||||
|
||||
Assert.Equal(MxEventFamily.OnDataChange, mxEvent.Family);
|
||||
Assert.Equal("session-1", mxEvent.SessionId);
|
||||
Assert.Equal(12, mxEvent.ServerHandle);
|
||||
Assert.Equal(34, mxEvent.ItemHandle);
|
||||
Assert.Equal(42, mxEvent.Value.Int32Value);
|
||||
Assert.Equal(192, mxEvent.Quality);
|
||||
Assert.Equal(timestamp, mxEvent.SourceTimestamp.ToDateTime());
|
||||
Assert.Equal(MxEvent.BodyOneofCase.OnDataChange, mxEvent.BodyCase);
|
||||
|
||||
MxStatusProxy status = Assert.Single(mxEvent.Statuses);
|
||||
Assert.Equal(-1, status.Success);
|
||||
Assert.Equal(MxStatusCategory.Ok, status.Category);
|
||||
Assert.Equal(MxStatusSource.RespondingAutomationObject, status.DetectedBy);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that OnWriteComplete and OperationComplete events preserve distinct families.</summary>
|
||||
[Fact]
|
||||
public void CreateOnWriteCompleteAndOperationComplete_PreservesDistinctFamilies()
|
||||
{
|
||||
MxEvent writeComplete = mapper.CreateOnWriteComplete(
|
||||
"session-1",
|
||||
serverHandle: 1,
|
||||
itemHandle: 2,
|
||||
statuses: Array.Empty<FakeStatus>());
|
||||
MxEvent operationComplete = mapper.CreateOperationComplete(
|
||||
"session-1",
|
||||
serverHandle: 1,
|
||||
itemHandle: 2,
|
||||
statuses: Array.Empty<FakeStatus>());
|
||||
|
||||
Assert.Equal(MxEventFamily.OnWriteComplete, writeComplete.Family);
|
||||
Assert.Equal(MxEvent.BodyOneofCase.OnWriteComplete, writeComplete.BodyCase);
|
||||
Assert.Equal(MxEventFamily.OperationComplete, operationComplete.Family);
|
||||
Assert.Equal(MxEvent.BodyOneofCase.OperationComplete, operationComplete.BodyCase);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that OnBufferedDataChange events preserve raw data type and array metadata.</summary>
|
||||
[Fact]
|
||||
public void CreateOnBufferedDataChange_PreservesRawDataTypeAndArrayMetadata()
|
||||
{
|
||||
DateTime firstTimestamp = new(2026, 4, 26, 13, 0, 0, DateTimeKind.Utc);
|
||||
DateTime secondTimestamp = new(2026, 4, 26, 13, 1, 0, DateTimeKind.Utc);
|
||||
|
||||
MxEvent mxEvent = mapper.CreateOnBufferedDataChange(
|
||||
"session-1",
|
||||
serverHandle: 10,
|
||||
itemHandle: 20,
|
||||
rawDataType: 2,
|
||||
value: new[] { 7, 8 },
|
||||
quality: new[] { 192, 0 },
|
||||
timestamp: new[] { firstTimestamp, secondTimestamp },
|
||||
statuses: null);
|
||||
|
||||
Assert.Equal(MxEventFamily.OnBufferedDataChange, mxEvent.Family);
|
||||
Assert.Equal(MxDataType.Integer, mxEvent.OnBufferedDataChange.DataType);
|
||||
Assert.Equal(2, mxEvent.OnBufferedDataChange.RawDataType);
|
||||
Assert.Equal(MxDataType.Integer, mxEvent.Value.ArrayValue.ElementDataType);
|
||||
Assert.Equal(new[] { 7, 8 }, mxEvent.Value.ArrayValue.Int32Values.Values);
|
||||
Assert.Equal(new[] { 192, 0 }, mxEvent.OnBufferedDataChange.QualityValues.Int32Values.Values);
|
||||
Assert.Equal(2, mxEvent.OnBufferedDataChange.TimestampValues.TimestampValues.Values.Count);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that MapMxDataType maps raw MXAccess data types to protobuf enum values.</summary>
|
||||
/// <param name="rawDataType">Raw MXAccess data type value to map.</param>
|
||||
/// <param name="expectedDataType">Expected MxDataType enum value.</param>
|
||||
[Theory]
|
||||
[InlineData(-1, MxDataType.Unknown)]
|
||||
[InlineData(0, MxDataType.NoData)]
|
||||
[InlineData(1, MxDataType.Boolean)]
|
||||
[InlineData(2, MxDataType.Integer)]
|
||||
[InlineData(6, MxDataType.Time)]
|
||||
[InlineData(15, MxDataType.InternationalizedString)]
|
||||
[InlineData(999, MxDataType.Unknown)]
|
||||
public void MapMxDataType_MapsInstalledMxAccessValues(
|
||||
int rawDataType,
|
||||
MxDataType expectedDataType)
|
||||
{
|
||||
Assert.Equal(expectedDataType, MxAccessEventMapper.MapMxDataType(rawDataType));
|
||||
}
|
||||
|
||||
/// <summary>Verifies CreateOnAlarmTransition packs the full alarm payload.</summary>
|
||||
[Fact]
|
||||
public void CreateOnAlarmTransition_PopulatesFullPayload()
|
||||
{
|
||||
DateTime raise = new(2026, 5, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
DateTime ack = raise.AddSeconds(45);
|
||||
|
||||
MxEvent mxEvent = mapper.CreateOnAlarmTransition(
|
||||
sessionId: "session-1",
|
||||
alarmFullReference: "Tank01.Level.HiHi",
|
||||
sourceObjectReference: "Tank01",
|
||||
alarmTypeName: "AnalogLimitAlarm.HiHi",
|
||||
transitionKind: AlarmTransitionKind.Acknowledge,
|
||||
severity: 750,
|
||||
originalRaiseTimestampUtc: raise,
|
||||
transitionTimestampUtc: ack,
|
||||
operatorUser: "alice",
|
||||
operatorComment: "investigating",
|
||||
category: "Process",
|
||||
description: "Tank 01 high-high level",
|
||||
statuses: null);
|
||||
|
||||
Assert.Equal(MxEventFamily.OnAlarmTransition, mxEvent.Family);
|
||||
Assert.Equal(MxEvent.BodyOneofCase.OnAlarmTransition, mxEvent.BodyCase);
|
||||
|
||||
OnAlarmTransitionEvent body = mxEvent.OnAlarmTransition;
|
||||
Assert.Equal("Tank01.Level.HiHi", body.AlarmFullReference);
|
||||
Assert.Equal("Tank01", body.SourceObjectReference);
|
||||
Assert.Equal("AnalogLimitAlarm.HiHi", body.AlarmTypeName);
|
||||
Assert.Equal(AlarmTransitionKind.Acknowledge, body.TransitionKind);
|
||||
Assert.Equal(750, body.Severity);
|
||||
Assert.Equal(raise, body.OriginalRaiseTimestamp.ToDateTime());
|
||||
Assert.Equal(ack, body.TransitionTimestamp.ToDateTime());
|
||||
Assert.Equal("alice", body.OperatorUser);
|
||||
Assert.Equal("investigating", body.OperatorComment);
|
||||
Assert.Equal("Process", body.Category);
|
||||
Assert.Equal("Tank 01 high-high level", body.Description);
|
||||
}
|
||||
|
||||
/// <summary>Verifies CreateOnAlarmTransition handles a Raise transition with no operator metadata.</summary>
|
||||
[Fact]
|
||||
public void CreateOnAlarmTransition_RaiseTransitionLeavesOperatorFieldsEmpty()
|
||||
{
|
||||
DateTime raise = new(2026, 5, 1, 12, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
MxEvent mxEvent = mapper.CreateOnAlarmTransition(
|
||||
sessionId: "session-1",
|
||||
alarmFullReference: "Tank01.Level.HiHi",
|
||||
sourceObjectReference: "Tank01",
|
||||
alarmTypeName: "AnalogLimitAlarm.HiHi",
|
||||
transitionKind: AlarmTransitionKind.Raise,
|
||||
severity: 750,
|
||||
originalRaiseTimestampUtc: null,
|
||||
transitionTimestampUtc: raise,
|
||||
operatorUser: string.Empty,
|
||||
operatorComment: string.Empty,
|
||||
category: "Process",
|
||||
description: "Tank 01 high-high level",
|
||||
statuses: null);
|
||||
|
||||
Assert.Equal(AlarmTransitionKind.Raise, mxEvent.OnAlarmTransition.TransitionKind);
|
||||
Assert.Equal(string.Empty, mxEvent.OnAlarmTransition.OperatorUser);
|
||||
Assert.Equal(string.Empty, mxEvent.OnAlarmTransition.OperatorComment);
|
||||
Assert.Null(mxEvent.OnAlarmTransition.OriginalRaiseTimestamp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that an OnDataChange whose timestamp arrives as the
|
||||
/// VT_BSTR string MXAccess actually delivers still populates
|
||||
/// <see cref="MxEvent.SourceTimestamp"/> — the string is parsed as
|
||||
/// local time and converted to UTC.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void CreateOnDataChange_WithMxAccessStringTimestamp_SetsSourceTimestamp()
|
||||
{
|
||||
// The exact shape MXAccess fires (see captures/003-subscribe-scalars).
|
||||
const string mxAccessTimestamp = "3/26/2026 1:38:22.907 PM";
|
||||
|
||||
MxEvent mxEvent = mapper.CreateOnDataChange(
|
||||
"session-1",
|
||||
serverHandle: 1,
|
||||
itemHandle: 1,
|
||||
value: 99,
|
||||
quality: 192,
|
||||
timestamp: mxAccessTimestamp,
|
||||
statuses: null);
|
||||
|
||||
Assert.NotNull(mxEvent.SourceTimestamp);
|
||||
|
||||
DateTime localWall = new(2026, 3, 26, 13, 38, 22, 907, DateTimeKind.Unspecified);
|
||||
DateTime expectedUtc = DateTime.SpecifyKind(localWall, DateTimeKind.Local).ToUniversalTime();
|
||||
Assert.Equal(expectedUtc, mxEvent.SourceTimestamp.ToDateTime());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the MXAccess timestamp string is interpreted as the host's
|
||||
/// local time and returned as UTC. Written timezone-independently by
|
||||
/// round-tripping a local wall-clock time.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TryParseSourceTimestamp_InterpretsStringAsLocalTime()
|
||||
{
|
||||
DateTime localWall = new(2026, 5, 21, 13, 43, 26, DateTimeKind.Unspecified);
|
||||
string text = localWall.ToString(CultureInfo.CurrentCulture);
|
||||
|
||||
Assert.True(MxAccessEventMapper.TryParseSourceTimestamp(text, out DateTime utc));
|
||||
Assert.Equal(DateTimeKind.Utc, utc.Kind);
|
||||
|
||||
DateTime expectedUtc = DateTime.SpecifyKind(localWall, DateTimeKind.Local).ToUniversalTime();
|
||||
Assert.Equal(expectedUtc, utc);
|
||||
}
|
||||
|
||||
/// <summary>Verifies unparseable or empty timestamp input is rejected without throwing.</summary>
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("not a timestamp")]
|
||||
public void TryParseSourceTimestamp_RejectsUnparseableInput(string? text)
|
||||
{
|
||||
Assert.False(MxAccessEventMapper.TryParseSourceTimestamp(text, out _));
|
||||
}
|
||||
|
||||
private sealed class FakeStatus
|
||||
{
|
||||
public int success;
|
||||
public int category;
|
||||
public int detectedBy;
|
||||
public int detail;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user