Ejemplo n.º 1
0
        public async Task Deposit_Deposit10_ReturnsOkAndPostDepositBalance()
        {
            //// Arrange

            decimal postDepositBalance = 15;
            Balance expectedBalance    = new Balance()
            {
                Amount = postDepositBalance
            };
            BalanceResponse expectedBalanceResponse = new BalanceResponse()
            {
                Amount = postDepositBalance
            };

            decimal        depositAmount  = 10;
            DepositRequest depositRequest = new DepositRequest {
                Amount = depositAmount
            };

            // Setup Mocks

            Mock <IWalletService> walletServiceMock = new Mock <IWalletService>();

            Deposit deposit = new Deposit {
                Amount = depositAmount
            };

            walletServiceMock
            .Setup(walletService => walletService.DepositFundsAsync(deposit))
            .Returns(Task.FromResult(expectedBalance));

            IWalletService walletService = walletServiceMock.Object;

            ILogger <WalletController> logger = Mock.Of <ILogger <WalletController> >();

            IMapper mapper = Mock.Of <IMapper>(mapper => mapper.Map <Deposit>(depositRequest) == deposit &&
                                               mapper.Map <BalanceResponse>(expectedBalance) == expectedBalanceResponse);

            // Initialize SUT

            WalletController walletController = new WalletController(logger, mapper, walletService);

            //// Act

            ActionResult <BalanceResponse> actionResult = await walletController.Deposit(depositRequest);

            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.DepositFundsAsync(deposit), Times.Once);
            walletServiceMock.VerifyNoOtherCalls();
        }