public async Task empty_snapshot_is_not_persisted() { var nullSnapshot = new SnapshotInfo("empty", 0, null, 0); await _snapshots.Add("empty", nullSnapshot); var tape = new Recorder(); await Store.ReadForwardAsync("empty", 0, tape); Assert.True(tape.IsEmpty); }
public async Task Save <T>( T aggregate, string operationId, Action <IHeadersAccessor> headers, CancellationToken cancellationToken ) where T : IAggregate { var persister = (IEventSourcedAggregate)aggregate; var changeSet = persister.GetChangeSet(); if (changeSet.IsEmpty && !PersistEmptyChangeset) { return; } var stream = GetStream(aggregate); if (!stream.IsWritable) { throw new AggregateReadOnlyException(); } headers?.Invoke(changeSet); await stream.AppendAsync(changeSet, operationId, cancellationToken).ConfigureAwait(false); persister.ChangesPersisted(changeSet); //we need to await, it's responsibility of the snapshot provider to clone & store state (sync or async) await _snapshots.Add(aggregate.Id, persister.GetSnapshot(), cancellationToken).ConfigureAwait(false); }
public static Task Add( this ISnapshotStore snapshots, string aggregateId, SnapshotInfo snapshot ) { return(snapshots.Add(aggregateId, snapshot, CancellationToken.None)); }