public async Task PerformsSideEffectOnNotSuccessfulResults() { var moqed = new Mock <ISideEffectsWrapper>(); var token = new CancellationTokenSource().Token; moqed .Setup(x => x.Effect()) .Verifiable(); moqed .Setup(x => x.CancellableEffect(It.Is <CancellationToken>(ct => ct == token))) .Verifiable(); moqed .Setup(x => x.AsyncEffect()) .Verifiable(); moqed .Setup(x => x.CancellableEffect(It.Is <CancellationToken>(ct => ct == token))) .Verifiable(); var exception = new TestException(); moqed .Setup(x => x.EffectPopulatedWithException(It.Is <TestException>(te => te == exception))) .Verifiable(); moqed .Setup(x => x.CancellableEffectPopulatedWithException(It.Is <TestException>(te => te == exception), It.Is <CancellationToken>(ct => ct == token))) .Verifiable(); moqed .Setup(x => x.CancellableEffectPopulatedWithExceptionAsync(It.Is <TestException>(te => te == exception), It.Is <CancellationToken>(ct => ct == token))) .Verifiable(); moqed .Setup(x => x.EffectPopulatedWithExceptionAsync(It.Is <TestException>(te => te == exception))) .Verifiable(); var fail = exception .AsFail(); fail .EffectIfNotSuccessful(moqed.Object.Effect) .SideEffect(x => x .Should() .BeSameAs(fail)) .EffectIfNotSuccessful(moqed.Object.CancellableEffect, token) .SideEffect(x => x .Should() .BeSameAs(fail)) .EffectIfNotSuccessful(moqed.Object.EffectPopulatedWithException) .SideEffect(x => x .Should() .BeSameAs(fail)) .EffectIfNotSuccessful(moqed.Object.CancellableEffectPopulatedWithException, token) .SideEffect(x => x .Should() .BeSameAs(fail)); await fail .EffectIfNotSuccessfulAsync(moqed.Object.AsyncEffect) .ContinueWith(x => x.Result .Should() .BeSameAs(fail)); await fail .EffectIfNotSuccessfulAsync(moqed.Object.AsyncCancellableEffect, token) .ContinueWith(x => x.Result .Should() .BeSameAs(fail)); await fail .EffectIfNotSuccessfulAsync(moqed.Object.CancellableEffectPopulatedWithExceptionAsync, token) .ContinueWith(x => x.Result .Should() .BeSameAs(fail)); await fail .EffectIfNotSuccessfulAsync(moqed.Object.EffectPopulatedWithExceptionAsync) .ContinueWith(x => x.Result .Should() .BeSameAs(fail)); moqed .Verify(x => x.Effect(), Times.Once); moqed .Verify(x => x.CancellableEffect(It.Is <CancellationToken>(ct => ct == token)), Times.Once); moqed .Verify( x => x.CancellableEffectPopulatedWithException(It.Is <TestException>(te => te == exception), It.Is <CancellationToken>(ct => ct == token)), Times.Once); moqed .Verify( x => x.EffectPopulatedWithException(It.Is <TestException>(te => te == exception)), Times.Once); moqed .Verify(x => x.AsyncEffect(), Times.Once); moqed .Verify(x => x.AsyncCancellableEffect(It.Is <CancellationToken>(ct => ct == token)), Times.Once); moqed .Verify( x => x.CancellableEffectPopulatedWithExceptionAsync(It.Is <TestException>(te => te == exception), It.Is <CancellationToken>(ct => ct == token)), Times.Once); moqed .Verify( x => x.EffectPopulatedWithExceptionAsync(It.Is <TestException>(te => te == exception)), Times.Once); }