public async Task ProcessPaymentAsync_ForValidRequestHavingAmountGreaterThan500AndPremiumFails4Times_PremiumGatewayIsCalled3TimesAndFailedStatusIsReturnedAsync() { //Arrange var model = GetPaymentRequestModel(540); _premiumPaymentGateway.ProcessPaymentAsync(Arg.Any <PaymentRequestModel>()) .Returns(x => throw new Exception(), x => throw new Exception(), x => throw new Exception(), x => throw new Exception(), x => Task.FromResult(PaymentStatus.Processed)); _logger.When(x => x.LogError(Arg.Any <Exception>())).Do(x => { }); //Act var actual = await _paymentBusiness.ProcessPaymentAsync(model); //Assert Assert.AreEqual(PaymentStatus.Failed, actual); _serviceAccessor.Received(2).Invoke(Arg.Any <string>()); await _cheapPaymentGateway.Received(0).ProcessPaymentAsync(Arg.Any <PaymentRequestModel>()); await _expensivePaymentGateway.Received(0).ProcessPaymentAsync(Arg.Any <PaymentRequestModel>()); await _expensivePaymentGateway.Received(0).IsAvailableAsync(); await _premiumPaymentGateway.Received(4).ProcessPaymentAsync(Arg.Any <PaymentRequestModel>()); await _unitOfWork.PaymentsRepository.Received(1).AddAsync(Arg.Any <PaymentEntities.Entities.Payment>()); _unitOfWork.Received(1).Complete(); _logger.Received(4).LogError(Arg.Any <Exception>()); }