public async Task Deposit_ValidAccount_ShouldCompleteTask()
        {
            //ARRANGE
            var customerId = Guid.NewGuid();
            var account    = new Account(customerId);
            var amount     = new Amount(10);

            _accountReadOnlyRepository.Setup(m => m.Get(account.Id)).Returns(Task.FromResult(account));
            _accountWriteOnlyRepository.Setup(m => m.Update(account, It.IsAny <Credit>())).Returns(Task.CompletedTask);

            //ACT
            DepositOutput outPut = await depositUseCase.Execute(account.Id, amount);

            //ASSERT
            _accountReadOnlyRepository.Verify(v => v.Get(account.Id), Times.Once());
            _accountWriteOnlyRepository.Verify(v => v.Update(account, It.IsAny <Credit>()), Times.Once());
            Assert.Equal(amount.ToString(), outPut.UpdatedBalance.ToString());
            Assert.NotNull(outPut.Transaction);
        }
        public async Task Deposit_ShouldNot_ChangesBalance_WhenNegative(decimal amount)
        {
            var presenter = new DepositPresenter();
            var sut       = new DepositUseCase(this._fixture.AccountService,
                                               presenter, this._fixture.AccountRepository, this._fixture.UnitOfWork);

            await Assert.ThrowsAsync <MoneyShouldBePositiveException>(() =>
                                                                      sut.Execute(
                                                                          new DepositInput(this._fixture.Context.DefaultAccountId,
                                                                                           new PositiveMoney(amount))));
        }
        public async Task Deposit_ChangesBalance(decimal amount)
        {
            var presenter = new DepositPresenter();
            var sut       = new DepositUseCase(this._fixture.AccountService,
                                               presenter, this._fixture.AccountRepository, this._fixture.UnitOfWork);

            await sut.Execute(
                new DepositInput(this._fixture.Context.DefaultAccountId,
                                 new PositiveMoney(amount)));

            var output = presenter.Deposits.Last();

            Assert.Equal(amount, output.Transaction.Amount.ToMoney().ToDecimal());
        }
        public async void Deposit_Valid_Amount(string accountId, double amount)
        {
            var account  = new Account(Guid.NewGuid());
            var customer = new Customer("08724050601", "Jorge Perales Diaz");

            accountReadOnlyRepository
            .Get(Guid.Parse(accountId))
            .Returns(account);

            var depositUseCase = new DepositUseCase(
                accountReadOnlyRepository,
                accountWriteOnlyRepository
                );

            DepositResult result = await depositUseCase.Execute(
                Guid.Parse(accountId),
                amount);

            Assert.Equal(amount, result.Transaction.Amount);
        }
예제 #5
0
        public async void Deposit_Valid_Amount(string accountId, decimal amount)
        {
            var mockAccountReadOnlyRepository  = new Mock <IAccountReadOnlyRepository>();
            var mockAccountWriteOnlyRepository = new Mock <IAccountWriteOnlyRepository>();

            Account account = new Account(Guid.Parse(accountId));

            mockAccountReadOnlyRepository.SetupSequence(e => e.Get(It.IsAny <Guid>()))
            .ReturnsAsync(account);

            DepositUseCase sut = new DepositUseCase(
                mockAccountReadOnlyRepository.Object,
                mockAccountWriteOnlyRepository.Object
                );

            DepositOutput output = await sut.Execute(
                Guid.Parse(accountId),
                amount);

            Assert.Equal(100, output.UpdatedBalance);
        }