nunit check throws exception
[TestFixture] public class AssertThrowsTests { [Test] public void Tests() { // Using a method as a delegate Assert.Throws<ArgumentException>(MethodThatThrows); // Using an anonymous delegate Assert.Throws<ArgumentException>( delegate { throw new ArgumentException(); }); // Using a Lambda expression Assert.Throws<ArgumentException>( () => { throw new ArgumentException(); }); } void MethodThatThrows() { throw new ArgumentException(); } }
Source: docs.nunit.org
nunit expect exception
[Test] public void TransferWithInsufficientFunds() { Account source = new Account(); source.Deposit(200m); Account destination = new Account(); destination.Deposit(150m); Assert.That(() => source.TransferFunds(destination, 300m), Throws.TypeOf<InsufficientFundsException>()); }
Source: www.blackwasp.co.uk