73 lines
3.5 KiB
C#
73 lines
3.5 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.AbCip;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.IntegrationTests;
|
|
|
|
/// <summary>
|
|
/// Pure-unit tests for the profile catalog. Verifies <see cref="KnownProfiles"/>
|
|
/// stays in sync with <see cref="AbCipPlcFamily"/> + 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.
|
|
/// </summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class AbServerProfileTests
|
|
{
|
|
/// <summary>Verifies known profiles for family returns expected compose profile.</summary>
|
|
/// <param name="family">The AB CIP PLC family.</param>
|
|
/// <param name="expected">The expected Docker Compose profile name.</param>
|
|
[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);
|
|
}
|
|
|
|
/// <summary>Verifies known profiles all covers every family.</summary>
|
|
[Fact]
|
|
public void KnownProfiles_All_Covers_Every_Family()
|
|
{
|
|
var covered = KnownProfiles.All.Select(p => p.Family).ToHashSet();
|
|
foreach (var family in Enum.GetValues<AbCipPlcFamily>())
|
|
covered.ShouldContain(family, $"Family {family} is missing a KnownProfiles entry.");
|
|
}
|
|
|
|
/// <summary>Uses the owned port for the family requested by the test.</summary>
|
|
[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);
|
|
}
|
|
|
|
/// <summary>Rejects missing or foreign endpoints and requests for a different variant.</summary>
|
|
[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<InvalidOperationException>(() => AbServerFixture.ResolveLocalPort(
|
|
KnownProfiles.ForFamily(family), selectedProfile, selectedEndpoint, controlLogixEndpoint));
|
|
}
|
|
|
|
/// <summary>Verifies default port matches EtherNetIP standard.</summary>
|
|
[Fact]
|
|
public void DefaultPort_Matches_EtherNetIP_Standard()
|
|
{
|
|
AbServerProfile.DefaultPort.ShouldBe(44818);
|
|
}
|
|
}
|