public void When_async_method_succeeds_and_expected_not_to_throw_particular_exception_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var asyncObject = new AsyncClass(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => asyncObject .Awaiting(async x => await asyncObject.SucceedAsync()) .ShouldNotThrow <InvalidOperationException>(); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldNotThrow(); }
public void When_async_method_does_not_throw_exception_and_expecting_not_to_throw_anything_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var asyncObject = new AsyncClass(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => { Func <Task> asyncFunction = async() => { await asyncObject.SucceedAsync(); }; asyncFunction.ShouldNotThrow(); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldNotThrow(); }
public void When_async_method_does_not_throw_expected_exception_it_should_fail() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var asyncObject = new AsyncClass(); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => { Func <Task> asyncFunction = async() => { await asyncObject.SucceedAsync(); }; asyncFunction.ShouldThrow <InvalidOperationException>(); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldThrow <AssertFailedException>() .WithMessage("Expected System.InvalidOperationException, but no exception was thrown*"); }