Writing some integration tests we want to compare values read from the DB (int) against the object being used (enum field on a DTO).
So conceptually dto.EnumValue.Should().Be((MyEnum)expectedIntValue)
However these are both nullable. I know how to compare two nullable values of the same type but I can't see an obvious way to compare nullable int against nullable enum.
So far we ended up with:
if(dto.EnumValue == null)
expectedValue.Should().BeNull();
else
dto.EnumValue.Should().Be((MyEnum)expectedIntValue.Value);
I feel there is surely a way to do this better, adding logic to unit test expectations is not great?