Question

I know how to write this using Nunit,

Assert.That(exception, Is.InstanceOfType(typeof(TypeNotRegisteredException)));

How can I write the same thing using in Xunit, as Xunit does not have Assert.That.

Was it helpful?

Solution

You might be looking for:

Assert.IsType<TypeNotRegisteredException>(exception);

Let me know if this is close to what you're looking for.

OTHER TIPS

I am thinking you are asking what is the equivalent of the InstanceOfType assert rather than the equivalent of Assert.That. The latter is just a better syntax that enables you to read your asserts like English.

The equivalent of InstanceOfType assert in Xunit is IsType:

Assert.IsType<TypeNotRegisteredException>(exception);

Note that the nunit equivalent is, indeed:

Assert.IsInstanceOf<TypeNotRegisteredException>(exception);

(the older IsInstanceOfType assert is deprecated - http://www.nunit.org/index.php?p=typeAsserts&r=2.5.1 )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top