using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Configuration.Enums; namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests; /// /// Pins the underlying type of to int so the SQL /// storage type (HasConversion<int>() in OtOpcUaConfigDbContext) and the /// XML doc ("Stored as int") cannot drift back into the latent uint→int overflow /// trap caught by Configuration-004. /// [Trait("Category", "Unit")] public sealed class NodePermissionsTests { [Fact] public void Underlying_type_is_int_so_it_matches_HasConversion_in_DbContext() { // Configuration-004: NodePermissions was declared : uint while NodeAcl.PermissionFlags // is persisted via HasConversion(). A bit-31 grant would overflow int and corrupt // the round-trip. Lock the underlying type to int. typeof(NodePermissions).GetEnumUnderlyingType().ShouldBe(typeof(int)); } [Fact] public void All_defined_bits_round_trip_through_int_cast_without_loss() { // Belt-and-braces: every declared bit must survive a (int) round-trip — fails today // if anyone re-introduces a bit-31 flag while the underlying type is uint. foreach (NodePermissions value in Enum.GetValues()) { var asInt = (int)value; var roundTripped = (NodePermissions)asInt; roundTripped.ShouldBe(value); } } [Fact] public void Bitwise_combinations_round_trip_through_int_storage() { // The PermissionFlags column stores int; combinations of bits must survive the conversion. var combo = NodePermissions.Engineer | NodePermissions.MethodCall; var stored = (int)combo; var rebuilt = (NodePermissions)stored; rebuilt.ShouldBe(combo); rebuilt.HasFlag(NodePermissions.WriteTune).ShouldBeTrue(); rebuilt.HasFlag(NodePermissions.MethodCall).ShouldBeTrue(); } }