assert.catch c# nunit code example
Example 1: nunit throws message
[Test]
public void TestException()
{
MyException ex = Assert.Throws<MyException>(
delegate { throw new MyException("message", 42); });
Assert.That(ex.Message, Is.EqualTo("message"));
Assert.That(ex.MyParam, Is.EqualTo(42));
}
Example 2: nunit throws message
[Test]
public void TestException()
{
Assert.Throws(Is.TypeOf<MyException>()
.And.Message.EqualTo("message")
.And.Property("MyParam").EqualTo(42),
delegate { throw new MyException("message", 42); });
}