Phase 0 — mechanical rename ZB.MOM.WW.LmxOpcUa.* → ZB.MOM.WW.OtOpcUa.*

Renames all 11 projects (5 src + 6 tests), the .slnx solution file, all source-file namespaces, all axaml namespace references, and all v1 documentation references in CLAUDE.md and docs/*.md (excluding docs/v2/ which is already in OtOpcUa form). Also updates the TopShelf service registration name from "LmxOpcUa" to "OtOpcUa" per Phase 0 Task 0.6.

Preserves runtime identifiers per Phase 0 Out-of-Scope rules to avoid breaking v1/v2 client trust during coexistence: OPC UA `ApplicationUri` defaults (`urn:{GalaxyName}:LmxOpcUa`), server `EndpointPath` (`/LmxOpcUa`), `ServerName` default (feeds cert subject CN), `MxAccessConfiguration.ClientName` default (defensive — stays "LmxOpcUa" for MxAccess audit-trail consistency), client OPC UA identifiers (`ApplicationName = "LmxOpcUaClient"`, `ApplicationUri = "urn:localhost:LmxOpcUaClient"`, cert directory `%LocalAppData%\LmxOpcUaClient\pki\`), and the `LmxOpcUaServer` class name (class rename out of Phase 0 scope per Task 0.5 sed pattern; happens in Phase 1 alongside `LmxNodeManager → GenericDriverNodeManager` Core extraction). 23 LmxOpcUa references retained, all enumerated and justified in `docs/v2/implementation/exit-gate-phase-0.md`.

Build clean: 0 errors, 30 warnings (lower than baseline 167). Tests at strict improvement over baseline: 821 passing / 1 failing vs baseline 820 / 2 (one flaky pre-existing failure passed this run; the other still fails — both pre-existing and unrelated to the rename). `Client.UI.Tests`, `Historian.Aveva.Tests`, `Client.Shared.Tests`, `IntegrationTests` all match baseline exactly. Exit gate compliance results recorded in `docs/v2/implementation/exit-gate-phase-0.md` with all 7 checks PASS or DEFERRED-to-PR-review (#7 service install verification needs Windows service permissions on the reviewer's box).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-04-17 13:57:47 -04:00
parent 5b8d708c58
commit 3b2defd94f
293 changed files with 841 additions and 722 deletions

View File

@@ -0,0 +1,416 @@
using System.Collections.Generic;
using System.Linq;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Configuration;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
namespace ZB.MOM.WW.OtOpcUa.Tests.Domain
{
/// <summary>
/// Exhaustive coverage of the template-based alarm object filter's pattern parsing,
/// chain matching, and hierarchy-subtree propagation logic.
/// </summary>
public class AlarmObjectFilterTests
{
// ---------- Pattern parsing & compilation ----------
[Fact]
public void EmptyConfig_DisablesFilter()
{
var sut = new AlarmObjectFilter(new AlarmFilterConfiguration());
sut.Enabled.ShouldBeFalse();
sut.PatternCount.ShouldBe(0);
sut.ResolveIncludedObjects(SingleObject()).ShouldBeNull();
}
[Fact]
public void NullConfig_DisablesFilter()
{
var sut = new AlarmObjectFilter(null);
sut.Enabled.ShouldBeFalse();
sut.ResolveIncludedObjects(SingleObject()).ShouldBeNull();
}
[Fact]
public void WhitespaceEntries_AreSkipped()
{
var sut = new AlarmObjectFilter(Config("", " ", "\t"));
sut.Enabled.ShouldBeFalse();
sut.PatternCount.ShouldBe(0);
}
[Fact]
public void CommaSeparatedEntry_SplitsIntoMultiplePatterns()
{
var sut = new AlarmObjectFilter(Config("TestMachine*, Pump_*"));
sut.Enabled.ShouldBeTrue();
sut.PatternCount.ShouldBe(2);
}
[Fact]
public void CommaAndListForms_Combine()
{
var sut = new AlarmObjectFilter(Config("A*, B*", "C*"));
sut.PatternCount.ShouldBe(3);
}
[Fact]
public void WhitespaceAroundCommas_IsTrimmed()
{
var sut = new AlarmObjectFilter(Config(" TestMachine* , Pump_* "));
sut.PatternCount.ShouldBe(2);
sut.MatchesTemplateChain(new List<string> { "TestMachine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "Pump_A" }).ShouldBeTrue();
}
[Fact]
public void LiteralPattern_MatchesExactTemplate()
{
var sut = new AlarmObjectFilter(Config("TestMachine"));
sut.MatchesTemplateChain(new List<string> { "TestMachine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "TestMachine_001" }).ShouldBeFalse();
sut.MatchesTemplateChain(new List<string> { "OtherMachine" }).ShouldBeFalse();
}
[Fact]
public void StarAlonePattern_MatchesAnyNonEmptyChain()
{
var sut = new AlarmObjectFilter(Config("*"));
sut.MatchesTemplateChain(new List<string> { "Foo" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "Bar", "Baz" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string>()).ShouldBeFalse();
}
[Fact]
public void PrefixWildcard_MatchesSuffix()
{
var sut = new AlarmObjectFilter(Config("*Machine"));
sut.MatchesTemplateChain(new List<string> { "TestMachine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "BigMachine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "MachineThing" }).ShouldBeFalse();
}
[Fact]
public void SuffixWildcard_MatchesPrefix()
{
var sut = new AlarmObjectFilter(Config("Test*"));
sut.MatchesTemplateChain(new List<string> { "TestMachine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "TestFoo" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "Machine" }).ShouldBeFalse();
}
[Fact]
public void BothWildcards_MatchesContains()
{
var sut = new AlarmObjectFilter(Config("*Machine*"));
sut.MatchesTemplateChain(new List<string> { "TestMachineWidget" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "Machine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "Pump" }).ShouldBeFalse();
}
[Fact]
public void MiddleWildcard_MatchesWithInnerAnything()
{
var sut = new AlarmObjectFilter(Config("Test*Machine"));
sut.MatchesTemplateChain(new List<string> { "TestMachine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "TestCoolMachine" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "TestMachineX" }).ShouldBeFalse();
}
[Fact]
public void RegexMetacharacters_AreEscapedLiterally()
{
// The '.' in Pump.v2 is a regex metachar; it must be a literal dot.
var sut = new AlarmObjectFilter(Config("Pump.v2"));
sut.MatchesTemplateChain(new List<string> { "Pump.v2" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "PumpXv2" }).ShouldBeFalse();
}
[Fact]
public void Matching_IsCaseInsensitive()
{
var sut = new AlarmObjectFilter(Config("testmachine*"));
sut.MatchesTemplateChain(new List<string> { "TestMachine_001" }).ShouldBeTrue();
sut.MatchesTemplateChain(new List<string> { "TESTMACHINE_XYZ" }).ShouldBeTrue();
}
[Fact]
public void GalaxyDollarPrefix_IsNormalizedAway_OnBothSides()
{
var sut = new AlarmObjectFilter(Config("TestMachine*"));
sut.MatchesTemplateChain(new List<string> { "$TestMachine" }).ShouldBeTrue();
var withDollarInPattern = new AlarmObjectFilter(Config("$TestMachine*"));
withDollarInPattern.MatchesTemplateChain(new List<string> { "$TestMachine" }).ShouldBeTrue();
withDollarInPattern.MatchesTemplateChain(new List<string> { "TestMachine" }).ShouldBeTrue();
}
// ---------- Template-chain matching ----------
[Fact]
public void ChainMatch_AtAncestorPosition_StillMatches()
{
var sut = new AlarmObjectFilter(Config("TestMachine"));
var chain = new List<string> { "TestCoolMachine", "TestMachine", "$UserDefined" };
sut.MatchesTemplateChain(chain).ShouldBeTrue();
}
[Fact]
public void ChainNoMatch_ReturnsFalse()
{
var sut = new AlarmObjectFilter(Config("TestMachine*"));
var chain = new List<string> { "FooBar", "$UserDefined" };
sut.MatchesTemplateChain(chain).ShouldBeFalse();
}
[Fact]
public void EmptyChain_NeverMatchesNonWildcard()
{
var sut = new AlarmObjectFilter(Config("TestMachine*"));
sut.MatchesTemplateChain(new List<string>()).ShouldBeFalse();
}
[Fact]
public void NullChain_NeverMatches()
{
var sut = new AlarmObjectFilter(Config("TestMachine*"));
sut.MatchesTemplateChain(null).ShouldBeFalse();
}
[Fact]
public void SystemTemplate_MatchesWhenOperatorOptsIn()
{
var sut = new AlarmObjectFilter(Config("Area*"));
sut.MatchesTemplateChain(new List<string> { "$Area" }).ShouldBeTrue();
}
[Fact]
public void DuplicateChainEntries_StillMatch()
{
var sut = new AlarmObjectFilter(Config("TestMachine"));
var chain = new List<string> { "TestMachine", "TestMachine", "$UserDefined" };
sut.MatchesTemplateChain(chain).ShouldBeTrue();
}
// ---------- Hierarchy subtree propagation ----------
[Fact]
public void FlatHierarchy_OnlyMatchingIdsIncluded()
{
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "TestMachine"),
Obj(2, parent: 0, template: "Pump"),
Obj(3, parent: 0, template: "TestMachine")
};
var sut = new AlarmObjectFilter(Config("TestMachine*"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.ShouldContain(1);
included.ShouldContain(3);
included.ShouldNotContain(2);
included.Count.ShouldBe(2);
}
[Fact]
public void MatchOnGrandparent_PropagatesToGrandchildren()
{
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "TestMachine"), // root matches
Obj(2, parent: 1, template: "UnrelatedThing"), // child — inherited
Obj(3, parent: 2, template: "UnrelatedOtherThing") // grandchild — inherited
};
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.ShouldBe(new[] { 1, 2, 3 }, ignoreOrder: true);
}
[Fact]
public void GrandchildMatch_DoesNotIncludeAncestors()
{
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "Unrelated"),
Obj(2, parent: 1, template: "Unrelated"),
Obj(3, parent: 2, template: "TestMachine")
};
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.ShouldBe(new[] { 3 });
}
[Fact]
public void OverlappingMatches_StillSingleInclude()
{
// Grandparent matches AND grandchild matches independently — grandchild still counted once.
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "TestMachine"),
Obj(2, parent: 1, template: "Widget"),
Obj(3, parent: 2, template: "TestMachine")
};
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.Count.ShouldBe(3);
included.ShouldContain(3);
}
[Fact]
public void SiblingSubtrees_OnlyMatchedSideIncluded()
{
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "TestMachine"), // match — left subtree
Obj(2, parent: 1, template: "Child"),
Obj(10, parent: 0, template: "Pump"), // no match — right subtree
Obj(11, parent: 10, template: "PumpChild")
};
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.ShouldBe(new[] { 1, 2 }, ignoreOrder: true);
}
// ---------- Defensive / edge cases ----------
[Fact]
public void OrphanObject_TreatedAsRoot()
{
// Object 2 claims parent 99 which isn't in the hierarchy — still reached as a root.
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(2, parent: 99, template: "TestMachine")
};
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.ShouldContain(2);
}
[Fact]
public void SyntheticCycle_TerminatesWithoutStackOverflow()
{
// A→B→A cycle defended by the visited set.
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 2, template: "TestMachine"),
Obj(2, parent: 1, template: "Widget")
};
var sut = new AlarmObjectFilter(Config("TestMachine"));
// No object has a ParentGobjectId of 0, and each references an id that exists —
// neither qualifies as a root under the orphan rule. Empty result is acceptable;
// the critical assertion is that the call returns without crashing.
var included = sut.ResolveIncludedObjects(hierarchy);
included.ShouldNotBeNull();
}
[Fact]
public void NullTemplateChain_TreatedAsEmpty()
{
var hierarchy = new List<GalaxyObjectInfo>
{
new() { GobjectId = 1, ParentGobjectId = 0, TemplateChain = null! }
};
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.ShouldBeEmpty();
}
[Fact]
public void EmptyHierarchy_ReturnsEmptySet()
{
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(new List<GalaxyObjectInfo>())!;
included.ShouldBeEmpty();
}
[Fact]
public void NullHierarchy_ReturnsEmptySet()
{
var sut = new AlarmObjectFilter(Config("TestMachine"));
var included = sut.ResolveIncludedObjects(null)!;
included.ShouldBeEmpty();
}
[Fact]
public void MultipleRoots_AllProcessed()
{
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "TestMachine"),
Obj(2, parent: 0, template: "TestMachine"),
Obj(3, parent: 0, template: "Pump")
};
var sut = new AlarmObjectFilter(Config("TestMachine*"));
var included = sut.ResolveIncludedObjects(hierarchy)!;
included.Count.ShouldBe(2);
}
// ---------- UnmatchedPatterns ----------
[Fact]
public void UnmatchedPatterns_ListsPatternsWithZeroHits()
{
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "TestMachine")
};
var sut = new AlarmObjectFilter(Config("TestMachine*", "NotThere*"));
sut.ResolveIncludedObjects(hierarchy);
sut.UnmatchedPatterns.ShouldContain("NotThere*");
sut.UnmatchedPatterns.ShouldNotContain("TestMachine*");
}
[Fact]
public void UnmatchedPatterns_EmptyWhenAllMatch()
{
var hierarchy = new List<GalaxyObjectInfo>
{
Obj(1, parent: 0, template: "TestMachine"),
Obj(2, parent: 0, template: "Pump")
};
var sut = new AlarmObjectFilter(Config("TestMachine", "Pump"));
sut.ResolveIncludedObjects(hierarchy);
sut.UnmatchedPatterns.ShouldBeEmpty();
}
[Fact]
public void UnmatchedPatterns_EmptyWhenFilterDisabled()
{
var sut = new AlarmObjectFilter(new AlarmFilterConfiguration());
sut.UnmatchedPatterns.ShouldBeEmpty();
}
[Fact]
public void UnmatchedPatterns_ResetBetweenResolutions()
{
var hierarchyA = new List<GalaxyObjectInfo> { Obj(1, parent: 0, template: "TestMachine") };
var hierarchyB = new List<GalaxyObjectInfo> { Obj(1, parent: 0, template: "Pump") };
var sut = new AlarmObjectFilter(Config("TestMachine*"));
sut.ResolveIncludedObjects(hierarchyA);
sut.UnmatchedPatterns.ShouldBeEmpty();
sut.ResolveIncludedObjects(hierarchyB);
sut.UnmatchedPatterns.ShouldContain("TestMachine*");
}
// ---------- Helpers ----------
private static AlarmFilterConfiguration Config(params string[] filters) =>
new() { ObjectFilters = filters.ToList() };
private static GalaxyObjectInfo Obj(int id, int parent, string template) => new()
{
GobjectId = id,
ParentGobjectId = parent,
TagName = $"Obj_{id}",
BrowseName = $"Obj_{id}",
TemplateChain = new List<string> { template }
};
private static List<GalaxyObjectInfo> SingleObject() => new()
{
Obj(1, parent: 0, template: "Anything")
};
}
}

View File

@@ -0,0 +1,63 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
namespace ZB.MOM.WW.OtOpcUa.Tests.Domain
{
/// <summary>
/// Verifies default and extended-field behavior for Galaxy attribute metadata objects.
/// </summary>
public class GalaxyAttributeInfoTests
{
/// <summary>
/// Confirms that a default attribute metadata object starts with empty strings for its text fields.
/// </summary>
[Fact]
public void DefaultValues_AreEmpty()
{
var info = new GalaxyAttributeInfo();
info.PrimitiveName.ShouldBe("");
info.AttributeSource.ShouldBe("");
info.TagName.ShouldBe("");
info.AttributeName.ShouldBe("");
info.FullTagReference.ShouldBe("");
info.DataTypeName.ShouldBe("");
info.SecurityClassification.ShouldBe(1);
info.IsHistorized.ShouldBeFalse();
info.IsAlarm.ShouldBeFalse();
}
/// <summary>
/// Confirms that primitive-name and attribute-source fields can be populated for extended metadata rows.
/// </summary>
[Fact]
public void ExtendedFields_CanBeSet()
{
var info = new GalaxyAttributeInfo
{
PrimitiveName = "UDO",
AttributeSource = "primitive"
};
info.PrimitiveName.ShouldBe("UDO");
info.AttributeSource.ShouldBe("primitive");
}
/// <summary>
/// Confirms that standard attribute rows leave the extended metadata fields empty.
/// </summary>
[Fact]
public void StandardAttributes_HaveEmptyExtendedFields()
{
var info = new GalaxyAttributeInfo
{
GobjectId = 1,
TagName = "TestObj",
AttributeName = "MachineID",
FullTagReference = "TestObj.MachineID",
MxDataType = 5
};
info.PrimitiveName.ShouldBe("");
info.AttributeSource.ShouldBe("");
}
}
}

View File

@@ -0,0 +1,97 @@
using System;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
namespace ZB.MOM.WW.OtOpcUa.Tests.Domain
{
/// <summary>
/// Verifies how Galaxy MX data types are mapped into OPC UA and CLR types by the bridge.
/// </summary>
public class MxDataTypeMapperTests
{
/// <summary>
/// Confirms that known Galaxy MX data types map to the expected OPC UA data type node identifiers.
/// </summary>
/// <param name="mxDataType">The Galaxy MX data type code.</param>
/// <param name="expectedNodeId">The expected OPC UA data type node identifier.</param>
[Theory]
[InlineData(1, 1u)] // Boolean
[InlineData(2, 6u)] // Integer → Int32
[InlineData(3, 10u)] // Float
[InlineData(4, 11u)] // Double
[InlineData(5, 12u)] // String
[InlineData(6, 13u)] // DateTime
[InlineData(7, 11u)] // ElapsedTime → Double
[InlineData(8, 12u)] // Reference → String
[InlineData(13, 6u)] // Enumeration → Int32
[InlineData(14, 12u)] // Custom → String
[InlineData(15, 21u)] // InternationalizedString → LocalizedText
[InlineData(16, 12u)] // Custom → String
public void MapToOpcUaDataType_AllKnownTypes(int mxDataType, uint expectedNodeId)
{
MxDataTypeMapper.MapToOpcUaDataType(mxDataType).ShouldBe(expectedNodeId);
}
/// <summary>
/// Confirms that unknown MX data types default to the OPC UA string data type.
/// </summary>
/// <param name="mxDataType">The unsupported MX data type code.</param>
[Theory]
[InlineData(0)]
[InlineData(99)]
[InlineData(-1)]
public void MapToOpcUaDataType_UnknownDefaultsToString(int mxDataType)
{
MxDataTypeMapper.MapToOpcUaDataType(mxDataType).ShouldBe(12u); // String
}
/// <summary>
/// Confirms that known MX data types map to the expected CLR runtime types.
/// </summary>
/// <param name="mxDataType">The Galaxy MX data type code.</param>
/// <param name="expectedType">The expected CLR type used by the bridge.</param>
[Theory]
[InlineData(1, typeof(bool))]
[InlineData(2, typeof(int))]
[InlineData(3, typeof(float))]
[InlineData(4, typeof(double))]
[InlineData(5, typeof(string))]
[InlineData(6, typeof(DateTime))]
[InlineData(7, typeof(double))]
[InlineData(8, typeof(string))]
[InlineData(13, typeof(int))]
[InlineData(15, typeof(string))]
public void MapToClrType_AllKnownTypes(int mxDataType, Type expectedType)
{
MxDataTypeMapper.MapToClrType(mxDataType).ShouldBe(expectedType);
}
/// <summary>
/// Confirms that unknown MX data types default to the CLR string type.
/// </summary>
[Fact]
public void MapToClrType_UnknownDefaultsToString()
{
MxDataTypeMapper.MapToClrType(999).ShouldBe(typeof(string));
}
/// <summary>
/// Confirms that the boolean MX type reports the expected OPC UA type name.
/// </summary>
[Fact]
public void GetOpcUaTypeName_Boolean()
{
MxDataTypeMapper.GetOpcUaTypeName(1).ShouldBe("Boolean");
}
/// <summary>
/// Confirms that unknown MX types report the fallback OPC UA type name of string.
/// </summary>
[Fact]
public void GetOpcUaTypeName_Unknown_ReturnsString()
{
MxDataTypeMapper.GetOpcUaTypeName(999).ShouldBe("String");
}
}
}

View File

@@ -0,0 +1,65 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
namespace ZB.MOM.WW.OtOpcUa.Tests.Domain
{
/// <summary>
/// Verifies the operator-facing error messages and quality mappings derived from MXAccess error codes.
/// </summary>
public class MxErrorCodesTests
{
/// <summary>
/// Confirms that known MXAccess error codes produce readable operator-facing descriptions.
/// </summary>
/// <param name="code">The MXAccess error code.</param>
/// <param name="expectedSubstring">A substring expected in the returned description.</param>
[Theory]
[InlineData(1008, "Invalid reference")]
[InlineData(1012, "Wrong data type")]
[InlineData(1013, "Not writable")]
[InlineData(1014, "Request timed out")]
[InlineData(1015, "Communication failure")]
[InlineData(1016, "Not connected")]
public void GetMessage_KnownCodes_ContainsDescription(int code, string expectedSubstring)
{
MxErrorCodes.GetMessage(code).ShouldContain(expectedSubstring);
}
/// <summary>
/// Confirms that unknown MXAccess error codes are reported as unknown while preserving the numeric code.
/// </summary>
[Fact]
public void GetMessage_UnknownCode_ReturnsUnknown()
{
MxErrorCodes.GetMessage(9999).ShouldContain("Unknown");
MxErrorCodes.GetMessage(9999).ShouldContain("9999");
}
/// <summary>
/// Confirms that known MXAccess error codes map to the expected bridge quality values.
/// </summary>
/// <param name="code">The MXAccess error code.</param>
/// <param name="expected">The expected bridge quality value.</param>
[Theory]
[InlineData(1008, Quality.BadConfigError)]
[InlineData(1012, Quality.BadConfigError)]
[InlineData(1013, Quality.BadOutOfService)]
[InlineData(1014, Quality.BadCommFailure)]
[InlineData(1015, Quality.BadCommFailure)]
[InlineData(1016, Quality.BadNotConnected)]
public void MapToQuality_KnownCodes(int code, Quality expected)
{
MxErrorCodes.MapToQuality(code).ShouldBe(expected);
}
/// <summary>
/// Confirms that unknown MXAccess error codes map to the generic bad quality bucket.
/// </summary>
[Fact]
public void MapToQuality_UnknownCode_ReturnsBad()
{
MxErrorCodes.MapToQuality(9999).ShouldBe(Quality.Bad);
}
}
}

View File

@@ -0,0 +1,149 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
namespace ZB.MOM.WW.OtOpcUa.Tests.Domain
{
/// <summary>
/// Verifies the mapping between MXAccess quality codes, bridge quality values, and OPC UA status codes.
/// </summary>
public class QualityMapperTests
{
/// <summary>
/// Confirms that bad-family MXAccess quality values map to the expected bridge quality values.
/// </summary>
/// <param name="input">The raw MXAccess quality code.</param>
/// <param name="expected">The bridge quality value expected for the code.</param>
[Theory]
[InlineData(0, Quality.Bad)]
[InlineData(4, Quality.BadConfigError)]
[InlineData(20, Quality.BadCommFailure)]
[InlineData(32, Quality.BadWaitingForInitialData)]
public void MapFromMxAccess_BadFamily(int input, Quality expected)
{
QualityMapper.MapFromMxAccessQuality(input).ShouldBe(expected);
}
/// <summary>
/// Confirms that uncertain-family MXAccess quality values map to the expected bridge quality values.
/// </summary>
/// <param name="input">The raw MXAccess quality code.</param>
/// <param name="expected">The bridge quality value expected for the code.</param>
[Theory]
[InlineData(64, Quality.Uncertain)]
[InlineData(68, Quality.UncertainLastUsable)]
[InlineData(88, Quality.UncertainSubNormal)]
public void MapFromMxAccess_UncertainFamily(int input, Quality expected)
{
QualityMapper.MapFromMxAccessQuality(input).ShouldBe(expected);
}
/// <summary>
/// Confirms that good-family MXAccess quality values map to the expected bridge quality values.
/// </summary>
/// <param name="input">The raw MXAccess quality code.</param>
/// <param name="expected">The bridge quality value expected for the code.</param>
[Theory]
[InlineData(192, Quality.Good)]
[InlineData(216, Quality.GoodLocalOverride)]
public void MapFromMxAccess_GoodFamily(int input, Quality expected)
{
QualityMapper.MapFromMxAccessQuality(input).ShouldBe(expected);
}
/// <summary>
/// Confirms that unknown bad-family values collapse to the generic bad quality bucket.
/// </summary>
[Fact]
public void MapFromMxAccess_UnknownBadValue_ReturnsBad()
{
QualityMapper.MapFromMxAccessQuality(63).ShouldBe(Quality.Bad);
}
/// <summary>
/// Confirms that unknown uncertain-family values collapse to the generic uncertain quality bucket.
/// </summary>
[Fact]
public void MapFromMxAccess_UnknownUncertainValue_ReturnsUncertain()
{
QualityMapper.MapFromMxAccessQuality(100).ShouldBe(Quality.Uncertain);
}
/// <summary>
/// Confirms that unknown good-family values collapse to the generic good quality bucket.
/// </summary>
[Fact]
public void MapFromMxAccess_UnknownGoodValue_ReturnsGood()
{
QualityMapper.MapFromMxAccessQuality(200).ShouldBe(Quality.Good);
}
/// <summary>
/// Confirms that the generic good quality maps to the OPC UA good status code.
/// </summary>
[Fact]
public void MapToOpcUa_Good_Returns0()
{
QualityMapper.MapToOpcUaStatusCode(Quality.Good).ShouldBe(0x00000000u);
}
/// <summary>
/// Confirms that the generic bad quality maps to the OPC UA bad status code.
/// </summary>
[Fact]
public void MapToOpcUa_Bad_Returns80000000()
{
QualityMapper.MapToOpcUaStatusCode(Quality.Bad).ShouldBe(0x80000000u);
}
/// <summary>
/// Confirms that communication failures map to the OPC UA bad communication-failure status code.
/// </summary>
[Fact]
public void MapToOpcUa_BadCommFailure()
{
QualityMapper.MapToOpcUaStatusCode(Quality.BadCommFailure).ShouldBe(0x80050000u);
}
/// <summary>
/// Confirms that the generic uncertain quality maps to the OPC UA uncertain status code.
/// </summary>
[Fact]
public void MapToOpcUa_Uncertain()
{
QualityMapper.MapToOpcUaStatusCode(Quality.Uncertain).ShouldBe(0x40000000u);
}
/// <summary>
/// Confirms that good quality values are classified correctly by the quality extension helpers.
/// </summary>
[Fact]
public void QualityExtensions_IsGood()
{
Quality.Good.IsGood().ShouldBe(true);
Quality.Good.IsBad().ShouldBe(false);
Quality.Good.IsUncertain().ShouldBe(false);
}
/// <summary>
/// Confirms that bad quality values are classified correctly by the quality extension helpers.
/// </summary>
[Fact]
public void QualityExtensions_IsBad()
{
Quality.Bad.IsBad().ShouldBe(true);
Quality.Bad.IsGood().ShouldBe(false);
}
/// <summary>
/// Confirms that uncertain quality values are classified correctly by the quality extension helpers.
/// </summary>
[Fact]
public void QualityExtensions_IsUncertain()
{
Quality.Uncertain.IsUncertain().ShouldBe(true);
Quality.Uncertain.IsGood().ShouldBe(false);
Quality.Uncertain.IsBad().ShouldBe(false);
}
}
}

View File

@@ -0,0 +1,54 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Domain;
namespace ZB.MOM.WW.OtOpcUa.Tests.Domain
{
public class SecurityClassificationMapperTests
{
/// <summary>
/// Verifies that Galaxy classifications intended for operator and engineering writes remain writable through OPC UA.
/// </summary>
/// <param name="classification">The Galaxy security classification value being evaluated for write access.</param>
/// <param name="expected">The expected writable result for the supplied Galaxy classification.</param>
[Theory]
[InlineData(0, true)] // FreeAccess
[InlineData(1, true)] // Operate
[InlineData(4, true)] // Tune
[InlineData(5, true)] // Configure
public void Writable_SecurityLevels(int classification, bool expected)
{
SecurityClassificationMapper.IsWritable(classification).ShouldBe(expected);
}
/// <summary>
/// Verifies that secured or view-only Galaxy classifications are exposed as read-only attributes.
/// </summary>
/// <param name="classification">The Galaxy security classification value expected to block writes.</param>
/// <param name="expected">The expected writable result for the supplied read-only Galaxy classification.</param>
[Theory]
[InlineData(2, false)] // SecuredWrite
[InlineData(3, false)] // VerifiedWrite
[InlineData(6, false)] // ViewOnly
public void ReadOnly_SecurityLevels(int classification, bool expected)
{
SecurityClassificationMapper.IsWritable(classification).ShouldBe(expected);
}
/// <summary>
/// Verifies that unknown security classifications do not accidentally block writes for unmapped Galaxy values.
/// </summary>
/// <param name="classification">
/// An unmapped Galaxy security classification value that should fall back to writable
/// behavior.
/// </param>
[Theory]
[InlineData(-1)]
[InlineData(7)]
[InlineData(99)]
public void Unknown_Values_DefaultToWritable(int classification)
{
SecurityClassificationMapper.IsWritable(classification).ShouldBeTrue();
}
}
}