Exemplo n.º 1
0
        private void Apply(WithdrewMoney e)
        {
            var walletId = new WalletId(e.EntityId);
            var wallet   = _wallets.Single(w => w.WalletId == walletId);

            wallet.Apply(e);
        }
Exemplo n.º 2
0
        internal void Apply(WithdrewMoney e)
        {
            var amount = new Money(e.Amount);

            Balance = Balance.Subtract(amount);
            Console.WriteLine($"Wallet {Id} balance is now {Balance}");
        }
Exemplo n.º 3
0
        public void Setup()
        {
            var fixture = new Fixture();

            _withdrewMoney = fixture.Build <WithdrewMoney>()
                             .Create();

            _wallet = fixture.Build <Wallet>()
                      .Create();

            _user = fixture.Build <User>()
                    .Create();

            _target = new WithdrewMoneyEventHandler(_walletRepositoryMock.Object, _accountHistoryRepositoryMock.Object, _userRepositoryMock.Object);
        }
Exemplo n.º 4
0
        public void Withdraw(Money amount, Currency currency = null)
        {
            if (amount.Value < 0)
            {
                throw new InvalidOperationException("Cannot withdraw an amount less than or equal to zero.");
            }

            decimal preCalculatedBalance = Balance.Value - amount.Value;

            preCalculatedBalance.Must(x => x >= 0, ex: new InsufficientFundsException(ExceptionMessage.InsufficientFundsExceptionMessage));

            Balance = Balance.Subtract(amount);

            var withdrawMoney = new WithdrewMoney
            {
                EntityId = Id,
                Amount   = amount.Value,
                UserId   = UserId,
                Currency = currency
            };

            AddDomainEvent(withdrawMoney);
        }