Esempio n. 1
0
        public void CheckingAccounts_Service_Transfer_Should_Be_OK()
        {
            //Arrange
            var returns = true;
            AccountTransactionModel model = new AccountTransactionModel()
            {
                AccountOriginId = 1, AccountDestinationId = 2, Value = 50
            };
            CheckingAccount accountDestination = new CheckingAccount()
            {
                Id = 2, IsActive = true
            };

            accountDestination.Transactions.Add(new Transaction {
                Type = TransactionType.CREDIT, Value = 50
            });

            _mockRepositoryAccount.Setup(r => r.GetById(model.AccountOriginId))
            .Returns(_checkingAccount);

            _mockRepositoryAccount.Setup(r => r.GetById(model.AccountDestinationId))
            .Returns(accountDestination);

            _mockRepositoryAccount.Setup(r => r.Update(_checkingAccount))
            .Returns(returns);

            _mockRepositoryAccount.Setup(r => r.Update(accountDestination))
            .Returns(returns);

            _mockRepositoryTransaction.Setup(r => r.Add(_checkingAccount.Transactions.First()))
            .Returns(_checkingAccount.Transactions.First());

            _mockRepositoryTransaction.Setup(r => r.Add(accountDestination.Transactions.First()))
            .Returns(_checkingAccount.Transactions.First());

            //Action
            var idInsert = _service.Transfer(model);

            //Verify
            idInsert.Should().Be(returns);
            _mockRepositoryAccount.Verify(r => r.GetById(_checkingAccount.Id));
            _mockRepositoryAccount.Verify(r => r.Update(_checkingAccount));
            _mockRepositoryAccount.Verify(r => r.GetById(accountDestination.Id));
            _mockRepositoryAccount.Verify(r => r.Update(accountDestination));
            _mockRepositoryTransaction.Verify(r => r.Add(_checkingAccount.Transactions.First()));
            _mockRepositoryTransaction.Verify(r => r.Add(accountDestination.Transactions.First()));
        }
Esempio n. 2
0
        public IHttpActionResult Transfer(CheckingAccountTransactionCommand cmd)
        {
            var validator = cmd.Validate(TransactionType.TRANSFER);

            if (!validator.IsValid)
            {
                return(HandleValidationFailure(validator.Errors));
            }

            return(HandleCallback(() => _accountsService.Transfer(cmd)));
        }
Esempio n. 3
0
 public IHttpActionResult Transfer(AccountTransactionModel account)
 {
     return(HandleCallback(() => _accountsService.Transfer(account)));
 }