Initialize CBDD solution and add a .NET-focused gitignore for generated artifacts.

This commit is contained in:
Joseph Doherty
2026-02-20 12:54:07 -05:00
commit b8ed5ec500
214 changed files with 101452 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core.Collections;
using Xunit;
using System.Collections.Generic;
using System;
using System.Linq;
namespace ZB.MOM.WW.CBDD.Tests;
public class RobustnessTests
{
public struct Point
{
public int X { get; set; }
public int Y { get; set; }
}
public class RobustEntity
{
public List<int?> NullableInts { get; set; } = new();
public Dictionary<string, int> Map { get; set; } = new();
public IEnumerable<string> EnumerableStrings { get; set; } = Array.Empty<string>();
public Point Location { get; set; }
public Point? NullableLocation { get; set; }
}
[Fact]
public void GenerateSchema_RobustnessChecks()
{
var schema = BsonSchemaGenerator.FromType<RobustEntity>();
// 1. Nullable Value Types in List
var nullableInts = schema.Fields.First(f => f.Name == "nullableints");
nullableInts.Type.ShouldBe(BsonType.Array);
nullableInts.ArrayItemType.ShouldBe(BsonType.Int32);
// Note: Current Schema doesn't capture "ItemIsNullable", but verifying it doesn't crash/return Undefined
// 2. Dictionary (likely treated as Array of KVPs currently, or Undefined if structs fail)
// With current logic: Dictionary implements IEnumerable<KVP>. KVP is struct.
// If generator doesn't handle structs as Documents, item type might be Undefined.
var map = schema.Fields.First(f => f.Name == "map");
map.Type.ShouldBe(BsonType.Array);
// 3. IEnumerable property
var enumerable = schema.Fields.First(f => f.Name == "enumerablestrings");
enumerable.Type.ShouldBe(BsonType.Array);
enumerable.ArrayItemType.ShouldBe(BsonType.String);
// 4. Struct
var location = schema.Fields.First(f => f.Name == "location");
// Structs should be treated as Documents in BSON if not primitive
location.Type.ShouldBe(BsonType.Document);
location.NestedSchema.ShouldNotBeNull();
location.NestedSchema.Fields.ShouldContain(f => f.Name == "x");
// 5. Nullable Struct
var nullableLocation = schema.Fields.First(f => f.Name == "nullablelocation");
nullableLocation.Type.ShouldBe(BsonType.Document);
nullableLocation.IsNullable.ShouldBeTrue();
nullableLocation.NestedSchema.ShouldNotBeNull();
}
}