public async Task read_snapshot_when_loading_aggregate() { var now = DateTime.UtcNow; var esStore = new EsEventStore(GetEventStoreClient(), "snapshot_test"); var esAggregateStore = new EsAggregateStore(esStore, 5); var aggregate = new Day(); var slots = new List <ScheduledSlot> { new ScheduledSlot(TimeSpan.FromMinutes(10), now), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(10)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(20)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(30)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(40)) }; aggregate.Schedule(new DoctorId(Guid.NewGuid()), DateTime.UtcNow, slots, Guid.NewGuid); await esAggregateStore.Save(aggregate, new CommandMetadata(new CorrelationId(Guid.NewGuid()), new CausationId(Guid.NewGuid()))); await esStore.TruncateStream(StreamName.For <Day>(aggregate.Id), Convert.ToUInt64(aggregate.GetChanges().Count())); var reloadedAggregate = await esAggregateStore.Load <Day>(aggregate.Id); Assert.Equal(5, reloadedAggregate.Version); }
public async Task write_snapshot_if_threshold_reached() { var now = DateTime.UtcNow; var esStore = new EsEventStore(GetEventStoreClient(), "snapshot_test"); var esAggregateStore = new EsAggregateStore(esStore, 5); var aggregate = new Day(); var slots = new List <ScheduledSlot> { new ScheduledSlot(TimeSpan.FromMinutes(10), now), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(10)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(20)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(30)), new ScheduledSlot(TimeSpan.FromMinutes(10), now.AddMinutes(40)) }; aggregate.Schedule(new DoctorId(Guid.NewGuid()), DateTime.UtcNow, slots, Guid.NewGuid); await esAggregateStore.Save(aggregate, new CommandMetadata(new CorrelationId(Guid.NewGuid()), new CausationId(Guid.NewGuid()))); var snapshotEnvelope = await esStore.LoadSnapshot(StreamName.For <Day>(aggregate.Id)); var snapshot = snapshotEnvelope?.Snapshot as DaySnapshot; Assert.NotNull(snapshot); }