Description
Sometimes it is needed to verify value type against default value.
Common use case - verify that value in rest response is not empty, e.g. Guid (not empty) or enums (not Undefined value).
Current alternative - using EqualConstraint (e.g. Is.Not.EqualTo(Guid.Empty)
, Is.Not.EqualTo(default(MyEnumTypeName))
), which is not always convenient.
Details:
-
If actual is non-nullable value type - should pass if
actual == default
. -
If actual is nullable value type - should pass if
actual
is equal to default value of underlying type, so the following code could be possible:
MyValueType? actual = ...;
Assert.That(actual, Is.Not.Null & Is.Not.Default);
Open question - what the expected behavior if nullable actual
is null? Technically it is default value for nullable value type, but I think would make sense to fail it in this case, i.e. only account for underlying type default value.
- Not sure about the behavior for reference types. Not sure it should be allowed at all. Another option - allow (passing when null), and provide roslyn analyzer with warning if used against reference type.