githubEdit

Null

ShouldBeNull and ShouldNotBeNull allow you to check whether a value is null.

ShouldNotBeNull returns the non-null value if it succeeds so that further assertions can be chained. When used with a reference type, the returned value is the same reference annotated as non-null. Equivalently, when used on a System.Nullable<T> expression, the returned value is the unwrapped T value.

ShouldBeNull

var myRef = "Hello World";
myRef.ShouldBeNull();

snippet sourcearrow-up-right | anchor

Exception

myRef
    should be null but was
"Hello World"

ShouldBeNull (nullable value type)

int? nullableValue = 42;
nullableValue.ShouldBeNull();

snippet sourcearrow-up-right | anchor

Exception

nullableValue
    should be null but was
42

ShouldNotBeNull

snippet sourcearrow-up-right | anchor

Exception

ShouldNotBeNull (nullable value type)

snippet sourcearrow-up-right | anchor

Exception

ShouldNotBeNull with chaining

snippet sourcearrow-up-right | anchor

Exception

ShouldNotBeNull with chaining (nullable value type)

snippet sourcearrow-up-right | anchor

Exception

Last updated