public async Task NewAccount_Should_Allows_Closing2() { var getAccountPresenter = new GetAccountDetailsPresenter(); var closeAccountPresenter = new CloseAccountPresenter(); var withdrawPresenter = new WithdrawPresenter(); var getAccountUseCase = new GetAccountDetailsUseCase( getAccountPresenter, this._fixture.AccountRepository); var withdrawUseCase = new WithdrawUseCase(this._fixture.AccountService, withdrawPresenter, this._fixture.AccountRepository, this._fixture.UnitOfWork); var sut = new CloseAccountUseCase( closeAccountPresenter, this._fixture.AccountRepository); await getAccountUseCase.Execute(new GetAccountDetailsInput(this._fixture.Context.DefaultAccountId)); var getAccountDetailtOutput = getAccountPresenter.GetAccountDetails.First(); await withdrawUseCase.Execute(new WithdrawInput(this._fixture.Context.DefaultAccountId, new PositiveMoney(getAccountDetailtOutput.CurrentBalance.ToDecimal()))); var input = new CloseAccountInput(this._fixture.Context.DefaultAccountId); await sut.Execute(input); Assert.Equal(input.AccountId, closeAccountPresenter.ClosedAccounts.First().AccountId); }
public async Task Withdraw_ValidValues_ShouldCompleteTask() { //ARRANGE var account = BuildAccount(10); var amount = new Amount(10); _accountReadOnlyRepository.Setup(m => m.Get(account.Id)).Returns(Task.FromResult(account)); _accountWriteOnlyRepository.Setup(m => m.Update(account, It.IsAny <Debit>())).Returns(Task.CompletedTask); //ACT WithdrawOutput outPut = await withdrawUseCase.Execute(account.Id, amount); //ASSERT _accountReadOnlyRepository.Verify(v => v.Get(account.Id), Times.Once()); _accountWriteOnlyRepository.Verify(v => v.Update(account, It.IsAny <Debit>()), Times.Once()); Assert.Equal(0, outPut.UpdatedBalance); Assert.NotNull(outPut.Transaction); }
public async Task Withdraw_Valid_Amount( decimal amount, decimal expectedBalance) { var presenter = new WithdrawPresenter(); var sut = new WithdrawUseCase(this._fixture.AccountService, presenter, this._fixture.AccountRepository, this._fixture.UnitOfWork); await sut.Execute(new WithdrawInput(this._fixture.Context.DefaultAccountId, new PositiveMoney(amount))); var actual = presenter.Withdrawals.Last(); Assert.Equal(expectedBalance, actual.UpdatedBalance.ToDecimal()); }
public async void Withdraw_Valid_Amount(string accountId, decimal amount) { var mockAccountReadOnlyRepository = new Mock <IAccountReadOnlyRepository>(); var mockAccountWriteOnlyRepository = new Mock <IAccountWriteOnlyRepository>(); TransactionCollection transactions = new TransactionCollection(); transactions.Add(new Credit(Guid.Empty, 4000)); Account account = Account.LoadFromDetails(Guid.Parse(accountId), Guid.Empty, transactions); mockAccountReadOnlyRepository.SetupSequence(e => e.Get(It.IsAny <Guid>())) .ReturnsAsync(account); WithdrawUseCase sut = new WithdrawUseCase( mockAccountReadOnlyRepository.Object, mockAccountWriteOnlyRepository.Object ); WithdrawOutput output = await sut.Execute( Guid.Parse(accountId), amount); Assert.Equal(3900, output.UpdatedBalance); }