Exemplo n.º 1
0
        public void TestThatJournalReaderReadsThreeEvents()
        {
            var interest = new MockAppendResultInterest <Test1Source, SnapshotState>();

            _dispatcher.AfterCompleting(1);
            interest.AfterCompleting(1);

            var three = new List <Source <string> > {
                new Test1Source(), new Test2Source(), new Test1Source()
            };

            _journal.AppendAll <Source <string>, SnapshotState>("123", 1, three, interest, _object);

            var accessResults = new TestResults().AfterCompleting(1);

            _journal.JournalReader <TextEntry>("test")
            .AndThenTo(reader => reader.ReadNext(5)
                       .AndThenConsume(entries => {
                accessResults.WriteUsing("addAll", entries.Select(entry => (BaseEntry <string>)entry).ToList());
            }));

            Assert.Equal(3, accessResults.ReadFrom <int>("size"));
            Assert.Equal("1", accessResults.ReadFrom <int, string>("entryId", 0));
            Assert.Equal("2", accessResults.ReadFrom <int, string>("entryId", 1));
            Assert.Equal("3", accessResults.ReadFrom <int, string>("entryId", 2));
        }
Exemplo n.º 2
0
        public void TestThatStreamReaderReadsFromBeyondSnapshot()
        {
            var interest = new MockAppendResultInterest <Test1Source, SnapshotState>();

            _dispatcher.AfterCompleting(5);
            interest.AfterCompleting(5);

            _journal.Append <Test1Source, SnapshotState>("123", 1, new Test1Source(), interest, _object);
            _journal.Append <Test1Source, SnapshotState>("123", 2, new Test1Source(), interest, _object);
            _journal.AppendWith("123", 3, new Test1Source(), new SnapshotState(), interest, _object);
            _journal.Append <Test1Source, SnapshotState>("123", 4, new Test1Source(), interest, _object);
            _journal.Append <Test1Source, SnapshotState>("123", 5, new Test1Source(), interest, _object);

            var accessResults = new TestResults().AfterCompleting(1);

            _journal.StreamReader("test")
            .AndThenTo(reader => reader.StreamFor("123", 4)
                       .AndThenConsume(eventStream => {
                accessResults.WriteUsing("addAll", eventStream.Entries.Select(entry => (BaseEntry <string>)entry).ToList());
                Assert.Null(eventStream.Snapshot);
            }));

            Assert.Equal(2, accessResults.ReadFrom <int>("size"));
            Assert.Equal("4", accessResults.ReadFrom <int, string>("entryId", 0));
            Assert.Equal("5", accessResults.ReadFrom <int, string>("entryId", 1));
        }
Exemplo n.º 3
0
        public void TestThatJournalReaderReadsOneEvent()
        {
            var interest = new MockAppendResultInterest <Test1Source, SnapshotState>();

            _dispatcher.AfterCompleting(1);
            interest.AfterCompleting(1);

            var source        = new Test1Source();
            var streamName    = "123";
            var streamVersion = 1;

            _journal.Append <Test1Source, SnapshotState>(streamName, streamVersion, source, interest, _object);

            var accessResults = new TestResults().AfterCompleting(1);

            _journal.JournalReader <TextEntry>("test")
            .AndThenTo(reader => reader.ReadNext()
                       .AndThenConsume(@event => {
                accessResults.WriteUsing("addAll", new List <BaseEntry <string> > {
                    @event
                });
            }));

            Assert.NotNull(accessResults.ReadFrom <int, BaseEntry <string> >("entry", 0));
            Assert.Equal("1", accessResults.ReadFrom <int, string>("entryId", 0));
        }
Exemplo n.º 4
0
        public void TestThatJournalAppendsOneEvent()
        {
            var interest = new MockAppendResultInterest <Test1Source, SnapshotState>();

            _dispatcher.AfterCompleting(1);
            interest.AfterCompleting(1);

            var source        = new Test1Source();
            var streamName    = "123";
            var streamVersion = 1;

            _journal.Append <Test1Source, SnapshotState>(streamName, streamVersion, source, interest, _object);

            Assert.Equal(1, interest.ReceivedAppendsSize);

            var entries     = interest.Entries;
            var journalData = entries.First();

            Assert.NotNull(journalData);
            Assert.Equal(streamName, journalData.StreamName);
            Assert.Equal(streamVersion, journalData.StreamVersion);
            Assert.Equal(Result.Success, journalData.Result);
            Assert.False(journalData.Snapshot.IsPresent);

            var sourceList = journalData.Sources;

            Assert.Single(sourceList);
            Assert.Equal(source, sourceList.First());

            Assert.Equal(1, _dispatcher.DispatchedCount());
            var dispatched = _dispatcher.GetDispatched()[0];

            Assert.NotEqual(new DateTimeOffset(), dispatched.CreatedOn);
            Assert.False(dispatched.State.IsPresent);
            Assert.NotNull(dispatched.Id);
            var dispatchedEntries = dispatched.Entries;

            Assert.Single(dispatchedEntries);
        }