public void Save(PayAsYouGoAccount payAsYouGoAccount) { var streamName = StreamNameFor(payAsYouGoAccount.Id); var expectedVersion = GetExpectedVersion(payAsYouGoAccount.InitialVersion); _eventStore.AppendEventsToStream(streamName, payAsYouGoAccount.Changes, expectedVersion); }
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; }
public void Execute(Guid id) { var payAsYouGoAccount = new PayAsYouGoAccount(id, new Money(10m)); _payAsYouGoAccountRepository.Add(payAsYouGoAccount); _unitOfWork.SaveChanges(); }
[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 }
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)); }
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; }
public void SaveSnapshot(PayAsYouGoAccountSnapshot snapshot, PayAsYouGoAccount payAsYouGoAccount) { var streamName = StreamNameFor(payAsYouGoAccount.Id); _eventStore.AddSnapshot<PayAsYouGoAccountSnapshot>(streamName, snapshot); }
public void Add(PayAsYouGoAccount payAsYouGoAccount) { var streamName = StreamNameFor(payAsYouGoAccount.Id); _eventStore.CreateNewStream(streamName, payAsYouGoAccount.Changes); }
public void Save(PayAsYouGoAccount payAsYouGoAccount) { var streamName = string.Format("{0}-{1}", typeof(PayAsYouGoAccount).Name, payAsYouGoAccount.Id.ToString()); _eventStore.AppendEventsToStream(streamName, payAsYouGoAccount.Changes); }
public void Add(PayAsYouGoAccount payAsYouGoAccount) { var streamName = string.Format("{0}-{1}", typeof(PayAsYouGoAccount).Name, payAsYouGoAccount.Id.ToString()); _eventStore.CreateNewStream(streamName, payAsYouGoAccount.Changes); }