Beispiel #1
0
        public void Test_EventReplaying_evaluating_CurrentAccountBalance_using_a_stream_containing_both_past_and_future_events()
        {
            var currentAccountId = Guid.NewGuid();
            var accountOpening   = new AccountOpenedEvent
            {
                CurrentAccountId = currentAccountId,
                Balance          = 200
            };

            EventStore.Save(accountOpening);

            var withdrawal1 = new WithdrawalEvent()
            {
                CurrentAccountId = currentAccountId,
                Amount           = 100
            };

            withdrawal1.SetTimeStamp(DateTime.Now.AddMonths(1));
            EventStore.Save(withdrawal1);

            var withdrawal2 = new WithdrawalEvent()
            {
                CurrentAccountId = currentAccountId,
                Amount           = 100
            };

            withdrawal2.SetTimeStamp(DateTime.Now.AddMonths(3));
            EventStore.Save(withdrawal2);

            WaitForIndexing(documentStore);
            var sut            = new Repository(EventStore);
            var currentAccount = sut.GetById <CurrentAccount>(currentAccountId, DateTime.Now.AddMonths(2));

            Assert.Equal(100, currentAccount.Balance);
        }
        public void Test_EventReplaying_evaluating_CurrentAccountBalance_using_a_stream_containing_past_events_only_and_a_different_timeline()
        {
            var currentAccountId = Guid.NewGuid();
            var accountOpening   = new AccountOpenedEvent
            {
                CurrentAccountId = currentAccountId,
                Balance          = 200
            };

            EventStore.Save(accountOpening);

            var withdrawal1 = new WithdrawalEvent()
            {
                CurrentAccountId = currentAccountId,
                Amount           = 100
            };

            withdrawal1.SetTimeStamp(DateTime.Now.AddMonths(1));
            EventStore.Save(withdrawal1);

            var withdrawal2 = new WithdrawalEvent()
            {
                CurrentAccountId = currentAccountId,
                Amount           = 100,
                TimelineId       = Guid.NewGuid()
            };

            withdrawal2.SetTimeStamp(DateTime.Now.AddMonths(3));
            EventStore.Save(withdrawal2);

            var sut            = new Repository(EventStore);
            var currentAccount = sut.GetById <SelfRetrievingCurrentAccount>(currentAccountId, DateTime.Now.AddMonths(3));

            Assert.AreEqual(100, currentAccount.Balance);
        }
        public void Test_EventCount_at_a_specific_date()
        {
            var currentAccountId = Guid.NewGuid();
            var accountOpening   = new AccountOpenedEvent
            {
                CurrentAccountId = currentAccountId,
                Balance          = 200
            };

            EventStore.Save(accountOpening);

            var withdrawal1 = new WithdrawalEvent()
            {
                CurrentAccountId = currentAccountId,
                Amount           = 100
            };

            withdrawal1.SetTimeStamp(DateTime.Now.AddMonths(1));
            EventStore.Save(withdrawal1);

            var sut            = new Repository(EventStore);
            var currentAccount = sut.GetById <CurrentAccount>(currentAccountId, DateTime.Now.AddMonths(2));

            Assert.AreEqual(2, ((IAggregate)currentAccount).OccurredEvents.Count);
        }