using ZB.MOM.WW.CBDD.Bson; using Xunit; namespace ZB.MOM.WW.CBDD.Tests; public class ObjectIdTests { /// /// Verifies new object identifiers are 12 bytes long. /// [Fact] public void NewObjectId_ShouldCreate12ByteId() { var oid = ObjectId.NewObjectId(); Span bytes = stackalloc byte[12]; oid.WriteTo(bytes); bytes.Length.ShouldBe(12); } /// /// Verifies object identifiers round-trip from their binary form. /// [Fact] public void ObjectId_ShouldRoundTrip() { var original = ObjectId.NewObjectId(); Span bytes = stackalloc byte[12]; original.WriteTo(bytes); var restored = new ObjectId(bytes); restored.ShouldBe(original); } /// /// Verifies object identifier equality behavior. /// [Fact] public void ObjectId_Equals_ShouldWork() { var oid1 = ObjectId.NewObjectId(); var oid2 = oid1; var oid3 = ObjectId.NewObjectId(); oid2.ShouldBe(oid1); oid3.ShouldNotBe(oid1); } /// /// Verifies object identifier timestamps are recent UTC values. /// [Fact] public void ObjectId_Timestamp_ShouldBeRecentUtc() { var oid = ObjectId.NewObjectId(); var timestamp = oid.Timestamp; (timestamp <= DateTime.UtcNow).ShouldBeTrue(); (timestamp >= DateTime.UtcNow.AddSeconds(-5)).ShouldBeTrue(); } }