Ejemplo n.º 1
0
        public async Task RealizarCreditoNaConta_Com_SaldoNegativo_NaoDeve_EfetuarOperacao()
        {
            // Arrange
            var account = new Account()
            {
                CPF     = "00100100199",
                Balance = 1500
            };

            var command = new AccountCredit.Command()
            {
                CPF         = "00100100199",
                Description = "Pix",
                Value       = -50
            };

            _accountRepositoryFake.Setup(x => x.GetByCPF(It.IsAny <string>()))
            .ReturnsAsync(account);

            // Act
            var response = await _handler.Handle(command, It.IsAny <CancellationToken>());

            // Assert
            Assert.IsFalse(response);
        }
Ejemplo n.º 2
0
        public async Task RealizarCreditoNaConta_Deve_ObterSucesso()
        {
            // Arrange
            var expectedValue = 1750;

            var account = new Account()
            {
                CPF     = "00100100199",
                Balance = 1500
            };

            var command = new AccountCredit.Command()
            {
                CPF         = "00100100199",
                Description = "Pix",
                Value       = 250
            };

            _accountRepositoryFake.Setup(x => x.GetByCPF(It.IsAny <string>()))
            .ReturnsAsync(account);
            _accountTransactionRepositoryFake.Setup(x => x.Add(It.IsAny <AccountTransaction>()))
            .ReturnsAsync(Guid.NewGuid());
            _accountRepositoryFake.Setup(x => x.Update(It.IsAny <Account>()));

            // Act
            var response = await _handler.Handle(command, It.IsAny <CancellationToken>());

            // Assert
            Assert.IsTrue(response);
            Assert.AreEqual(expectedValue, account.Balance);
        }
        public async Task <IActionResult> CreditAsync([FromBody] AccountCredit.Command accountCreditCommand)
        {
            var response = await _mediator.Send(accountCreditCommand);

            return(Ok(response));
        }