Initial import of the CBDDC codebase with docs and tests. Add a .NET-focused gitignore to keep generated artifacts out of source control.
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
Joseph Doherty
2026-02-20 13:03:21 -05:00
commit 08bfc17218
218 changed files with 33910 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
using System;
using System.Text.Json;
using Xunit;
using ZB.MOM.WW.CBDDC.Core;
using System.Globalization;
namespace ZB.MOM.WW.CBDDC.Core.Tests
{
public class OplogEntryTests
{
/// <summary>
/// Verifies that hash computation is deterministic even when payload content differs.
/// </summary>
[Fact]
public void ComputeHash_ShouldBeDeterministic_RegardlessOfPayload()
{
// Arrange
var collection = "test-collection";
var key = "test-key";
var op = OperationType.Put;
var timestamp = new HlcTimestamp(100, 0, "node-1");
var prevHash = "prev-hash";
var payload1 = JsonDocument.Parse("{\"prop\": 1}").RootElement;
var payload2 = JsonDocument.Parse("{\"prop\": 2, \"extra\": \"whitespace\"}").RootElement;
// Act
var entry1 = new OplogEntry(collection, key, op, payload1, timestamp, prevHash);
var entry2 = new OplogEntry(collection, key, op, payload2, timestamp, prevHash);
// Assert
entry2.Hash.ShouldBe(entry1.Hash);
}
/// <summary>
/// Verifies that hash computation uses invariant culture formatting for timestamp values.
/// </summary>
[Fact]
public void ComputeHash_ShouldUseInvariantCulture_ForTimestamp()
{
// Arrange
var originalCulture = CultureInfo.CurrentCulture;
try
{
var culture = CultureInfo.GetCultureInfo("de-DE");
CultureInfo.CurrentCulture = culture;
var timestamp = new HlcTimestamp(123456789, 1, "node");
var entry = new OplogEntry("col", "key", OperationType.Put, null, timestamp, "prev");
// Act
var hash = entry.ComputeHash();
// Assert
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
var expectedEntry = new OplogEntry("col", "key", OperationType.Put, null, timestamp, "prev");
hash.ShouldBe(expectedEntry.Hash);
}
finally
{
CultureInfo.CurrentCulture = originalCulture;
}
}
/// <summary>
/// Verifies that an entry is valid when its stored hash matches computed content.
/// </summary>
[Fact]
public void IsValid_ShouldReturnTrue_WhenHashMatches()
{
var timestamp = new HlcTimestamp(100, 0, "node-1");
var entry = new OplogEntry("col", "key", OperationType.Put, null, timestamp, "prev");
entry.IsValid().ShouldBeTrue();
}
}
}