diff --git a/src/Context.Tests/ImmutableConventionTests.cs b/src/Context.Tests/ImmutableConventionTests.cs index ad8eaa5..d8c775d 100644 --- a/src/Context.Tests/ImmutableConventionTests.cs +++ b/src/Context.Tests/ImmutableConventionTests.cs @@ -81,6 +81,106 @@ public interface IA } } + public class NullableReferenceTypeCase : IClassFixture + { + private readonly MongoDbContextData _context; + + public NullableReferenceTypeCase(MongoResource mongoResource) + { + _context = CreateContext(mongoResource); + } + + [Fact] + public async Task ApplyConvention_WithoutValue_SerializeSuccessful() + { + // Arrange + IMongoCollection collection = _context.CreateCollection(); + + // Act + await collection.InsertOneAsync(new A("a")); + + // Assert + A result = await collection.FindSync(FilterDefinition.Empty).FirstAsync(); + result.MatchSnapshot(); + } + + [Fact] + public async Task ApplyConvention_WithValue_SerializeSuccessful() + { + // Arrange + IMongoCollection collection = _context.CreateCollection(); + + // Act + await collection.InsertOneAsync(new A("a", "b")); + + // Assert + A result = await collection.FindSync(FilterDefinition.Empty).FirstAsync(); + result.MatchSnapshot(); + } + + public class A + { + public A(string _a, string? _b = default) + { + _A = _a; + _B = _b; + } + + public string _A { get; } + public string? _B { get; } + } + } + + public class NullableValueTypeCase : IClassFixture + { + private readonly MongoDbContextData _context; + + public NullableValueTypeCase(MongoResource mongoResource) + { + _context = CreateContext(mongoResource); + } + + [Fact] + public async Task ApplyConvention_WithoutValue_SerializeSuccessful() + { + // Arrange + IMongoCollection collection = _context.CreateCollection(); + + // Act + await collection.InsertOneAsync(new A("a")); + + // Assert + A result = await collection.FindSync(FilterDefinition.Empty).FirstAsync(); + result.MatchSnapshot(); + } + + [Fact] + public async Task ApplyConvention_WithValue_SerializeSuccessful() + { + // Arrange + IMongoCollection collection = _context.CreateCollection(); + + // Act + await collection.InsertOneAsync(new A("a", 9)); + + // Assert + A result = await collection.FindSync(FilterDefinition.Empty).FirstAsync(); + result.MatchSnapshot(); + } + + public class A + { + public A(string _a, int? _b = default) + { + _A = _a; + _B = _b; + } + + public string _A { get; } + public int? _B { get; } + } + } + public class AbstractImmutableWithBasePropertyCase : IClassFixture { private readonly MongoDbContextData _context; diff --git a/src/Context.Tests/__snapshots__/NullableReferenceTypeCase.ApplyConvention_WithValue_SerializeSuccessful.snap b/src/Context.Tests/__snapshots__/NullableReferenceTypeCase.ApplyConvention_WithValue_SerializeSuccessful.snap new file mode 100644 index 0000000..322cced --- /dev/null +++ b/src/Context.Tests/__snapshots__/NullableReferenceTypeCase.ApplyConvention_WithValue_SerializeSuccessful.snap @@ -0,0 +1,4 @@ +{ + "_A": "a", + "_B": "b" +} diff --git a/src/Context.Tests/__snapshots__/NullableReferenceTypeCase.ApplyConvention_WithoutValue_SerializeSuccessful.snap b/src/Context.Tests/__snapshots__/NullableReferenceTypeCase.ApplyConvention_WithoutValue_SerializeSuccessful.snap new file mode 100644 index 0000000..2f2130a --- /dev/null +++ b/src/Context.Tests/__snapshots__/NullableReferenceTypeCase.ApplyConvention_WithoutValue_SerializeSuccessful.snap @@ -0,0 +1,4 @@ +{ + "_A": "a", + "_B": null +} diff --git a/src/Context.Tests/__snapshots__/NullableValueTypeCase.ApplyConvention_WithValue_SerializeSuccessful.snap b/src/Context.Tests/__snapshots__/NullableValueTypeCase.ApplyConvention_WithValue_SerializeSuccessful.snap new file mode 100644 index 0000000..a5b78f6 --- /dev/null +++ b/src/Context.Tests/__snapshots__/NullableValueTypeCase.ApplyConvention_WithValue_SerializeSuccessful.snap @@ -0,0 +1,4 @@ +{ + "_A": "a", + "_B": 9 +} diff --git a/src/Context.Tests/__snapshots__/NullableValueTypeCase.ApplyConvention_WithoutValue_SerializeSuccessful.snap b/src/Context.Tests/__snapshots__/NullableValueTypeCase.ApplyConvention_WithoutValue_SerializeSuccessful.snap new file mode 100644 index 0000000..2f2130a --- /dev/null +++ b/src/Context.Tests/__snapshots__/NullableValueTypeCase.ApplyConvention_WithoutValue_SerializeSuccessful.snap @@ -0,0 +1,4 @@ +{ + "_A": "a", + "_B": null +}