public void When_async_method_throws_expected_exception_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var asyncObject = new AsyncClass(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => { Func <Task> asyncFunction = async() => { await asyncObject.ThrowAsync <ArgumentException>(); }; asyncFunction.ShouldThrow <ArgumentException>(); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldNotThrow(); }
public void When_async_method_throws_unexpected_exception_it_should_fail() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var asyncObject = new AsyncClass(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => { Func <Task> asyncFunction = async() => { await asyncObject.ThrowAsync <ArgumentException>(); }; asyncFunction.ShouldThrow <InvalidOperationException>(); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldThrow <AssertFailedException>() .WithMessage("Expected System.InvalidOperationException, but found*System.ArgumentException*"); }
public void When_async_method_throws_exception_expected_not_to_be_thrown_it_should_fail() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var asyncObject = new AsyncClass(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => { Func <Task> asyncFunction = async() => { await asyncObject.ThrowAsync <ArgumentException>(); }; asyncFunction.ShouldNotThrow <ArgumentException>(); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldThrow <AssertFailedException>() .WithMessage("Did not expect System.ArgumentException, but found one*"); }
public void When_async_method_throws_exception_and_expecting_not_to_throw_anything_it_should_fail() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var asyncObject = new AsyncClass(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => { Func <Task> asyncFunction = async() => { await asyncObject.ThrowAsync <ArgumentException>(); }; asyncFunction.ShouldNotThrow(); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldThrow <AssertFailedException>() .WithMessage("Did not expect any exception, but found a System.ArgumentException", ComparisonMode.StartWith); }