Files
CBDD/tests/CBDD.Tests/ObjectIdTests.cs
Joseph Doherty 3ffd468c79
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 45s
NuGet Publish / publish-to-gitea (push) Successful in 52s
Fix audit findings for coverage, architecture checks, and XML docs
2026-02-20 15:43:25 -05:00

65 lines
1.5 KiB
C#
Executable File

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