I've found a couple of scenarios where exceptions are being thrown when storing documents due to null values for Duplicate fields.
[Fact]
public void when_field_is_null_due_to_nesting()
{
StoreOptions(_ => _.Schema.For<Target>().Duplicate(t => t.Inner.Number));
using (var session = theStore.OpenSession())
{
session.Store(new Target
{
Number = 1,
Inner = null
});
session.SaveChanges();
}
using (var session = theStore.OpenSession())
{
session.Query<Target>().Where(x => x.Number == 1)
.ToArray()
.Select(x => x.Number)
.ShouldHaveTheSameElementsAs(1);
}
}
Throws a NullReferenceException.
[Fact]
public void when_string_enum_is_null_due_to_nullable_type()
{
StoreOptions(_ =>
{
_.Serializer(new JsonNetSerializer{EnumStorage = EnumStorage.AsString});
_.Schema.For<Target>().Duplicate(t => t.NullableColor);
});
using (var session = theStore.OpenSession())
{
session.Store(new Target
{
Number = 1,
NullableColor = null
});
session.SaveChanges();
}
using (var session = theStore.OpenSession())
{
session.Query<Target>().Where(x => x.Number == 1)
.ToArray()
.Select(x => x.Number)
.ShouldHaveTheSameElementsAs(1);
}
}
Throws ArgumentNullException when calling System.RuntimeType.GetEnumName() internally.
N.B. I added a NullableColor property of type Colours? to the Target class for this one.
I'd be happy to contribute a PR if you accept them and these scenarios are valid use cases.
@richardoliver-umusic all of your cases looks valid to me, we'd be happy to take PR with fixes :)
Cheers @oskardudycz. I'll report back when i have something.
Most helpful comment
Cheers @oskardudycz. I'll report back when i have something.