public void WithExceptionShouldFailIfNoExceptionMatches() { Task <bool> task = TaskResultBuilder.Faulted(new InvalidOperationException("Unexpected failure.")); Action act = () => task.Should().BeCompleted().WithException <InvalidCastException>(); act.ShouldThrow <AssertFailedException>().WithMessage("Expected a <System.InvalidCastException> to be thrown, but found a*System.InvalidOperationException with message \"Unexpected failure.\"*"); }
public void FaultedTaskShouldPass() { Task <bool> task = TaskResultBuilder.Faulted(); Action act = () => task.Should().BeCompleted(); act.ShouldNotThrow(); }
public void ShouldAllowChainingWithTypedException() { Task <bool> task = TaskResultBuilder.Faulted(); Action act = () => task.Should().BeCompleted().WithException <InvalidCastException>().WithMessage("Expected failure."); act.ShouldNotThrow(); }
public void WithExceptionShouldPassIfAtLeastOneExceptionMatches() { Task <bool> task = TaskResultBuilder.Faulted(new InvalidCastException("Expected failure."), new InvalidProgramException("Other expected failure.")); Action act = () => task.Should().BeCompleted().WithException <InvalidCastException>().WithMessage("Expected failure."); act.ShouldNotThrow(); }
public void ShouldAllowChainingWithWhich() { Task <bool> task = TaskResultBuilder.Faulted(); Action act = () => task.Should().BeCompleted().Which.IsCompleted.Should().BeTrue(); act.ShouldNotThrow(); }
public void ShouldAllowChainingWithAnd() { Task <bool> task = TaskResultBuilder.Faulted(); Action act = () => task.Should().BeCompleted().And.BeCompleted(); act.ShouldNotThrow(); }
public void FaultedTaskShouldFail() { Task <bool> task = TaskResultBuilder.Faulted(); Action act = () => task.Should().BeCompletedSuccessfully(); act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be completed successfully but was Faulted."); }
public void FaultedTaskShouldFailWithReasonFormatted() { Task <bool> task = TaskResultBuilder.Faulted(); Action act = () => task.Should().BeCanceled("I said {0}", "so"); act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be canceled because I said so but was Faulted."); }
public void FaultedTaskShouldFailWithReason() { Task <bool> task = TaskResultBuilder.Faulted(); Action act = () => task.Should().BePending(because: "I said so"); act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be pending because I said so but was Faulted."); }
public static Task Faulted(params Exception[] exceptions) { return(TaskResultBuilder.Faulted(exceptions)); }