public void CheckingAccounts_Service_Deposit_Should_Be_OK() { //Arrange var returns = true; AccountTransactionModel model = new AccountTransactionModel() { AccountOriginId = 1, Value = 50 }; _mockRepositoryAccount.Setup(r => r.GetById(model.AccountOriginId)) .Returns(_checkingAccount); _mockRepositoryAccount.Setup(r => r.Update(_checkingAccount)) .Returns(returns); _mockRepositoryTransaction.Setup(r => r.Add(_checkingAccount.Transactions.First())) .Returns(_checkingAccount.Transactions.First()); //Action var idInsert = _service.Deposit(model); //Verify idInsert.Should().Be(returns); _mockRepositoryAccount.Verify(r => r.GetById(model.AccountOriginId)); _mockRepositoryAccount.Verify(r => r.Update(_checkingAccount)); _mockRepositoryTransaction.Verify(r => r.Add(_checkingAccount.Transactions.First())); }
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())); }
public void CheckingAccounts_Service_Deposit_InvalidValue_Should_ThroException() { //Arrange AccountTransactionModel model = new AccountTransactionModel() { AccountOriginId = 1, Value = -50 }; _mockRepositoryAccount.Setup(r => r.GetById(_checkingAccount.Id)) .Returns(_checkingAccount); //Action Action action = () => _service.Deposit(model); //Verify action.Should().Throw <InvalidObjectException>(); _mockRepositoryAccount.Verify(r => r.GetById(_checkingAccount.Id)); }
public void CheckingAccounts_Service_Transfer_NullAccount_Should_ThrowException() { //Arrange AccountTransactionModel model = new AccountTransactionModel() { AccountOriginId = 1234, AccountDestinationId = 2222, Value = 50 }; CheckingAccount accountDestination = new CheckingAccount() { Id = 2, IsActive = true }; accountDestination.Transactions.Add(new Transaction { Type = TransactionType.CREDIT, Value = 50 }); //Action Action action = () => _service.Deposit(model); //Verify action.Should().Throw <NotFoundException>(); }
public void CheckingAccounts_Service_Transfer_InvalidValue_Should_ThrowException() { //Arrange 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 }); //Action Action action = () => _service.Transfer(model); //Verify action.Should().Throw <InvalidObjectException>(); }
public IHttpActionResult Deposit(AccountTransactionModel account) { return(HandleCallback(() => _accountsService.Deposit(account))); }
public IHttpActionResult Withdraw(AccountTransactionModel account) { return(HandleCallback(() => _accountsService.Withdraw(account))); }