Initialize CBDD solution and add a .NET-focused gitignore for generated artifacts.
This commit is contained in:
57
tests/CBDD.Tests/SchemaTests.cs
Executable file
57
tests/CBDD.Tests/SchemaTests.cs
Executable file
@@ -0,0 +1,57 @@
|
||||
using ZB.MOM.WW.CBDD.Bson;
|
||||
using ZB.MOM.WW.CBDD.Core.Collections;
|
||||
using ZB.MOM.WW.CBDD.Core.Indexing;
|
||||
using ZB.MOM.WW.CBDD.Shared.TestDbContext_TestDbContext_Mappers;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.CBDD.Tests;
|
||||
|
||||
public class SchemaTests
|
||||
{
|
||||
private static readonly System.Collections.Concurrent.ConcurrentDictionary<string, ushort> _testKeyMap = new(StringComparer.OrdinalIgnoreCase);
|
||||
static SchemaTests()
|
||||
{
|
||||
ushort id = 1;
|
||||
foreach (var k in new[] { "_id", "name", "mainaddress", "otheraddresses", "tags", "secret", "street", "city" }) _testKeyMap[k] = id++;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsedKeys_ShouldReturnAllKeys()
|
||||
{
|
||||
var mapper = new ZB_MOM_WW_CBDD_Shared_ComplexUserMapper();
|
||||
var keys = mapper.UsedKeys.ToList();
|
||||
|
||||
keys.ShouldContain("_id");
|
||||
keys.ShouldContain("name");
|
||||
keys.ShouldContain("mainaddress");
|
||||
keys.ShouldContain("otheraddresses");
|
||||
keys.ShouldContain("tags");
|
||||
keys.ShouldContain("secret");
|
||||
keys.ShouldContain("street");
|
||||
keys.ShouldContain("city");
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSchema_ShouldReturnBsonSchema()
|
||||
{
|
||||
var mapper = new ZB_MOM_WW_CBDD_Shared_ComplexUserMapper();
|
||||
var schema = mapper.GetSchema();
|
||||
|
||||
var idField = schema.Fields.FirstOrDefault(f => f.Name == "_id");
|
||||
idField.ShouldNotBeNull();
|
||||
idField.Type.ShouldBe(BsonType.ObjectId);
|
||||
|
||||
var nameField = schema.Fields.FirstOrDefault(f => f.Name == "name");
|
||||
nameField.ShouldNotBeNull();
|
||||
nameField.Type.ShouldBe(BsonType.String);
|
||||
|
||||
var addressField = schema.Fields.FirstOrDefault(f => f.Name == "mainaddress");
|
||||
addressField.ShouldNotBeNull();
|
||||
addressField.Type.ShouldBe(BsonType.Document);
|
||||
addressField.NestedSchema.ShouldNotBeNull();
|
||||
// Address in MockEntities has City (Nested)
|
||||
addressField.NestedSchema.Fields.ShouldContain(f => f.Name == "city");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user