public async Task Withdrawal_Withdraw20_ReturnsOkAndBalance5() { //// Arrange decimal postWithdrawalBalanceAmount = 5; Balance postWithdrawalBalance = new Balance() { Amount = postWithdrawalBalanceAmount }; BalanceResponse expectedBalanceResponse = new BalanceResponse() { Amount = postWithdrawalBalanceAmount }; decimal withdrawalAmount = 20; WithdrawalRequest withdrawalRequest = new WithdrawalRequest { Amount = withdrawalAmount }; // Setup Mocks Mock <IWalletService> walletServiceMock = new Mock <IWalletService>(); Withdrawal withdrawal = new Withdrawal { Amount = withdrawalAmount }; walletServiceMock .Setup(walletService => walletService.WithdrawFundsAsync(withdrawal)) .Returns(Task.FromResult(postWithdrawalBalance)); IWalletService walletService = walletServiceMock.Object; ILogger <WalletController> logger = Mock.Of <ILogger <WalletController> >(); IMapper mapper = Mock.Of <IMapper>(mapper => mapper.Map <Withdrawal>(withdrawalRequest) == withdrawal && mapper.Map <BalanceResponse>(postWithdrawalBalance) == expectedBalanceResponse); // Initialize SUT WalletController walletController = new WalletController(logger, mapper, walletService); //// Act ActionResult <BalanceResponse> actionResult = await walletController.Withdraw(withdrawalRequest); ActionResult actualActionResult = actionResult.Result; //// Assert OkObjectResult okObjectResult = Assert.IsType <OkObjectResult>(actionResult.Result); BalanceResponse actualBalanceResponse = Assert.IsType <BalanceResponse>(okObjectResult.Value); Assert.Equal(expectedBalanceResponse, actualBalanceResponse); walletServiceMock.Verify(walletService => walletService.WithdrawFundsAsync(withdrawal), Times.Once); walletServiceMock.VerifyNoOtherCalls(); }
public async Task Withdraw_Wallet_Fund_Should_Return_Bad_Request_Response_When_Amount_Is_Less_Than_One() { //Arrange var withdrawWallet = new WithdrawFundRequestModel { Amount = 0 }; Mediator.Setup(x => x.Send(It.IsAny <WithdrawFundRequestModel>(), new CancellationToken())). Throws(new ArgumentException()); var walletController = new WalletController(Mediator.Object); //Action var result = await walletController.Withdraw(withdrawWallet); //Assert Assert.IsType <BadRequestObjectResult>(result); }
public async Task Withdraw_Wallet_Fund_Should_Return_Bad_Request_Response_When_Amount_Is_More_Than_Balance() { //Arrange Wallet wallet = new Wallet { AccountNumber = "0123456789", Balance = 100 }; var withdrawWallet = new WithdrawFundRequestModel { Amount = 200, AccountNumber = wallet.AccountNumber }; Mediator.Setup(x => x.Send(It.IsAny <WithdrawFundRequestModel>(), new CancellationToken())). Throws(new ArgumentException()); var walletController = new WalletController(Mediator.Object); //Action var result = await walletController.Withdraw(withdrawWallet); //Assert Assert.IsType <BadRequestObjectResult>(result); }