Beispiel #1
0
        public async Task four_events_without_snapshot()
        {
            var data = new EntityStreamData()
            {
                Commits = SetupCommits(2)
            };

            _storage.GetData(Arg.Any <QueryConfig>(), CancellationToken.None)
            .Returns(new Optional <EntityStreamData>(data));
            var raw = await _sut.GetEvents(Setup.EntityId);

            raw.Value.LatestSnapshot.IsEmpty.Should().BeTrue();
            var evs = raw.Value;

            evs.Count.Should().Be(4);
            evs.Version.Should().Be(2);
        }
Beispiel #2
0
        public async Task append_then_get_events_no_snapshot()
        {
            var commit1 = Setup.UnversionedCommit();
            var commit2 = Setup.UnversionedCommit(guid: commit1.EntityId);
            var commit3 = Setup.UnversionedCommit();
            await _store.Append(commit1);

            await _store.Append(commit2);

            await _store.Append(commit3);

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

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

            commits.Length.Should().Be(2);
            commits[0].Version.Should().Be(1);
            commits[0].EventData.Should().Be(commit1.EventData);
            commits[1].Version.Should().Be(2);
            commits[1].EventData.Should().Be(commit2.EventData);
        }
Beispiel #3
0
        public async Task <Optional <EntityEvents> > GetEvents(Action <IConfigureQuery> advancedConfig, CancellationToken?token = null)
        {
            var config = new QueryConfig();

            advancedConfig(config);
            EventStore.Logger.Debug("Getting events with query {@query}", new{ config.TenantId, config.EntityId, config.IgnoreSnapshots, config.DateStart, config.DateEnd });
            var raw = await _store.GetData(config, token ?? CancellationToken.None).ConfigureFalse();

            var dbg = new{ config.TenantId, config.EntityId };

            if (raw.HasValue)
            {
                var events = ConvertToEntityEvents(raw.Value);
                EventStore.Logger.Debug("Query for {@entity} returned " + events.Count + " events", dbg);

                return(new Optional <EntityEvents>(events));
            }
            else
            {
                EventStore.Logger.Debug("Query for {@entity} returned empty", dbg);
                return(Optional <EntityEvents> .Empty);
            }
        }