Beispiel #1
0
        public void Initialize_Version()
        {
            var @event      = new DepositedMoney(new Money(123m));
            var storedEvent = new StoredEvent(Guid.NewGuid().ToString(), @event, 1);

            Assert.AreEqual(1, storedEvent.Version);
        }
Beispiel #2
0
        internal void Apply(DepositedMoney e)
        {
            var amount = new Money(e.Amount);

            Balance = Balance.Add(amount);
            Console.WriteLine($"Wallet {Id} balance is now {Balance}");
        }
Beispiel #3
0
        public void Initialize_DomainEvent()
        {
            var @event      = new DepositedMoney(new Money(123m));
            var storedEvent = new StoredEvent(Guid.NewGuid().ToString(), @event, 1);

            Assert.AreEqual(@event, storedEvent.Event);
        }
Beispiel #4
0
        private void Apply(DepositedMoney e)
        {
            var walletId = new WalletId(e.EntityId);
            var wallet   = _wallets.Single(w => w.WalletId == walletId);

            wallet.Apply(e);
        }
Beispiel #5
0
        public void Initialize_EventStreamId()
        {
            var @event      = new DepositedMoney(new Money(123m));
            var guid        = Guid.NewGuid();
            var storedEvent = new StoredEvent(guid.ToString(), @event, 1);

            Assert.AreEqual(guid.ToString(), storedEvent.EventStreamId);
        }
Beispiel #6
0
        private DateTimeOffset[] GetOccurredOns()
        {
            var accountCreatedWithBalance      = new AccountCreatedWithBalance(Balance.Create(123m));
            var accountCreatedWithEmptyBalance = new AccountCreatedWithEmptyBalance();
            var depositedMoney = new DepositedMoney(new Money(123m));
            var withdrawnMoney = new WithdrawnMoney(new Money(123m));

            return(new[] { accountCreatedWithBalance.OccurredOn, accountCreatedWithEmptyBalance.OccurredOn, depositedMoney.OccurredOn, withdrawnMoney.OccurredOn });
        }
        public void Initialize_Amount()
        {
            var money          = new Money(123);
            var depositedMoney = new DepositedMoney(money);

            var actual = depositedMoney.Amount;

            Assert.AreEqual(money, actual);
        }
Beispiel #8
0
        public void Setup()
        {
            var fixture = new Fixture();

            _depositedMoney = fixture.Build <DepositedMoney>()
                              .Create();

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

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

            _target = new DepositedMoneyEventHandler(_walletRepositoryMock.Object, _accountHistoryRepositoryMock.Object, _userRepositoryMock.Object);
        }
Beispiel #9
0
        public virtual void Deposit(Money amount, Currency currency = null)
        {
            if (amount.Value <= 0)
            {
                throw new InvalidOperationException("Cannot deposit an amount less than or equal to zero.");
            }

            Balance = Balance.Add(amount);

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

            AddDomainEvent(depositMoney);
        }
Beispiel #10
0
 private void When(DepositedMoney moneyAdded)
 {
     // Todo : Add balance check here !
     this.balance = this.balance.Add(moneyAdded.Amount);
 }
Beispiel #11
0
 private void When(DepositedMoney depositedMoney)
 {
     Balance = Balance.Deposit(depositedMoney.Amount);
 }