Exemple #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);
        }
Exemple #2
0
 private void onAccountCreated(AccountOpenedEvent accountOpenedEvent)
 {
     Id             = accountOpenedEvent.AccountId;
     _clientId      = accountOpenedEvent.ClientId;
     _accountName   = new AccountName(accountOpenedEvent.AccountName);
     _accountNumber = new AccountNumber(accountOpenedEvent.AccountNumber);
 }
        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);
        }
Exemple #5
0
        private bool Execute(OpenNewAccountCommand command)
        {
            //this spec is part of Akkatecture
            var spec = new AggregateIsNewSpecification();

            if (spec.IsSatisfiedBy(this))
            {
                var aggregateEvent = new AccountOpenedEvent(command.OpeningBalance);
                Emit(aggregateEvent);
            }

            return(true);
        }
Exemple #6
0
            public static CurrentAccount CreateCurrentAccount()
            {
                var a = new CurrentAccount()
                {
                    Id = Guid.NewGuid()
                };
                var e = new AccountOpenedEvent()
                {
                    CurrentAccountId = a.Id,
                    Balance          = 0
                };

                a.RaiseEvent(e);

                return(a);
            }
Exemple #7
0
        public async Task <ActionResult <Account> > CreateAccountAsync([FromBody] AccountInputModel inputModel)
        {
            if (!TryValidateModel(inputModel))
            {
                return(BadRequest());
            }

            var accountDetails = new AccountDetails(AccountId.New.Id, inputModel.Externalid, inputModel.Name,
                                                    inputModel.CountryCode, inputModel.CurrencyCode, inputModel.StartingBalance);
            var @event = new AccountOpenedEvent(accountDetails);

            await _eventStoreConnection.AppendToStreamAsync(@event.Data.AccountId, ExpectedVersion.Any,
                                                            @event.EventData);

            return(new Account(accountDetails));
        }
        public void Test_EventCount()
        {
            var currentAccountId = Guid.NewGuid();
            var accountOpening   = new AccountOpenedEvent
            {
                CurrentAccountId = currentAccountId,
                Balance          = 200
            };

            EventStore.Save(accountOpening);

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

            EventStore.Save(withdrawal1);

            var sut            = new Repository(EventStore);
            var currentAccount = sut.GetById <CurrentAccount>(currentAccountId);

            Assert.AreEqual(2, ((IAggregate)currentAccount).OccurredEvents.Count);
        }
 public void ApplyEvent(AccountOpenedEvent @event)
 {
     this.Id      = @event.CurrentAccountId;
     this.Balance = @event.Balance;
 }
Exemple #10
0
 public void Apply(AccountOpenedEvent aggregateEvent)
 {
     Balance = aggregateEvent.OpeningBalance;
 }
Exemple #11
0
 public void Handle(AccountOpenedEvent domainEvent)
 {
     _table.SetUser(domainEvent.AggregateRootId, domainEvent.Name, domainEvent.Address);
 }
Exemple #12
0
 public void Handle(AccountOpenedEvent @event)
 {
     this.Status = Status.Open;
 }
Exemple #13
0
 public Task Apply(AccountOpenedEvent evt)
 {
     //this.logger.LogError($"加款:{evt.Amount}; 余额:{evt.Balance}");
     return(Task.CompletedTask);
 }
Exemple #14
0
 void OnAccountOpened(AccountOpenedEvent @event)
 {
     name    = @event.Name;
     address = @event.Address;
 }