public void Exception_not_occuring_assertions() { SomeType someObject = new SomeType(); Action action = () => someObject.SomeMethod(); Action actionThatThrows = () => someObject.SomeMethodThatThrows(null); action.ShouldNotThrow(); actionThatThrows.ShouldNotThrow <InvalidCastException>(); }
public void Exception_occuring_assertions() { SomeType someObject = new SomeType(); someObject.Invoking(subject => subject.SomeMethodThatThrows("Something")) .ShouldThrow <ArgumentException>() .WithMessage("Invalid message\r\nParameter name: message"); Action throwAction = () => someObject.SomeMethodThatThrows("Hello"); throwAction.ShouldThrow <ArgumentException>() .WithInnerException <ArgumentOutOfRangeException>() .WithInnerMessage("whatever\r\nParameter name: message"); throwAction.ShouldThrow <ArgumentException>().Which.ParamName.Should().Be("message"); throwAction.ShouldThrow <ArgumentException>().Where(exception => exception.Message == "Invalid message\r\nParameter name: message"); throwAction.ShouldThrow <ArgumentException>().WithMessage("*val*"); }