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

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

            _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")
                       .AndThenConsume(eventStream => {
                accessResults.WriteUsing("addAll", eventStream.Entries.Select(entry => (BaseEntry <string>)entry).ToList());
            }));

            Assert.Equal(3, accessResults.ReadFrom <int>("size"));
            Assert.Equal("3", accessResults.ReadFrom <int, string>("entryId", 0));
            Assert.Equal("4", accessResults.ReadFrom <int, string>("entryId", 1));
            Assert.Equal("5", accessResults.ReadFrom <int, string>("entryId", 2));
        }