コード例 #1
0
        public async Task <Transaction> Handle(WithdrawCommand command)
        {
            Account account = await accountReadOnlyRepository.GetAccount(command.AccountId);

            if (account == null)
            {
                throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed.");
            }

            Transaction transaction = Debit.Create(command.CustomerId, Amount.Create(command.Amount));

            account.Withdraw(transaction);

            var domainEvents = account.GetEvents();
            await bus.Publish(domainEvents, command.Header);

            bool received = false;

            for (int i = 0; i < 5; i++)
            {
                received = await accountReadOnlyRepository.CheckTransactionReceived(account.Id, transaction.Id);

                if (received)
                {
                    break;
                }
            }

            //if (!received)
            //{
            //}

            return(transaction);
        }
コード例 #2
0
        public void Withdraw_100()
        {
            //
            // Arrange
            Account account = Account.Create(
                Guid.NewGuid(),
                Amount.Create(1000.0));

            Customer customer = Customer.Create(
                PIN.Create("08724050601"),
                Name.Create("Ivan Paulovich"));

            customer.Register(account);

            Account sut = customer.GetAccounts().First();

            Transaction transaction = Debit.Create(
                customer.Id, Amount.Create(100.0));

            //
            // Act
            sut.Withdraw(transaction);

            //
            // Assert
            var domainEvents = sut.GetEvents();
            var deposited    = domainEvents.Where(e => e is WithdrewDomainEvent).First() as WithdrewDomainEvent;

            Assert.Equal(deposited.Amount.Value, 100.0);
            Assert.Equal(sut.GetCurrentBalance().Value, 900);
        }
コード例 #3
0
        public void Close_Account()
        {
            //
            // Arrange
            Account account = Account.Create(
                Guid.NewGuid(),
                Amount.Create(1000.0));

            Customer customer = Customer.Create(
                PIN.Create("08724050601"),
                Name.Create("Ivan Paulovich"));

            customer.Register(account);

            Account     sut         = customer.GetAccounts().First();
            Transaction transaction = Debit.Create(
                customer.Id, Amount.Create(1000.0));

            sut.Withdraw(transaction);

            //
            // Act
            sut.Close();

            //
            // Assert
            var domainEvents = sut.GetEvents();
            var closed       = domainEvents.Where(e => e is ClosedDomainEvent).Count();

            Assert.NotEqual(closed, 0);
        }
コード例 #4
0
        public void Withdraw_100()
        {
            //
            // Arrange
            Customer customer = Customer.Create(
                PIN.Create("08724050601"),
                Name.Create("Ivan Paulovich"));

            Account account = Account.Create(
                customer,
                Amount.Create(1000.0));

            customer.Register(account);

            Account sut = customer.GetAccounts().First();

            Transaction transaction = Debit.Create(
                customer.Id, Amount.Create(100.0));

            //
            // Act
            sut.Withdraw(transaction);

            //
            // Assert
            var transactions = sut.GetTransactions();
            var deposited    = transactions.Where(e => e.Id == transaction.Id).First();

            Assert.Equal(deposited.GetAmount().Value, 100.0);
            Assert.Equal(sut.GetCurrentBalance().Value, 900);
        }
コード例 #5
0
ファイル: AccountTests.cs プロジェクト: CiBuildOrg/acerola
        public void Account_With_200_Balance_Should_Not_Allow_50000_Withdraw()
        {
            //
            // Arrange
            Account sut    = Substitute.For <Account>();
            Credit  credit = Credit.Create(Amount.Create(200));

            sut.Deposit(credit);

            Debit debit = Debit.Create(Amount.Create(5000.0));

            //
            // Act and Assert
            Assert.Throws <InsuficientFundsException>(
                () => sut.Withdraw(debit));
        }
コード例 #6
0
        public async Task <Debit> Handle(WithdrawMessage command)
        {
            Account account = await accountReadOnlyRepository.Get(command.AccountId);

            if (account == null)
            {
                throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed.");
            }

            Debit debit = Debit.Create(Amount.Create(command.Amount));

            account.Withdraw(debit);

            await accountWriteOnlyRepository.Update(account);

            return(debit);
        }
コード例 #7
0
        public async Task <Transaction> Handle(WithdrawCommand command)
        {
            Account account = await accountReadOnlyRepository.GetAccount(command.AccountId);

            if (account == null)
            {
                throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed.");
            }

            Transaction transaction = Debit.Create(command.CustomerId, Amount.Create(command.Amount));

            account.Withdraw(transaction);

            var domainEvents = account.GetEvents();
            await bus.Publish(domainEvents, command.Header);

            return(transaction);
        }
コード例 #8
0
ファイル: AccountTests.cs プロジェクト: CiBuildOrg/acerola
        public void New_Account_With_1000_Balance_Should_Have_900_After_Withdraw()
        {
            //
            // Arrange
            Account sut    = Substitute.For <Account>();
            Credit  credit = Credit.Create(Amount.Create(1000.0));

            sut.Deposit(credit);

            Debit transaction = Debit.Create(Amount.Create(100.0));

            //
            // Act
            sut.Withdraw(transaction);

            //
            // Assert
            Assert.Equal(900, sut.CurrentBalance.Value);
        }
コード例 #9
0
        public void Withdraw_More_Than_Current_Balance()
        {
            //
            // Arrange
            Account account = Account.Create(
                Guid.NewGuid(),
                Amount.Create(1000.0));

            Customer customer = Customer.Create(
                PIN.Create("08724050601"),
                Name.Create("Ivan Paulovich"));

            customer.Register(account);

            Account sut = customer.GetAccounts().First();

            Transaction transaction = Debit.Create(
                customer.Id, Amount.Create(5000.0));

            //
            // Act and Assert
            Assert.Throws <InsuficientFundsException>(
                () => sut.Withdraw(transaction));
        }