Reformat / cleanup
This commit is contained in:
@@ -1,36 +1,48 @@
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
using ZB.MOM.WW.CBDD.Shared;
|
||||
using System.Linq;
|
||||
|
||||
namespace ZB.MOM.WW.CBDD.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for Source Generator enhancements:
|
||||
/// 1. Property inheritance from base classes (including Id)
|
||||
/// 2. Exclusion of computed getter-only properties
|
||||
/// 3. Recognition of advanced collection types (HashSet, ISet, LinkedList, etc.)
|
||||
/// Tests for Source Generator enhancements:
|
||||
/// 1. Property inheritance from base classes (including Id)
|
||||
/// 2. Exclusion of computed getter-only properties
|
||||
/// 3. Recognition of advanced collection types (HashSet, ISet, LinkedList, etc.)
|
||||
/// </summary>
|
||||
public class SourceGeneratorFeaturesTests : 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="SourceGeneratorFeaturesTests"/> class.
|
||||
/// Initializes a new instance of the <see cref="SourceGeneratorFeaturesTests" /> class.
|
||||
/// </summary>
|
||||
public SourceGeneratorFeaturesTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"test_sg_features_{Guid.NewGuid()}.db");
|
||||
_walPath = Path.Combine(Path.GetTempPath(), $"test_sg_features_{Guid.NewGuid()}.wal");
|
||||
|
||||
_db = new Shared.TestDbContext(_dbPath);
|
||||
_db = new TestDbContext(_dbPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the resources used by this instance.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_db?.Dispose();
|
||||
|
||||
if (File.Exists(_dbPath))
|
||||
File.Delete(_dbPath);
|
||||
if (File.Exists(_walPath))
|
||||
File.Delete(_walPath);
|
||||
}
|
||||
|
||||
#region Inheritance Tests
|
||||
|
||||
/// <summary>
|
||||
/// Tests derived entity inherits id from base class.
|
||||
/// Tests derived entity inherits id from base class.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DerivedEntity_InheritsId_FromBaseClass()
|
||||
@@ -57,7 +69,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests derived entity update works with inherited id.
|
||||
/// Tests derived entity update works with inherited id.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DerivedEntity_Update_WorksWithInheritedId()
|
||||
@@ -90,7 +102,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests derived entity query works with inherited properties.
|
||||
/// Tests derived entity query works with inherited properties.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DerivedEntity_Query_WorksWithInheritedProperties()
|
||||
@@ -120,7 +132,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
#region Computed Properties Tests
|
||||
|
||||
/// <summary>
|
||||
/// Tests computed properties are not serialized.
|
||||
/// Tests computed properties are not serialized.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ComputedProperties_AreNotSerialized()
|
||||
@@ -151,7 +163,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests computed properties update does not break.
|
||||
/// Tests computed properties update does not break.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ComputedProperties_UpdateDoesNotBreak()
|
||||
@@ -189,7 +201,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
#region Advanced Collections Tests
|
||||
|
||||
/// <summary>
|
||||
/// Tests hash set serializes and deserializes.
|
||||
/// Tests hash set serializes and deserializes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void HashSet_SerializesAndDeserializes()
|
||||
@@ -219,7 +231,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests iset serializes and deserializes.
|
||||
/// Tests iset serializes and deserializes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ISet_SerializesAndDeserializes()
|
||||
@@ -250,7 +262,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests linked list serializes and deserializes.
|
||||
/// Tests linked list serializes and deserializes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void LinkedList_SerializesAndDeserializes()
|
||||
@@ -281,7 +293,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests queue serializes and deserializes.
|
||||
/// Tests queue serializes and deserializes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Queue_SerializesAndDeserializes()
|
||||
@@ -311,7 +323,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests stack serializes and deserializes.
|
||||
/// Tests stack serializes and deserializes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Stack_SerializesAndDeserializes()
|
||||
@@ -341,7 +353,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests hash set with nested objects serializes and deserializes.
|
||||
/// Tests hash set with nested objects serializes and deserializes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void HashSet_WithNestedObjects_SerializesAndDeserializes()
|
||||
@@ -351,8 +363,10 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
{
|
||||
Name = "Test Nested HashSet"
|
||||
};
|
||||
entity.Addresses.Add(new Address { Street = "123 Main St", City = new City { Name = "NYC", ZipCode = "10001" } });
|
||||
entity.Addresses.Add(new Address { Street = "456 Oak Ave", City = new City { Name = "LA", ZipCode = "90001" } });
|
||||
entity.Addresses.Add(
|
||||
new Address { Street = "123 Main St", City = new City { Name = "NYC", ZipCode = "10001" } });
|
||||
entity.Addresses.Add(new Address
|
||||
{ Street = "456 Oak Ave", City = new City { Name = "LA", ZipCode = "90001" } });
|
||||
|
||||
// Act
|
||||
var id = _db.AdvancedCollectionEntities.Insert(entity);
|
||||
@@ -371,7 +385,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests iset with nested objects serializes and deserializes.
|
||||
/// Tests iset with nested objects serializes and deserializes.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ISet_WithNestedObjects_SerializesAndDeserializes()
|
||||
@@ -403,7 +417,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests advanced collections all types in single entity.
|
||||
/// Tests advanced collections all types in single entity.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void AdvancedCollections_AllTypesInSingleEntity()
|
||||
@@ -454,7 +468,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
#region Private Setters Tests
|
||||
|
||||
/// <summary>
|
||||
/// Tests entity with private setters can be deserialized.
|
||||
/// Tests entity with private setters can be deserialized.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EntityWithPrivateSetters_CanBeDeserialized()
|
||||
@@ -475,7 +489,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests entity with private setters update works.
|
||||
/// Tests entity with private setters update works.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EntityWithPrivateSetters_Update_Works()
|
||||
@@ -501,7 +515,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests entity with private setters query works.
|
||||
/// Tests entity with private setters query works.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EntityWithPrivateSetters_Query_Works()
|
||||
@@ -530,7 +544,7 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
#region Init-Only Setters Tests
|
||||
|
||||
/// <summary>
|
||||
/// Tests entity with init setters can be deserialized.
|
||||
/// Tests entity with init setters can be deserialized.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EntityWithInitSetters_CanBeDeserialized()
|
||||
@@ -557,15 +571,18 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests entity with init setters query works.
|
||||
/// Tests entity with init setters query works.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EntityWithInitSetters_Query_Works()
|
||||
{
|
||||
// Arrange
|
||||
var entity1 = new EntityWithInitSetters { Id = ObjectId.NewObjectId(), Name = "Alpha", Age = 20, CreatedAt = DateTime.UtcNow };
|
||||
var entity2 = new EntityWithInitSetters { Id = ObjectId.NewObjectId(), Name = "Beta", Age = 30, CreatedAt = DateTime.UtcNow };
|
||||
var entity3 = new EntityWithInitSetters { Id = ObjectId.NewObjectId(), Name = "Gamma", Age = 40, CreatedAt = DateTime.UtcNow };
|
||||
var entity1 = new EntityWithInitSetters
|
||||
{ Id = ObjectId.NewObjectId(), Name = "Alpha", Age = 20, CreatedAt = DateTime.UtcNow };
|
||||
var entity2 = new EntityWithInitSetters
|
||||
{ Id = ObjectId.NewObjectId(), Name = "Beta", Age = 30, CreatedAt = DateTime.UtcNow };
|
||||
var entity3 = new EntityWithInitSetters
|
||||
{ Id = ObjectId.NewObjectId(), Name = "Gamma", Age = 40, CreatedAt = DateTime.UtcNow };
|
||||
|
||||
_db.InitSetterEntities.Insert(entity1);
|
||||
_db.InitSetterEntities.Insert(entity2);
|
||||
@@ -582,17 +599,4 @@ public class SourceGeneratorFeaturesTests : IDisposable
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the resources used by this instance.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_db?.Dispose();
|
||||
|
||||
if (File.Exists(_dbPath))
|
||||
File.Delete(_dbPath);
|
||||
if (File.Exists(_walPath))
|
||||
File.Delete(_walPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user