using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Driver.AbCip; namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.IntegrationTests; /// /// Pure-unit tests for the profile catalog. Verifies /// stays in sync with + with the compose-file service /// names — a typo in either would surface as a test failure rather than a silent /// "wrong family booted" at runtime. Runs without Docker, so CI without the /// container still exercises these contracts. /// [Trait("Category", "Unit")] public sealed class AbServerProfileTests { /// Verifies known profiles for family returns expected compose profile. /// The AB CIP PLC family. /// The expected Docker Compose profile name. [Theory] [InlineData(AbCipPlcFamily.ControlLogix, "controllogix")] [InlineData(AbCipPlcFamily.CompactLogix, "compactlogix")] [InlineData(AbCipPlcFamily.Micro800, "micro800")] [InlineData(AbCipPlcFamily.GuardLogix, "guardlogix")] public void KnownProfiles_ForFamily_Returns_Expected_ComposeProfile(AbCipPlcFamily family, string expected) { KnownProfiles.ForFamily(family).ComposeProfile.ShouldBe(expected); } /// Verifies known profiles all covers every family. [Fact] public void KnownProfiles_All_Covers_Every_Family() { var covered = KnownProfiles.All.Select(p => p.Family).ToHashSet(); foreach (var family in Enum.GetValues()) covered.ShouldContain(family, $"Family {family} is missing a KnownProfiles entry."); } /// Uses the owned port for the family requested by the test. [Theory] [InlineData(AbCipPlcFamily.ControlLogix, "controllogix", 41234)] [InlineData(AbCipPlcFamily.ControlLogix, "micro800", 41234)] [InlineData(AbCipPlcFamily.CompactLogix, "compactlogix", 41235)] [InlineData(AbCipPlcFamily.Micro800, "micro800", 41235)] [InlineData(AbCipPlcFamily.GuardLogix, "guardlogix", 41235)] public void Owned_endpoint_matches_the_requested_family(AbCipPlcFamily family, string selectedProfile, int expectedPort) { AbServerFixture.ResolveLocalPort(KnownProfiles.ForFamily(family), selectedProfile, "127.0.0.1:41235", "127.0.0.1:41234").ShouldBe(expectedPort); } /// Rejects missing or foreign endpoints and requests for a different variant. [Theory] [InlineData(AbCipPlcFamily.ControlLogix, "micro800", "127.0.0.1:41235", null)] [InlineData(AbCipPlcFamily.ControlLogix, "micro800", "127.0.0.1:41235", "fixture.example:41234")] [InlineData(AbCipPlcFamily.Micro800, "micro800", "127.0.0.2:41235", "127.0.0.1:41234")] [InlineData(AbCipPlcFamily.Micro800, "micro800", "127.0.0.1:65536", "127.0.0.1:41234")] [InlineData(AbCipPlcFamily.CompactLogix, "micro800", "127.0.0.1:41235", "127.0.0.1:41234")] public void Invalid_owned_endpoint_cannot_fall_back(AbCipPlcFamily family, string selectedProfile, string selectedEndpoint, string? controlLogixEndpoint) { Assert.Throws(() => AbServerFixture.ResolveLocalPort( KnownProfiles.ForFamily(family), selectedProfile, selectedEndpoint, controlLogixEndpoint)); } /// Verifies default port matches EtherNetIP standard. [Fact] public void DefaultPort_Matches_EtherNetIP_Standard() { AbServerProfile.DefaultPort.ShouldBe(44818); } }