public void HandleEventInstance(MoneyWithdrawn eventInstance)
 {
     if (null != eventInstance)
     {
         currentBalance -= eventInstance.AmountWithdrawn;
     }
 }
Пример #2
0
        public async Task On(MoneyWithdrawn @event, long sequence)
        {
            var balance = await _repository.GetAsync(@event.Id);

            balance.Balance -= @event.Amount;
            await _repository.UpdateBalance(balance, sequence);

            _logger.LogInformation(
                $"Money withdrawn from bank account {_repository.BankAccount}. New Balance: {balance.Balance}");
        }
Пример #3
0
        public void WithdrawMoney_WithLimitNotExceeded_WithdrawsMoney()
        {
            var bankAccount           = new BankAccountBuilder(DefaultBankAccountId).WithCurrency(Currency.Euro).WithDepositedMoney(50).WithDepositedMoney(50).Build();
            var bankAccountRepository = ConfigureBankAccountRepositoryForAccount(bankAccount);
            var systemUnderTest       = new WithdrawMoneyHandler(bankAccountRepository);
            var command = new WithdrawMoney(DefaultBankAccountId, Transaction.Of(Guid.Parse("996228f4-70cb-4e44-9716-8a2a3b27d18c")), new Money(100, Currency.Euro), TimeStamp.Of(3));

            systemUnderTest.Handle(command, CancellationToken.None).GetAwaiter().GetResult();

            var moneyDeposited = new MoneyWithdrawn(DefaultBankAccountId.Value, command.Transaction.Value, command.Amount.Amount, command.TimeStamp.Value);

            bankAccountRepository.Received().SaveAsync(Arg.Is <BankAccount>(it => it.IsCorrectBankAccount(DefaultBankAccountId, 4, moneyDeposited)));
        }
Пример #4
0
        public void Withdraw(decimal amount)
        {
            if (amount > balance)
            {
                throw new InsufficientFundsException();
            }

            var @event = new MoneyWithdrawn(
                accountId: Id,
                amount: amount);

            Apply(@event);
            AddDomainEvent(@event);
        }
 public ClassificationResponse.ClassificationResults ClassifyEventInstance(MoneyWithdrawn eventInstance)
 {
     if (null != eventInstance)
     {
         currentBalance -= eventInstance.AmountWithdrawn;
     }
     if (currentBalance >= threshold)
     {
         // Balance is above threshold
         return(ClassificationResponse.ClassificationResults.Exclude);
     }
     else
     {
         return(ClassificationResponse.ClassificationResults.Include);
     }
 }
Пример #6
0
        public void Handle(MoneyWithdrawn e)
        {
            if (e.Transaction == Guid.Empty)
            {
                return;
            }

            var status = new UpdateTransfer(e.Transaction, "Debit Succeeded");

            _commander.Send(status);

            var transfer = (Transfer)_repository.Get <TransferAggregate>(e.Transaction).State;

            var deposit = new DepositMoney(transfer.ToAccount, e.Amount, e.Transaction);

            _commander.Send(deposit);
        }
Пример #7
0
        private void Handle(MoneyWithdrawn evt)
        {
            var ci = indexer.Get <ClientInformation>(evt.ClientID);

            ci.Balance     -= evt.Quantity;
            ci.LastMovement = evt.TimeStamp;

            indexer.Index(ci);

            var ad = indexer.Get <AmountDepositedInTheBank>(evt.TransactionId.ToString());

            if (ad == null)
            {
                indexer.Index(new AmountDepositedInTheBank {
                    Quantity = evt.Quantity, TimeStamp = evt.TimeStamp, ID = evt.ClientID, TransactionId = evt.TransactionId
                });
            }
        }
Пример #8
0
        public async Task Handle(WithdrawMoney withdrawMoney, IMessageHandlerContext context)
        {
            try
            {
                log.Info($"WithdrawMoneyHandler, TransactionId = {withdrawMoney.TransactionId}");
                var nHibernateSession = context.SynchronizedStorageSession.Session();
                var bankAccountId     = BankAccountId.FromExisting(withdrawMoney.FromBankAccountId);
                var fromBankAccount   = nHibernateSession.Get <BankAccount>(bankAccountId) ?? BankAccount.NonExisting();
                if (fromBankAccount.DoesNotExist())
                {
                    var fromBankAccountNotFound = new FromBankAccountNotFound(withdrawMoney.TransactionId);
                    await context.Publish(fromBankAccountNotFound);

                    return;
                }
                if (fromBankAccount.CanBeWithdrawed(withdrawMoney.Amount))
                {
                    fromBankAccount.Withdraw(withdrawMoney.Amount);
                    fromBankAccount.ChangeUpdatedAt();
                    nHibernateSession.Save(fromBankAccount);
                    var moneyWithdrawn = new MoneyWithdrawn
                                         (
                        withdrawMoney.TransactionId,
                        withdrawMoney.FromBankAccountId,
                        withdrawMoney.Amount,
                        fromBankAccount.Balance.Amount
                                         );
                    await context.Publish(moneyWithdrawn);

                    return;
                }
                var withdrawRejected = new WithdrawRejected
                                       (
                    withdrawMoney.TransactionId
                                       );
                await context.Publish(withdrawRejected);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message + " ** " + ex.StackTrace);
            }
        }
Пример #9
0
 private void Apply(MoneyWithdrawn obj)
 {
     Balance -= obj.Quantity;
 }
Пример #10
0
 public void Handle(MoneyWithdrawn c)
 {
     _store.DecreaseAccountBalance(c.AggregateIdentifier, c.Amount);
 }
Пример #11
0
 private void When(MoneyWithdrawn e)
 {
     Balance -= e.Amount;
 }
Пример #12
0
 void IApply <MoneyWithdrawn> .Apply(MoneyWithdrawn @event)
 {
     balance -= @event.Amount;
 }
Пример #13
0
 private void When(MoneyWithdrawn @event)
 {
     balance -= @event.Amount;
 }
Пример #14
0
 /// <summary>
 /// Apply money withdrawn state changes.
 /// </summary>
 /// <param name="e">The money withdrawn event.</param>
 protected void Apply(MoneyWithdrawn e)
 {
     Balance = e.Balance;
 }
Пример #15
0
 public void Handle(MoneyWithdrawn e)
 {
 }