Inheritance: PPPDDDChap23.EventSourcing.Application.Infrastructure.EventSourcedAggregate
コード例 #1
0
        public void Save(PayAsYouGoAccount payAsYouGoAccount)
        {
            var streamName = StreamNameFor(payAsYouGoAccount.Id);

            var expectedVersion = GetExpectedVersion(payAsYouGoAccount.InitialVersion);
            _eventStore.AppendEventsToStream(streamName, payAsYouGoAccount.Changes, expectedVersion);                      
        }
コード例 #2
0
        public PayAsYouGoAccount FindBy(Guid id)
        {
            var streamName = StreamNameFor(id);
            
            var fromEventNumber = 0;
            var toEventNumber = int.MaxValue ;

            var snapshot = _eventStore.GetLatestSnapshot<PayAsYouGoAccountSnapshot>(streamName);
            if (snapshot != null)
            {
                fromEventNumber = snapshot.Version + 1; // load only events after snapshot
            }
            
            var stream = _eventStore.GetStream(streamName, fromEventNumber, toEventNumber);

            PayAsYouGoAccount payAsYouGoAccount = null;
            if (snapshot != null)
            {
                payAsYouGoAccount = new PayAsYouGoAccount(snapshot);
            }
            else
            {
                payAsYouGoAccount = new PayAsYouGoAccount();
            }


            foreach(var @event in stream)
            {
                payAsYouGoAccount.Apply(@event);
            }

            return payAsYouGoAccount;            
        }
コード例 #3
0
ファイル: CreateAccount.cs プロジェクト: elbandit/PPPDDD
        public void Execute(Guid id)
        {
            var payAsYouGoAccount = new PayAsYouGoAccount(id, new Money(10m));

            _payAsYouGoAccountRepository.Add(payAsYouGoAccount);

            _unitOfWork.SaveChanges();            
        }
コード例 #4
0
        [ClassInitialize] // runs first
        public static void When_applying_a_top_up_that_does_not_qualify_for_inclusive_minutes(TestContext ctx)
        {
            _account = new PayAsYouGoAccount(Guid.NewGuid(), new Money(0));
            // remove the AccountCreated event that is not relevant to this test
            _account.Changes.Clear();

            _account.AddInclusiveMinutesOffer(_free90MinsWith10DollarTopUp);
            _account.TopUp(_fiveDollars, new SystemClock()); // $5 top up does not meet $10 threshold for free minutes
        }
コード例 #5
0
ファイル: ImportTestData.cs プロジェクト: elbandit/PPPDDD
        private void Create5EmptyAccounts()
        {
            var account1Id = Guid.NewGuid();
            account1 = new PayAsYouGoAccount(account1Id, new Money(0));

            var account2Id = Guid.NewGuid();
            account2 = new PayAsYouGoAccount(account2Id, new Money(0));

            var account3Id = Guid.NewGuid();
            account3 = new PayAsYouGoAccount(account3Id, new Money(0));

            var account4Id = Guid.NewGuid();
            account4 = new PayAsYouGoAccount(account4Id, new Money(0));

            var account5Id = Guid.NewGuid();
            account5 = new PayAsYouGoAccount(account5Id, new Money(0));
        }
コード例 #6
0
        public PayAsYouGoAccount FindBy(Guid id)
        {
            var streamName = string.Format("{0}-{1}", typeof(PayAsYouGoAccount).Name, id.ToString());

            // Check for snapshots

            var fromEventNumber = 0;
            var toEventNumber = int.MaxValue ;

            // pull back all events from snapshot
            var stream = _eventStore.GetStream(streamName, fromEventNumber, toEventNumber);

            var payAsYouGoAccount = new PayAsYouGoAccount();

            foreach(var @event in stream)
            {
                payAsYouGoAccount.Apply(@event);
            }

            return payAsYouGoAccount;            
        }
コード例 #7
0
        public void SaveSnapshot(PayAsYouGoAccountSnapshot snapshot, PayAsYouGoAccount payAsYouGoAccount)
        {
            var streamName = StreamNameFor(payAsYouGoAccount.Id);

            _eventStore.AddSnapshot<PayAsYouGoAccountSnapshot>(streamName, snapshot);
        }
コード例 #8
0
        public void Add(PayAsYouGoAccount payAsYouGoAccount)
        {
            var streamName = StreamNameFor(payAsYouGoAccount.Id);

            _eventStore.CreateNewStream(streamName, payAsYouGoAccount.Changes);
        }
コード例 #9
0
        public void Save(PayAsYouGoAccount payAsYouGoAccount)
        {
            var streamName = string.Format("{0}-{1}", typeof(PayAsYouGoAccount).Name, payAsYouGoAccount.Id.ToString());

            _eventStore.AppendEventsToStream(streamName, payAsYouGoAccount.Changes);                      
        }
コード例 #10
0
        public void Add(PayAsYouGoAccount payAsYouGoAccount)
        {
            var streamName = string.Format("{0}-{1}", typeof(PayAsYouGoAccount).Name, payAsYouGoAccount.Id.ToString());

            _eventStore.CreateNewStream(streamName, payAsYouGoAccount.Changes);
        }