Files
CBDD/tests/CBDD.Tests/VisibilityTests.cs
Joseph Doherty 3ffd468c79
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 45s
NuGet Publish / publish-to-gitea (push) Successful in 52s
Fix audit findings for coverage, architecture checks, and XML docs
2026-02-20 15:43:25 -05:00

64 lines
2.0 KiB
C#
Executable File

using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core.Collections;
using Xunit;
using System.Linq;
namespace ZB.MOM.WW.CBDD.Tests;
public class VisibilityTests
{
public class VisibilityEntity
{
// Should be included
/// <summary>
/// Gets or sets the normal prop.
/// </summary>
public int NormalProp { get; set; }
// Should be included (serialization usually writes it)
/// <summary>
/// Gets or sets the private set prop.
/// </summary>
public int PrivateSetProp { get; private set; }
// Should be included
/// <summary>
/// Gets or sets the init prop.
/// </summary>
public int InitProp { get; init; }
// Fields - typically included in BSON if public, but reflection need GetFields
public string PublicField = string.Empty;
// Should NOT be included
private int _privateField;
// Helper to set private
/// <summary>
/// Tests set private.
/// </summary>
/// <param name="val">Value assigned to the private field.</param>
public void SetPrivate(int val) => _privateField = val;
}
/// <summary>
/// Tests generate schema visibility checks.
/// </summary>
[Fact]
public void GenerateSchema_VisibilityChecks()
{
var schema = BsonSchemaGenerator.FromType<VisibilityEntity>();
schema.Fields.ShouldContain(f => f.Name == "normalprop");
schema.Fields.ShouldContain(f => f.Name == "privatesetprop");
schema.Fields.ShouldContain(f => f.Name == "initprop");
// Verify assumption about fields
// Current implementation uses GetProperties, so publicfield might be missing.
// We will assert current status and then fix if requested/failed.
schema.Fields.ShouldContain(f => f.Name == "publicfield"); // This will likely fail currently
schema.Fields.ShouldNotContain(f => f.Name == "_privatefield");
}
}