Exemple #1
0
        public async Task Store(int entityVersion, Guid entityId, object memento, string tenantId = EventStore.DefaultTenant)
        {
            var snapshot = new Snapshot(entityVersion, entityId, tenantId, Utils.PackSnapshot(memento), DateTimeOffset.Now);

            EventStore.Logger.Debug("Storing snapshot {@snapshot}", snapshot);
            await _store.Store(snapshot).ConfigureFalse();

            EventStore.Logger.Debug("Snapshot for {@entity} stored successfully", new{ entityId, tenantId, entityVersion });
        }
Exemple #2
0
        public async Task append_then_get_events_with_snapshot()
        {
            var commit1  = Setup.UnversionedCommit();
            var commit2  = Setup.UnversionedCommit(guid: commit1.EntityId);
            var commit3  = Setup.UnversionedCommit(guid: commit1.EntityId);
            var snapshot = Setup.Snapshot(2, commit1.EntityId);

            await _store.Append(commit1);

            await _store.Append(commit2);

            await _store.Store(snapshot);

            await _store.Append(commit3);

            var data = await _store.GetData(Config(c => c.OfEntity(commit1.EntityId).IncludeSnapshots(true)), _cancellationToken);

            var commits = data.Value.Commits.ToArray();

            data.Value.LatestSnapshot.HasValue.Should().BeTrue();
            data.Value.LatestSnapshot.Value.Should().BeEquivalentTo(snapshot, i => i.Excluding(d => d.SnapshotDate));
            commits.Length.Should().Be(1);
            commits[0].Version.Should().Be(3);
        }