Implement checkpoint modes with docs/tests and reorganize project file layout
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 46s
NuGet Publish / publish-to-gitea (push) Successful in 53s

This commit is contained in:
Joseph Doherty
2026-02-21 07:56:36 -05:00
parent 3ffd468c79
commit 4c6aaa5a3f
96 changed files with 744 additions and 249 deletions

View File

@@ -0,0 +1,64 @@
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();
}
}

View File

@@ -0,0 +1,53 @@
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Metadata;
using ZB.MOM.WW.CBDD.Shared;
using Xunit;
namespace ZB.MOM.WW.CBDD.Tests;
public class ValueObjectIdTests : IDisposable
{
private readonly string _dbPath = "value_object_ids.db";
private readonly Shared.TestDbContext _db;
/// <summary>
/// Initializes a new instance of the <see cref="ValueObjectIdTests"/> class.
/// </summary>
public ValueObjectIdTests()
{
if (File.Exists(_dbPath)) File.Delete(_dbPath);
_db = new Shared.TestDbContext(_dbPath);
}
/// <summary>
/// Executes Should_Support_ValueObject_Id_Conversion.
/// </summary>
[Fact]
public void Should_Support_ValueObject_Id_Conversion()
{
var order = new Order
{
Id = new OrderId("ORD-123"),
CustomerName = "John Doe"
};
_db.Orders.Insert(order);
var retrieved = _db.Orders.FindById(new OrderId("ORD-123"));
retrieved.ShouldNotBeNull();
retrieved.Id.Value.ShouldBe("ORD-123");
retrieved.CustomerName.ShouldBe("John Doe");
}
/// <summary>
/// Executes Dispose.
/// </summary>
public void Dispose()
{
_db.Dispose();
if (File.Exists(_dbPath)) File.Delete(_dbPath);
}
}