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 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.\"*");
        }
Exemple #3
0
        public void CompletedTaskShouldFail()
        {
            Task <bool> task = TaskResultBuilder.Completed();

            Action act = () => task.Should().BePending();

            act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be pending but was RanToCompletion.");
        }
        public void ShouldAllowChainingWithTypedException()
        {
            Task <bool> task = TaskResultBuilder.Faulted();

            Action act = () => task.Should().BeCompleted().WithException <InvalidCastException>().WithMessage("Expected failure.");

            act.ShouldNotThrow();
        }
Exemple #5
0
        public void CanceledTaskShouldFail()
        {
            Task <bool> task = TaskResultBuilder.Canceled();

            Action act = () => task.Should().BeCompletedSuccessfully();

            act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be completed successfully but was Canceled.");
        }
        public void ShouldAllowChainingWithAnd()
        {
            Task <bool> task = TaskResultBuilder.Faulted();

            Action act = () => task.Should().BeCompleted().And.BeCompleted();

            act.ShouldNotThrow();
        }
Exemple #7
0
        public void ShouldAllowChaining()
        {
            Task <bool> task = TaskResultBuilder.Completed();

            Action act = () => task.Should().BeCompletedSuccessfully().BeCompletedSuccessfully();

            act.ShouldNotThrow();
        }
        public void CanceledTaskShouldPass()
        {
            Task <bool> task = TaskResultBuilder.Canceled();

            Action act = () => task.Should().BeCompleted();

            act.ShouldNotThrow();
        }
Exemple #9
0
        public void FaultedTaskShouldPass()
        {
            Task <bool> task = TaskResultBuilder.Faulted();

            Action act = () => task.Should().BeFaulted();

            act.ShouldNotThrow();
        }
Exemple #10
0
        public void CanceledTaskShouldFail()
        {
            Task <bool> task = TaskResultBuilder.Canceled();

            Action act = () => task.Should().BeFaulted();

            act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be faulted but was Canceled.");
        }
Exemple #11
0
        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.");
        }
Exemple #12
0
        public void ShouldAllowChaining()
        {
            Task <bool> task = TaskResultBuilder.Canceled();

            Action act = () => task.Should().BeCanceled().BeCanceled();

            act.ShouldNotThrow();
        }
Exemple #13
0
        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 void WithExceptionShouldFailOnNullExceptionWithReasonFormatted()
        {
            Task <bool> task = TaskResultBuilder.Completed();

            Action act = () => task.Should().BeCompleted().WithException <InvalidCastException>("I said {0}", "so");

            act.ShouldThrow <AssertFailedException>().WithMessage("Expected a <System.InvalidCastException> to be thrown because I said so, but no exception was thrown.");
        }
Exemple #15
0
        public void PendingTaskShouldFail()
        {
            Task <bool> task = TaskResultBuilder.Pending();

            Action act = () => task.Should().BeCompletedSuccessfully();

            act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be completed successfully but was WaitingForActivation.");
        }
        public void PendingTaskShouldFailWithReasonFormatted()
        {
            Task <bool> task = TaskResultBuilder.Pending();

            Action act = () => task.Should().BeCompleted("I said {0}", "so");

            act.ShouldThrow <AssertFailedException>().WithMessage("Expected task to be completed because I said so but was WaitingForActivation.");
        }
        public void ShouldAllowChainingWithWhich()
        {
            Task <bool> task = TaskResultBuilder.Faulted();

            Action act = () => task.Should().BeCompleted().Which.IsCompleted.Should().BeTrue();

            act.ShouldNotThrow();
        }
Exemple #18
0
        public void PendingTaskShouldPass()
        {
            Task <bool> task = TaskResultBuilder.Pending();

            Action act = () => task.Should().BePending();

            act.ShouldNotThrow();
        }
Exemple #19
0
 public static Task Canceled()
 {
     return(TaskResultBuilder.Canceled());
 }
Exemple #20
0
 public static Task Pending()
 {
     return(TaskResultBuilder.Pending());
 }
Exemple #21
0
 public static Task Faulted(params Exception[] exceptions)
 {
     return(TaskResultBuilder.Faulted(exceptions));
 }
Exemple #22
0
 public static Task Completed()
 {
     return(TaskResultBuilder.Completed());
 }