Reformat / cleanup
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 46s
NuGet Publish / publish-to-gitea (push) Successful in 56s

This commit is contained in:
Joseph Doherty
2026-02-21 08:10:36 -05:00
parent 4c6aaa5a3f
commit a70d8befae
176 changed files with 50555 additions and 49587 deletions

View File

@@ -1,10 +1,8 @@
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Bson.Schema;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using Xunit;
using System.Collections.Generic;
using System.Linq;
using ZB.MOM.WW.CBDD.Bson.Schema;
using System.Diagnostics.CodeAnalysis;
namespace ZB.MOM.WW.CBDD.Tests;
@@ -14,7 +12,7 @@ public class DictionaryPersistenceTests : IDisposable
private readonly StorageEngine _storage;
/// <summary>
/// Initializes a new instance of the <see cref="DictionaryPersistenceTests"/> class.
/// Initializes a new instance of the <see cref="DictionaryPersistenceTests" /> class.
/// </summary>
public DictionaryPersistenceTests()
{
@@ -23,55 +21,18 @@ public class DictionaryPersistenceTests : IDisposable
}
/// <summary>
/// Disposes test resources and removes temporary files.
/// Disposes test resources and removes temporary files.
/// </summary>
public void Dispose()
{
_storage.Dispose();
if (File.Exists(_dbPath)) File.Delete(_dbPath);
var walPath = Path.ChangeExtension(_dbPath, ".wal");
string walPath = Path.ChangeExtension(_dbPath, ".wal");
if (File.Exists(walPath)) File.Delete(walPath);
}
private class MockMapper : DocumentMapperBase<ObjectId, Dictionary<string, object>>
{
private readonly string _collectionName;
private readonly List<string> _keys;
/// <summary>
/// Initializes a new instance of the <see cref="MockMapper"/> class.
/// </summary>
/// <param name="name">The collection name.</param>
/// <param name="keys">The mapper keys.</param>
public MockMapper(string name, params string[] keys)
{
_collectionName = name;
_keys = keys.ToList();
}
/// <inheritdoc />
public override string CollectionName => _collectionName;
/// <inheritdoc />
public override IEnumerable<string> UsedKeys => _keys;
/// <inheritdoc />
public override BsonSchema GetSchema() => new BsonSchema { Title = _collectionName };
/// <inheritdoc />
public override ObjectId GetId(Dictionary<string, object> entity) => throw new NotImplementedException();
/// <inheritdoc />
public override void SetId(Dictionary<string, object> entity, ObjectId id) => throw new NotImplementedException();
/// <inheritdoc />
public override int Serialize(Dictionary<string, object> entity, BsonSpanWriter writer) => throw new NotImplementedException();
/// <inheritdoc />
public override Dictionary<string, object> Deserialize(BsonSpanReader reader) => throw new NotImplementedException();
}
/// <summary>
/// Verifies mapper registration adds all unique dictionary keys.
/// Verifies mapper registration adds all unique dictionary keys.
/// </summary>
[Fact]
public void RegisterMappers_Registers_All_Unique_Keys()
@@ -99,7 +60,7 @@ public class DictionaryPersistenceTests : IDisposable
}
/// <summary>
/// Verifies dictionary keys persist across storage restarts.
/// Verifies dictionary keys persist across storage restarts.
/// </summary>
[Fact]
public void Dictionary_Keys_Persist_Across_Restarts()
@@ -107,7 +68,7 @@ public class DictionaryPersistenceTests : IDisposable
var mapper = new MockMapper("Coll1", "PersistedKey");
_storage.RegisterMappers(new IDocumentMapper[] { mapper });
var originalId = _storage.GetOrAddDictionaryEntry("PersistedKey");
ushort originalId = _storage.GetOrAddDictionaryEntry("PersistedKey");
originalId.ShouldNotBe((ushort)0);
_storage.Dispose();
@@ -115,10 +76,78 @@ public class DictionaryPersistenceTests : IDisposable
// Re-open
using var storage2 = new StorageEngine(_dbPath, PageFileConfig.Default);
var recoveredId = storage2.GetOrAddDictionaryEntry("PersistedKey");
ushort recoveredId = storage2.GetOrAddDictionaryEntry("PersistedKey");
recoveredId.ShouldBe(originalId);
}
/// <summary>
/// Verifies nested schema fields are registered as dictionary keys.
/// </summary>
[Fact]
public void RegisterMappers_Handles_Nested_Keys()
{
var mapper = new NestedMockMapper();
_storage.RegisterMappers(new IDocumentMapper[] { mapper });
_storage.GetOrAddDictionaryEntry("Top").ShouldNotBe((ushort)0);
_storage.GetOrAddDictionaryEntry("Child").ShouldNotBe((ushort)0);
}
[SuppressMessage("ReSharper", "All", Justification = "Test-only stub mapper; members are intentionally not used.")]
private class MockMapper : DocumentMapperBase<ObjectId, Dictionary<string, object>>
{
private readonly string _collectionName;
private readonly List<string> _keys;
/// <summary>
/// Initializes a new instance of the <see cref="MockMapper" /> class.
/// </summary>
/// <param name="name">The collection name.</param>
/// <param name="keys">The mapper keys.</param>
public MockMapper(string name, params string[] keys)
{
_collectionName = name;
_keys = keys.ToList();
}
/// <inheritdoc />
public override string CollectionName => _collectionName;
/// <inheritdoc />
public override IEnumerable<string> UsedKeys => _keys;
/// <inheritdoc />
public override BsonSchema GetSchema()
{
return new BsonSchema { Title = _collectionName };
}
/// <inheritdoc />
public override ObjectId GetId(Dictionary<string, object> entity)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override void SetId(Dictionary<string, object> entity, ObjectId id)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override int Serialize(Dictionary<string, object> entity, BsonSpanWriter writer)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override Dictionary<string, object> Deserialize(BsonSpanReader reader)
{
throw new NotImplementedException();
}
}
[SuppressMessage("ReSharper", "All", Justification = "Test-only stub mapper; members are intentionally not used.")]
private class NestedMockMapper : DocumentMapperBase<ObjectId, object>
{
/// <inheritdoc />
@@ -141,28 +170,27 @@ public class DictionaryPersistenceTests : IDisposable
}
/// <inheritdoc />
public override ObjectId GetId(object entity) => throw new NotImplementedException();
public override ObjectId GetId(object entity)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override void SetId(object entity, ObjectId id) => throw new NotImplementedException();
public override void SetId(object entity, ObjectId id)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override int Serialize(object entity, BsonSpanWriter writer) => throw new NotImplementedException();
public override int Serialize(object entity, BsonSpanWriter writer)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override object Deserialize(BsonSpanReader reader) => throw new NotImplementedException();
}
/// <summary>
/// Verifies nested schema fields are registered as dictionary keys.
/// </summary>
[Fact]
public void RegisterMappers_Handles_Nested_Keys()
{
var mapper = new NestedMockMapper();
_storage.RegisterMappers(new IDocumentMapper[] { mapper });
_storage.GetOrAddDictionaryEntry("Top").ShouldNotBe((ushort)0);
_storage.GetOrAddDictionaryEntry("Child").ShouldNotBe((ushort)0);
public override object Deserialize(BsonSpanReader reader)
{
throw new NotImplementedException();
}
}
}