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,9 +1,4 @@
using ZB.MOM.WW.CBDD.Core;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using ZB.MOM.WW.CBDD.Core.Transactions;
using ZB.MOM.WW.CBDD.Shared;
using Xunit;
namespace ZB.MOM.WW.CBDD.Tests;
@@ -12,7 +7,7 @@ public class AsyncTests : IDisposable
private readonly string _dbPath;
/// <summary>
/// Initializes a new instance of the <see cref="AsyncTests"/> class.
/// Initializes a new instance of the <see cref="AsyncTests" /> class.
/// </summary>
public AsyncTests()
{
@@ -20,7 +15,7 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Dispose.
/// Executes Dispose.
/// </summary>
public void Dispose()
{
@@ -29,14 +24,14 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Async_Transaction_Commit_Should_Persist_Data.
/// Executes Async_Transaction_Commit_Should_Persist_Data.
/// </summary>
[Fact]
public async Task Async_Transaction_Commit_Should_Persist_Data()
{
var ct = TestContext.Current.CancellationToken;
using (var db = new Shared.TestDbContext(_dbPath))
using (var db = new TestDbContext(_dbPath))
{
using (var txn = await db.BeginTransactionAsync(ct))
{
@@ -47,7 +42,7 @@ public class AsyncTests : IDisposable
}
// Verify with new storage engine instance
using var db2 = new Shared.TestDbContext(_dbPath);
using var db2 = new TestDbContext(_dbPath);
var doc1 = db2.AsyncDocs.FindById(1);
doc1.ShouldNotBeNull();
doc1.Name.ShouldBe("Async1");
@@ -58,14 +53,14 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Async_Transaction_Rollback_Should_Discard_Data.
/// Executes Async_Transaction_Rollback_Should_Discard_Data.
/// </summary>
[Fact]
public async Task Async_Transaction_Rollback_Should_Discard_Data()
{
var ct = TestContext.Current.CancellationToken;
using var db = new Shared.TestDbContext(_dbPath);
using var db = new TestDbContext(_dbPath);
using (var txn = await db.BeginTransactionAsync(ct))
{
db.AsyncDocs.Insert(new AsyncDoc { Id = 3, Name = "RollbackMe" });
@@ -76,12 +71,12 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Bulk_Async_Insert_Should_Persist_Data.
/// Executes Bulk_Async_Insert_Should_Persist_Data.
/// </summary>
[Fact]
public async Task Bulk_Async_Insert_Should_Persist_Data()
{
using var db = new Shared.TestDbContext(_dbPath);
using var db = new TestDbContext(_dbPath);
var docs = Enumerable.Range(1, 100).Select(i => new AsyncDoc { Id = i + 5000, Name = $"Bulk{i}" });
var ids = await db.AsyncDocs.InsertBulkAsync(docs);
@@ -94,23 +89,20 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes Bulk_Async_Update_Should_Persist_Changes.
/// Executes Bulk_Async_Update_Should_Persist_Changes.
/// </summary>
[Fact]
public async Task Bulk_Async_Update_Should_Persist_Changes()
{
using var db = new Shared.TestDbContext(_dbPath);
using var db = new TestDbContext(_dbPath);
// 1. Insert 100 docs
var docs = Enumerable.Range(1, 100).Select(i => new AsyncDoc { Id = i + 6000, Name = $"Original{i}" }).ToList();
await db.AsyncDocs.InsertBulkAsync(docs);
// 2. Update all docs
foreach (var doc in docs)
{
doc.Name = $"Updated{doc.Id - 6000}";
}
foreach (var doc in docs) doc.Name = $"Updated{doc.Id - 6000}";
var count = await db.AsyncDocs.UpdateBulkAsync(docs);
int count = await db.AsyncDocs.UpdateBulkAsync(docs);
count.ShouldBe(100);
@@ -121,23 +113,24 @@ public class AsyncTests : IDisposable
}
/// <summary>
/// Executes High_Concurrency_Async_Commits.
/// Executes High_Concurrency_Async_Commits.
/// </summary>
[Fact]
public async Task High_Concurrency_Async_Commits()
{
var ct = TestContext.Current.CancellationToken;
using var db = new Shared.TestDbContext(Path.Combine(Path.GetTempPath(), $"cbdd_async_concurrency_{Guid.NewGuid()}.db"));
int threadCount = 2;
int docsPerThread = 50;
using var db =
new TestDbContext(Path.Combine(Path.GetTempPath(), $"cbdd_async_concurrency_{Guid.NewGuid()}.db"));
var threadCount = 2;
var docsPerThread = 50;
var tasks = Enumerable.Range(0, threadCount).Select(async i =>
{
// Test mix of implicit and explicit transactions
for (int j = 0; j < docsPerThread; j++)
for (var j = 0; j < docsPerThread; j++)
{
int id = (i * docsPerThread) + j + 8000;
int id = i * docsPerThread + j + 8000;
await db.AsyncDocs.InsertAsync(new AsyncDoc { Id = id, Name = $"Thread{i}_Doc{j}" });
}
});
@@ -146,7 +139,7 @@ public class AsyncTests : IDisposable
await db.SaveChangesAsync(ct);
// Verify count
var count = db.AsyncDocs.Scan(_ => true).Count();
int count = db.AsyncDocs.Scan(_ => true).Count();
count.ShouldBe(threadCount * docsPerThread);
}
}
}

View File

@@ -1,33 +1,27 @@
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using ZB.MOM.WW.CBDD.Core.Transactions;
using ZB.MOM.WW.CBDD.Shared;
using ZB.MOM.WW.CBDD.Shared.TestDbContext_TestDbContext_Mappers;
using Xunit;
using static ZB.MOM.WW.CBDD.Tests.SchemaTests;
namespace ZB.MOM.WW.CBDD.Tests;
public class BulkOperationsTests : IDisposable
{
private readonly TestDbContext _dbContext;
private readonly string _dbPath;
private readonly string _walPath;
private readonly Shared.TestDbContext _dbContext;
/// <summary>
/// Initializes a new instance of the <see cref="BulkOperationsTests"/> class.
/// Initializes a new instance of the <see cref="BulkOperationsTests" /> class.
/// </summary>
public BulkOperationsTests()
{
_dbPath = Path.Combine(Path.GetTempPath(), $"test_bulk_{Guid.NewGuid()}.db");
_walPath = Path.Combine(Path.GetTempPath(), $"test_bulk_{Guid.NewGuid()}.wal");
_dbContext = new Shared.TestDbContext(_dbPath);
_dbContext = new TestDbContext(_dbPath);
}
/// <summary>
/// Executes Dispose.
/// Executes Dispose.
/// </summary>
public void Dispose()
{
@@ -35,17 +29,14 @@ public class BulkOperationsTests : IDisposable
}
/// <summary>
/// Executes UpdateBulk_UpdatesMultipleDocuments.
/// Executes UpdateBulk_UpdatesMultipleDocuments.
/// </summary>
[Fact]
public void UpdateBulk_UpdatesMultipleDocuments()
{
// Arrange: Insert 100 users
var users = new List<User>();
for (int i = 0; i < 100; i++)
{
users.Add(new User { Id = ObjectId.NewObjectId(), Name = $"User {i}", Age = 20 });
}
for (var i = 0; i < 100; i++) users.Add(new User { Id = ObjectId.NewObjectId(), Name = $"User {i}", Age = 20 });
_dbContext.Users.InsertBulk(users);
_dbContext.SaveChanges();
@@ -57,7 +48,7 @@ public class BulkOperationsTests : IDisposable
}
// Act
var updatedCount = _dbContext.Users.UpdateBulk(users);
int updatedCount = _dbContext.Users.UpdateBulk(users);
_dbContext.SaveChanges();
// Assert
@@ -74,41 +65,32 @@ public class BulkOperationsTests : IDisposable
}
/// <summary>
/// Executes DeleteBulk_RemovesMultipleDocuments.
/// Executes DeleteBulk_RemovesMultipleDocuments.
/// </summary>
[Fact]
public void DeleteBulk_RemovesMultipleDocuments()
{
// Arrange: Insert 100 users
var users = new List<User>();
for (int i = 0; i < 100; i++)
{
users.Add(new User { Id = ObjectId.NewObjectId(), Name = $"User {i}", Age = 20 });
}
for (var i = 0; i < 100; i++) users.Add(new User { Id = ObjectId.NewObjectId(), Name = $"User {i}", Age = 20 });
_dbContext.Users.InsertBulk(users);
_dbContext.SaveChanges();
var idsToDelete = users.Take(50).Select(u => u.Id).ToList();
// Act
var deletedCount = _dbContext.Users.DeleteBulk(idsToDelete);
int deletedCount = _dbContext.Users.DeleteBulk(idsToDelete);
_dbContext.SaveChanges();
// Assert
deletedCount.ShouldBe(50);
// Verify deleted
foreach (var id in idsToDelete)
{
_dbContext.Users.FindById(id).ShouldBeNull();
}
foreach (var id in idsToDelete) _dbContext.Users.FindById(id).ShouldBeNull();
// Verify remaining
var remaining = users.Skip(50).ToList();
foreach (var u in remaining)
{
_dbContext.Users.FindById(u.Id).ShouldNotBeNull();
}
foreach (var u in remaining) _dbContext.Users.FindById(u.Id).ShouldNotBeNull();
// Verify count
// Note: Count() is not fully implemented efficiently yet (iterates everything), but FindAll().Count() works
@@ -116,7 +98,7 @@ public class BulkOperationsTests : IDisposable
}
/// <summary>
/// Executes DeleteBulk_WithTransaction_Rollworks.
/// Executes DeleteBulk_WithTransaction_Rollworks.
/// </summary>
[Fact]
public void DeleteBulk_WithTransaction_Rollworks()
@@ -137,4 +119,4 @@ public class BulkOperationsTests : IDisposable
// Assert: Should still exist
_dbContext.Users.FindById(user.Id).ShouldNotBeNull();
}
}
}

View File

@@ -1,32 +1,27 @@
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using ZB.MOM.WW.CBDD.Core.Transactions;
using ZB.MOM.WW.CBDD.Shared;
using ZB.MOM.WW.CBDD.Shared.TestDbContext_TestDbContext_Mappers;
using Xunit;
namespace ZB.MOM.WW.CBDD.Tests;
public class DocumentCollectionDeleteTests : IDisposable
{
private readonly TestDbContext _dbContext;
private readonly string _dbPath;
private readonly string _walPath;
private readonly Shared.TestDbContext _dbContext;
/// <summary>
/// Initializes a new instance of the <see cref="DocumentCollectionDeleteTests"/> class.
/// Initializes a new instance of the <see cref="DocumentCollectionDeleteTests" /> class.
/// </summary>
public DocumentCollectionDeleteTests()
{
_dbPath = Path.Combine(Path.GetTempPath(), $"test_delete_{Guid.NewGuid()}.db");
_walPath = Path.Combine(Path.GetTempPath(), $"test_delete_{Guid.NewGuid()}.wal");
_dbContext = new Shared.TestDbContext(_dbPath);
_dbContext = new TestDbContext(_dbPath);
}
/// <summary>
/// Releases test resources.
/// Releases test resources.
/// </summary>
public void Dispose()
{
@@ -34,7 +29,7 @@ public class DocumentCollectionDeleteTests : IDisposable
}
/// <summary>
/// Verifies delete removes both the document and its index entry.
/// Verifies delete removes both the document and its index entry.
/// </summary>
[Fact]
public void Delete_RemovesDocumentAndIndexEntry()
@@ -47,7 +42,7 @@ public class DocumentCollectionDeleteTests : IDisposable
_dbContext.Users.FindById(user.Id).ShouldNotBeNull();
// Delete
var deleted = _dbContext.Users.Delete(user.Id);
bool deleted = _dbContext.Users.Delete(user.Id);
_dbContext.SaveChanges();
// Assert
@@ -62,19 +57,19 @@ public class DocumentCollectionDeleteTests : IDisposable
}
/// <summary>
/// Verifies delete returns false for a non-existent document.
/// Verifies delete returns false for a non-existent document.
/// </summary>
[Fact]
public void Delete_NonExistent_ReturnsFalse()
{
var id = ObjectId.NewObjectId();
var deleted = _dbContext.Users.Delete(id);
bool deleted = _dbContext.Users.Delete(id);
_dbContext.SaveChanges();
deleted.ShouldBeFalse();
}
/// <summary>
/// Verifies deletes inside a transaction commit successfully.
/// Verifies deletes inside a transaction commit successfully.
/// </summary>
[Fact]
public void Delete_WithTransaction_CommitsSuccessfully()
@@ -92,4 +87,4 @@ public class DocumentCollectionDeleteTests : IDisposable
// Verify
_dbContext.Users.FindById(user.Id).ShouldBeNull();
}
}
}

View File

@@ -5,20 +5,31 @@ namespace ZB.MOM.WW.CBDD.Tests;
public class DocumentCollectionIndexApiTests : IDisposable
{
private readonly TestDbContext _db;
private readonly string _dbPath;
private readonly Shared.TestDbContext _db;
/// <summary>
/// Initializes a new instance of the <see cref="DocumentCollectionIndexApiTests"/> class.
/// Initializes a new instance of the <see cref="DocumentCollectionIndexApiTests" /> class.
/// </summary>
public DocumentCollectionIndexApiTests()
{
_dbPath = Path.Combine(Path.GetTempPath(), $"collection_index_api_{Guid.NewGuid():N}.db");
_db = new Shared.TestDbContext(_dbPath);
_db = new TestDbContext(_dbPath);
}
/// <summary>
/// Verifies vector index creation and deletion behavior.
/// Disposes test resources and removes temporary files.
/// </summary>
public void Dispose()
{
_db.Dispose();
if (File.Exists(_dbPath)) File.Delete(_dbPath);
string wal = Path.ChangeExtension(_dbPath, ".wal");
if (File.Exists(wal)) File.Delete(wal);
}
/// <summary>
/// Verifies vector index creation and deletion behavior.
/// </summary>
[Fact]
public void CreateVectorIndex_And_DropIndex_Should_Work()
@@ -39,34 +50,23 @@ public class DocumentCollectionIndexApiTests : IDisposable
}
/// <summary>
/// Verifies ensure-index returns existing indexes when already present.
/// Verifies ensure-index returns existing indexes when already present.
/// </summary>
[Fact]
public void EnsureIndex_Should_Return_Existing_Index_When_Already_Present()
{
var first = _db.People.EnsureIndex(p => p.Age, name: "idx_people_age");
var second = _db.People.EnsureIndex(p => p.Age, name: "idx_people_age");
var first = _db.People.EnsureIndex(p => p.Age, "idx_people_age");
var second = _db.People.EnsureIndex(p => p.Age, "idx_people_age");
ReferenceEquals(first, second).ShouldBeTrue();
}
/// <summary>
/// Verifies dropping the primary index name is rejected.
/// Verifies dropping the primary index name is rejected.
/// </summary>
[Fact]
public void DropIndex_Should_Reject_Primary_Index_Name()
{
Should.Throw<InvalidOperationException>(() => _db.People.DropIndex("_id"));
}
/// <summary>
/// Disposes test resources and removes temporary files.
/// </summary>
public void Dispose()
{
_db.Dispose();
if (File.Exists(_dbPath)) File.Delete(_dbPath);
var wal = Path.ChangeExtension(_dbPath, ".wal");
if (File.Exists(wal)) File.Delete(wal);
}
}
}

View File

@@ -1,31 +1,35 @@
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using ZB.MOM.WW.CBDD.Core.Transactions;
using ZB.MOM.WW.CBDD.Shared;
using ZB.MOM.WW.CBDD.Shared.TestDbContext_TestDbContext_Mappers;
namespace ZB.MOM.WW.CBDD.Tests;
public class DocumentCollectionTests : IDisposable
{
private readonly TestDbContext _db;
private readonly string _dbPath;
private readonly string _walPath;
private readonly Shared.TestDbContext _db;
/// <summary>
/// Initializes a new instance of the <see cref="DocumentCollectionTests"/> class.
/// Initializes a new instance of the <see cref="DocumentCollectionTests" /> class.
/// </summary>
public DocumentCollectionTests()
{
_dbPath = Path.Combine(Path.GetTempPath(), $"test_collection_{Guid.NewGuid()}.db");
_walPath = Path.Combine(Path.GetTempPath(), $"test_collection_{Guid.NewGuid()}.wal");
_db = new Shared.TestDbContext(_dbPath);
_db = new TestDbContext(_dbPath);
}
/// <summary>
/// Verifies insert and find-by-id operations.
/// Releases test resources.
/// </summary>
public void Dispose()
{
_db?.Dispose();
}
/// <summary>
/// Verifies insert and find-by-id operations.
/// </summary>
[Fact]
public void Insert_And_FindById_Works()
@@ -46,7 +50,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies find-by-id returns null when no document is found.
/// Verifies find-by-id returns null when no document is found.
/// </summary>
[Fact]
public void FindById_Returns_Null_When_Not_Found()
@@ -59,7 +63,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies find-all returns all entities.
/// Verifies find-all returns all entities.
/// </summary>
[Fact]
public void FindAll_Returns_All_Entities()
@@ -81,7 +85,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies update modifies an existing entity.
/// Verifies update modifies an existing entity.
/// </summary>
[Fact]
public void Update_Modifies_Entity()
@@ -93,7 +97,7 @@ public class DocumentCollectionTests : IDisposable
// Act
user.Age = 31;
var updated = _db.Users.Update(user);
bool updated = _db.Users.Update(user);
_db.SaveChanges();
// Assert
@@ -105,7 +109,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies update returns false when the entity does not exist.
/// Verifies update returns false when the entity does not exist.
/// </summary>
[Fact]
public void Update_Returns_False_When_Not_Found()
@@ -114,7 +118,7 @@ public class DocumentCollectionTests : IDisposable
var user = new User { Id = ObjectId.NewObjectId(), Name = "Ghost", Age = 99 };
// Act
var updated = _db.Users.Update(user);
bool updated = _db.Users.Update(user);
_db.SaveChanges();
// Assert
@@ -122,7 +126,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies delete removes an entity.
/// Verifies delete removes an entity.
/// </summary>
[Fact]
public void Delete_Removes_Entity()
@@ -133,7 +137,7 @@ public class DocumentCollectionTests : IDisposable
_db.SaveChanges();
// Act
var deleted = _db.Users.Delete(id);
bool deleted = _db.Users.Delete(id);
_db.SaveChanges();
// Assert
@@ -142,13 +146,13 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies delete returns false when the entity does not exist.
/// Verifies delete returns false when the entity does not exist.
/// </summary>
[Fact]
public void Delete_Returns_False_When_Not_Found()
{
// Act
var deleted = _db.Users.Delete(ObjectId.NewObjectId());
bool deleted = _db.Users.Delete(ObjectId.NewObjectId());
_db.SaveChanges();
// Assert
@@ -156,7 +160,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies count returns the correct entity count.
/// Verifies count returns the correct entity count.
/// </summary>
[Fact]
public void Count_Returns_Correct_Count()
@@ -167,14 +171,14 @@ public class DocumentCollectionTests : IDisposable
_db.SaveChanges();
// Act
var count = _db.Users.Count();
int count = _db.Users.Count();
// Assert
count.ShouldBe(2);
}
/// <summary>
/// Verifies predicate queries filter entities correctly.
/// Verifies predicate queries filter entities correctly.
/// </summary>
[Fact]
public void Find_With_Predicate_Filters_Correctly()
@@ -194,7 +198,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies bulk insert stores multiple entities.
/// Verifies bulk insert stores multiple entities.
/// </summary>
[Fact]
public void InsertBulk_Inserts_Multiple_Entities()
@@ -217,7 +221,7 @@ public class DocumentCollectionTests : IDisposable
}
/// <summary>
/// Verifies inserts preserve an explicitly assigned identifier.
/// Verifies inserts preserve an explicitly assigned identifier.
/// </summary>
[Fact]
public void Insert_With_SpecifiedId_RetainsId()
@@ -238,12 +242,4 @@ public class DocumentCollectionTests : IDisposable
found.Id.ShouldBe(id);
found.Name.ShouldBe("SpecifiedID");
}
/// <summary>
/// Releases test resources.
/// </summary>
public void Dispose()
{
_db?.Dispose();
}
}
}

View File

@@ -1,29 +1,24 @@
using ZB.MOM.WW.CBDD.Core;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Core.Storage;
using ZB.MOM.WW.CBDD.Core.Transactions;
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Shared;
using ZB.MOM.WW.CBDD.Shared.TestDbContext_TestDbContext_Mappers;
using Xunit;
namespace ZB.MOM.WW.CBDD.Tests;
public class InsertBulkTests : IDisposable
{
private readonly TestDbContext _db;
private readonly string _testFile;
private readonly Shared.TestDbContext _db;
/// <summary>
/// Initializes a new instance of the <see cref="InsertBulkTests"/> class.
/// Initializes a new instance of the <see cref="InsertBulkTests" /> class.
/// </summary>
public InsertBulkTests()
{
_testFile = Path.GetTempFileName();
_db = new Shared.TestDbContext(_testFile);
_db = new TestDbContext(_testFile);
}
/// <summary>
/// Disposes test resources.
/// Disposes test resources.
/// </summary>
public void Dispose()
{
@@ -31,16 +26,13 @@ public class InsertBulkTests : IDisposable
}
/// <summary>
/// Verifies bulk inserts are immediately persisted and visible.
/// Verifies bulk inserts are immediately persisted and visible.
/// </summary>
[Fact]
public void InsertBulk_PersistsData_ImmediatelyVisible()
{
var users = new List<User>();
for (int i = 0; i < 50; i++)
{
users.Add(new User { Id = ZB.MOM.WW.CBDD.Bson.ObjectId.NewObjectId(), Name = $"User {i}", Age = 20 });
}
for (var i = 0; i < 50; i++) users.Add(new User { Id = ObjectId.NewObjectId(), Name = $"User {i}", Age = 20 });
_db.Users.InsertBulk(users);
_db.SaveChanges();
@@ -51,21 +43,23 @@ public class InsertBulkTests : IDisposable
}
/// <summary>
/// Verifies bulk inserts spanning multiple pages persist correctly.
/// Verifies bulk inserts spanning multiple pages persist correctly.
/// </summary>
[Fact]
public void InsertBulk_SpanningMultiplePages_PersistsCorrectly()
{
// 16KB page. User ~50 bytes. 400 users -> ~20KB -> 2 pages.
var users = new List<User>();
for (int i = 0; i < 400; i++)
{
users.Add(new User { Id = ZB.MOM.WW.CBDD.Bson.ObjectId.NewObjectId(), Name = $"User {i} with some long padding text to ensure we fill space {new string('x', 50)}", Age = 20 });
}
for (var i = 0; i < 400; i++)
users.Add(new User
{
Id = ObjectId.NewObjectId(),
Name = $"User {i} with some long padding text to ensure we fill space {new string('x', 50)}", Age = 20
});
_db.Users.InsertBulk(users);
_db.SaveChanges();
_db.Users.Count().ShouldBe(400);
}
}
}

View File

@@ -1,25 +1,24 @@
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core.Collections;
using ZB.MOM.WW.CBDD.Shared;
namespace ZB.MOM.WW.CBDD.Tests;
public class SetMethodTests : IDisposable
{
private readonly TestDbContext _db;
private readonly string _dbPath;
private readonly Shared.TestDbContext _db;
/// <summary>
/// Initializes a new instance of the <see cref="SetMethodTests"/> class.
/// Initializes a new instance of the <see cref="SetMethodTests" /> class.
/// </summary>
public SetMethodTests()
{
_dbPath = Path.Combine(Path.GetTempPath(), $"cbdd_set_{Guid.NewGuid()}.db");
_db = new Shared.TestDbContext(_dbPath);
_db = new TestDbContext(_dbPath);
}
/// <summary>
/// Disposes the resources used by this instance.
/// Disposes the resources used by this instance.
/// </summary>
public void Dispose()
{
@@ -28,7 +27,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set object id returns correct collection.
/// Tests set object id returns correct collection.
/// </summary>
[Fact]
public void Set_ObjectId_ReturnsCorrectCollection()
@@ -39,7 +38,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set shorthand returns correct collection.
/// Tests set shorthand returns correct collection.
/// </summary>
[Fact]
public void Set_Shorthand_ReturnsCorrectCollection()
@@ -50,7 +49,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set int returns correct collection.
/// Tests set int returns correct collection.
/// </summary>
[Fact]
public void Set_Int_ReturnsCorrectCollection()
@@ -61,7 +60,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set string returns correct collection.
/// Tests set string returns correct collection.
/// </summary>
[Fact]
public void Set_String_ReturnsCorrectCollection()
@@ -72,7 +71,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set guid returns correct collection.
/// Tests set guid returns correct collection.
/// </summary>
[Fact]
public void Set_Guid_ReturnsCorrectCollection()
@@ -83,7 +82,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set custom key returns correct collection.
/// Tests set custom key returns correct collection.
/// </summary>
[Fact]
public void Set_CustomKey_ReturnsCorrectCollection()
@@ -94,7 +93,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set all object id collections return correct instances.
/// Tests set all object id collections return correct instances.
/// </summary>
[Fact]
public void Set_AllObjectIdCollections_ReturnCorrectInstances()
@@ -110,7 +109,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set all int collections return correct instances.
/// Tests set all int collections return correct instances.
/// </summary>
[Fact]
public void Set_AllIntCollections_ReturnCorrectInstances()
@@ -123,7 +122,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set string key collections return correct instances.
/// Tests set string key collections return correct instances.
/// </summary>
[Fact]
public void Set_StringKeyCollections_ReturnCorrectInstances()
@@ -132,7 +131,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set unregistered entity throws invalid operation exception.
/// Tests set unregistered entity throws invalid operation exception.
/// </summary>
[Fact]
public void Set_UnregisteredEntity_ThrowsInvalidOperationException()
@@ -141,7 +140,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set wrong key type throws invalid operation exception.
/// Tests set wrong key type throws invalid operation exception.
/// </summary>
[Fact]
public void Set_WrongKeyType_ThrowsInvalidOperationException()
@@ -150,7 +149,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set can perform operations.
/// Tests set can perform operations.
/// </summary>
[Fact]
public void Set_CanPerformOperations()
@@ -167,7 +166,7 @@ public class SetMethodTests : IDisposable
}
/// <summary>
/// Tests set with int key can perform operations.
/// Tests set with int key can perform operations.
/// </summary>
[Fact]
public void Set_WithIntKey_CanPerformOperations()
@@ -186,20 +185,20 @@ public class SetMethodTests : IDisposable
public class SetMethodInheritanceTests : IDisposable
{
private readonly TestExtendedDbContext _db;
private readonly string _dbPath;
private readonly Shared.TestExtendedDbContext _db;
/// <summary>
/// Initializes a new instance of the <see cref="SetMethodInheritanceTests"/> class.
/// Initializes a new instance of the <see cref="SetMethodInheritanceTests" /> class.
/// </summary>
public SetMethodInheritanceTests()
{
_dbPath = Path.Combine(Path.GetTempPath(), $"cbdd_set_inherit_{Guid.NewGuid()}.db");
_db = new Shared.TestExtendedDbContext(_dbPath);
_db = new TestExtendedDbContext(_dbPath);
}
/// <summary>
/// Disposes the resources used by this instance.
/// Disposes the resources used by this instance.
/// </summary>
public void Dispose()
{
@@ -208,7 +207,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set own collection returns correct instance.
/// Tests set own collection returns correct instance.
/// </summary>
[Fact]
public void Set_OwnCollection_ReturnsCorrectInstance()
@@ -219,7 +218,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set parent collection returns correct instance.
/// Tests set parent collection returns correct instance.
/// </summary>
[Fact]
public void Set_ParentCollection_ReturnsCorrectInstance()
@@ -230,7 +229,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set parent shorthand returns correct instance.
/// Tests set parent shorthand returns correct instance.
/// </summary>
[Fact]
public void Set_ParentShorthand_ReturnsCorrectInstance()
@@ -241,7 +240,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set parent int collection returns correct instance.
/// Tests set parent int collection returns correct instance.
/// </summary>
[Fact]
public void Set_ParentIntCollection_ReturnsCorrectInstance()
@@ -251,7 +250,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set parent custom key returns correct instance.
/// Tests set parent custom key returns correct instance.
/// </summary>
[Fact]
public void Set_ParentCustomKey_ReturnsCorrectInstance()
@@ -262,7 +261,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set unregistered entity throws invalid operation exception.
/// Tests set unregistered entity throws invalid operation exception.
/// </summary>
[Fact]
public void Set_UnregisteredEntity_ThrowsInvalidOperationException()
@@ -271,7 +270,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set own collection can perform operations.
/// Tests set own collection can perform operations.
/// </summary>
[Fact]
public void Set_OwnCollection_CanPerformOperations()
@@ -287,7 +286,7 @@ public class SetMethodInheritanceTests : IDisposable
}
/// <summary>
/// Tests set parent collection can perform operations.
/// Tests set parent collection can perform operations.
/// </summary>
[Fact]
public void Set_ParentCollection_CanPerformOperations()
@@ -301,4 +300,4 @@ public class SetMethodInheritanceTests : IDisposable
found.ShouldNotBeNull();
found.Name.ShouldBe("Bob");
}
}
}