public async Task Can_read_streams_forwards_and_backwards(ReadStreamTheory theory)
        {
            using(var fixture = GetFixture())
            {
                using(var eventStore = await fixture.GetEventStore())
                {
                    await eventStore.AppendToStream("stream-1", ExpectedVersion.NoStream, CreateNewStreamEvents(1, 2, 3));
                    await eventStore.AppendToStream("stream-2", ExpectedVersion.NoStream, CreateNewStreamEvents(4, 5, 6));

                    var streamEventsPage =
                        await eventStore.ReadStream(theory.StreamId, theory.Start, theory.PageSize, theory.Direction);

                    var expectedStreamEventsPage = theory.ExpectedStreamEventsPage;
                    var expectedEvents = theory.ExpectedStreamEventsPage.Events;

                    streamEventsPage.FromStreamVersion.Should().Be(expectedStreamEventsPage.FromStreamVersion);
                    streamEventsPage.LastStreamVersion.Should().Be(expectedStreamEventsPage.LastStreamVersion);
                    streamEventsPage.NextStreamVersion.Should().Be(expectedStreamEventsPage.NextStreamVersion);
                    streamEventsPage.ReadDirection.Should().Be(expectedStreamEventsPage.ReadDirection);
                    streamEventsPage.IsEndOfStream.Should().Be(expectedStreamEventsPage.IsEndOfStream);
                    streamEventsPage.Status.Should().Be(expectedStreamEventsPage.Status);
                    streamEventsPage.StreamId.Should().Be(expectedStreamEventsPage.StreamId);
                    streamEventsPage.Events.Count.Should().Be(expectedStreamEventsPage.Events.Count);

                    streamEventsPage.Events.ShouldAllBeEquivalentTo(
                        expectedEvents,
                        options =>
                        {
                            options.Excluding(streamEvent => streamEvent.Checkpoint);
                            options.Excluding(streamEvent => streamEvent.Created);
                            return options;
                        });
                }
            }
        }
        public async Task Can_read_streams_backwards_with_prefetch(ReadStreamTheory theory)
        {
            await store.AppendToStream("stream-1", ExpectedVersion.NoStream, CreateNewStreamMessages(1, 2, 3));

            await store.AppendToStream("stream-2", ExpectedVersion.NoStream, CreateNewStreamMessages(4, 5, 6));

            var streamMessagesPage =
                await store.ReadStreamBackwards(theory.StreamId, theory.Start, theory.PageSize);

            var expectedStreamMessagesPage = theory.ExpectedReadStreamPage;
            var expectedMessages           = theory.ExpectedReadStreamPage.Messages.ToArray();

            streamMessagesPage.FromStreamVersion.ShouldBe(expectedStreamMessagesPage.FromStreamVersion);
            streamMessagesPage.LastStreamVersion.ShouldBe(expectedStreamMessagesPage.LastStreamVersion);
            streamMessagesPage.NextStreamVersion.ShouldBe(expectedStreamMessagesPage.NextStreamVersion);
            streamMessagesPage.ReadDirection.ShouldBe(expectedStreamMessagesPage.ReadDirection);
            streamMessagesPage.IsEnd.ShouldBe(expectedStreamMessagesPage.IsEnd);
            streamMessagesPage.Status.ShouldBe(expectedStreamMessagesPage.Status);
            streamMessagesPage.StreamId.ShouldBe(expectedStreamMessagesPage.StreamId);
            streamMessagesPage.Messages.Length.ShouldBe(expectedStreamMessagesPage.Messages.Length);

            for (int i = 0; i < streamMessagesPage.Messages.Length; i++)
            {
                var streamMessage   = streamMessagesPage.Messages.ToArray()[i];
                var expectedMessage = expectedMessages[i];

                streamMessage.MessageId.ShouldBe(expectedMessage.MessageId);
                var jsonData = await streamMessage.GetJsonData();

                var expectedJsonData = await expectedMessage.GetJsonData();

                JToken.DeepEquals(
                    JObject.Parse(jsonData),
                    JObject.Parse(expectedJsonData))
                .ShouldBeTrue();
                JToken.DeepEquals(JObject.Parse(streamMessage.JsonMetadata),
                                  JObject.Parse(expectedMessage.JsonMetadata))
                .ShouldBeTrue();
                streamMessage.StreamId.ShouldBe(expectedMessage.StreamId);
                streamMessage.StreamVersion.ShouldBe(expectedMessage.StreamVersion);
                streamMessage.Type.ShouldBe(expectedMessage.Type);

                // We don't care about StreamMessage.Position and StreamMessage.Position
                // as they are non-deterministic
            }
        }
        public async Task Can_read_streams_forwards_and_backwards(ReadStreamTheory theory)
        {
            using(var fixture = GetFixture())
            {
                using(var eventStore = await fixture.GetEventStore())
                {
                    await eventStore.AppendToStream("stream-1", ExpectedVersion.NoStream, CreateNewStreamEvents(1, 2, 3));
                    await eventStore.AppendToStream("stream-2", ExpectedVersion.NoStream, CreateNewStreamEvents(4, 5, 6));

                    var streamEventsPage =
                        await eventStore.ReadStream(theory.StreamId, theory.Start, theory.PageSize, theory.Direction);

                    var expectedStreamEventsPage = theory.ExpectedStreamEventsPage;
                    var expectedEvents = theory.ExpectedStreamEventsPage.Events.ToArray();

                    streamEventsPage.FromStreamVersion.ShouldBe(expectedStreamEventsPage.FromStreamVersion);
                    streamEventsPage.LastStreamVersion.ShouldBe(expectedStreamEventsPage.LastStreamVersion);
                    streamEventsPage.NextStreamVersion.ShouldBe(expectedStreamEventsPage.NextStreamVersion);
                    streamEventsPage.ReadDirection.ShouldBe(expectedStreamEventsPage.ReadDirection);
                    streamEventsPage.IsEndOfStream.ShouldBe(expectedStreamEventsPage.IsEndOfStream);
                    streamEventsPage.Status.ShouldBe(expectedStreamEventsPage.Status);
                    streamEventsPage.StreamId.ShouldBe(expectedStreamEventsPage.StreamId);
                    streamEventsPage.Events.Count.ShouldBe(expectedStreamEventsPage.Events.Count);


                    for (int i = 0; i < streamEventsPage.Events.Count; i++)
                    {
                        var streamEvent = streamEventsPage.Events.ToArray()[i];
                        var expectedEvent = expectedEvents[i];


                        streamEvent.EventId.ShouldBe(expectedEvent.EventId);
                        streamEvent.JsonData.ShouldBe(expectedEvent.JsonData);
                        streamEvent.JsonMetadata.ShouldBe(expectedEvent.JsonMetadata);
                        streamEvent.StreamId.ShouldBe(expectedEvent.StreamId);
                        streamEvent.StreamVersion.ShouldBe(expectedEvent.StreamVersion);
                        streamEvent.Type.ShouldBe(expectedEvent.Type);

                        // We don't care about streamEvent.Checkpoint and streamEvent.Checkpoint
                        // as they are non-deterministic
                    }
                }
            }
        }
        public async Task Can_read_streams_forwards_without_prefetch(ReadStreamTheory theory)
        {
            using (var fixture = GetFixture())
            {
                using (var store = await fixture.GetStreamStore())
                {
                    await store.AppendToStream("stream-1", ExpectedVersion.NoStream, CreateNewStreamMessages(1, 2, 3));

                    await store.AppendToStream("stream-2", ExpectedVersion.NoStream, CreateNewStreamMessages(4, 5, 6));

                    var streamMessagesPage =
                        await store.ReadStreamForwards(theory.StreamId, theory.Start, theory.PageSize, false);

                    var expectedStreamMessagesPage = theory.ExpectedReadStreamPage;
                    var expectedMessages           = theory.ExpectedReadStreamPage.Messages.ToArray();

                    streamMessagesPage.FromStreamVersion.ShouldBe(expectedStreamMessagesPage.FromStreamVersion);
                    streamMessagesPage.LastStreamVersion.ShouldBe(expectedStreamMessagesPage.LastStreamVersion);
                    streamMessagesPage.NextStreamVersion.ShouldBe(expectedStreamMessagesPage.NextStreamVersion);
                    streamMessagesPage.ReadDirection.ShouldBe(expectedStreamMessagesPage.ReadDirection);
                    streamMessagesPage.IsEnd.ShouldBe(expectedStreamMessagesPage.IsEnd);
                    streamMessagesPage.Status.ShouldBe(expectedStreamMessagesPage.Status);
                    streamMessagesPage.StreamId.ShouldBe(expectedStreamMessagesPage.StreamId);
                    streamMessagesPage.Messages.Length.ShouldBe(expectedStreamMessagesPage.Messages.Length);

                    for (int i = 0; i < streamMessagesPage.Messages.Length; i++)
                    {
                        var message         = streamMessagesPage.Messages.ToArray()[i];
                        var expectedMessage = expectedMessages[i];

                        message.MessageId.ShouldBe(expectedMessage.MessageId);
                        (await message.GetJsonData()).ShouldBe(await expectedMessage.GetJsonData());
                        message.JsonMetadata.ShouldBe(expectedMessage.JsonMetadata);
                        message.StreamId.ShouldBe(expectedMessage.StreamId);
                        message.StreamVersion.ShouldBe(expectedMessage.StreamVersion);
                        message.Type.ShouldBe(expectedMessage.Type);

                        // We don't care about StreamMessage.Position and StreamMessage.Position
                        // as they are non-deterministic
                    }
                }
            }
        }
Beispiel #5
0
        public async Task Can_read_streams_backwards(ReadStreamTheory theory)
        {
            using (var fixture = GetFixture())
            {
                using (var eventStore = await fixture.GetEventStore())
                {
                    await eventStore.AppendToStream("stream-1", ExpectedVersion.NoStream, CreateNewStreamEvents(1, 2, 3));

                    await eventStore.AppendToStream("stream-2", ExpectedVersion.NoStream, CreateNewStreamEvents(4, 5, 6));

                    var streamEventsPage =
                        await eventStore.ReadStreamBackwards(theory.StreamId, theory.Start, theory.PageSize);

                    var expectedStreamEventsPage = theory.ExpectedStreamEventsPage;
                    var expectedEvents           = theory.ExpectedStreamEventsPage.Events.ToArray();

                    streamEventsPage.FromStreamVersion.ShouldBe(expectedStreamEventsPage.FromStreamVersion);
                    streamEventsPage.LastStreamVersion.ShouldBe(expectedStreamEventsPage.LastStreamVersion);
                    streamEventsPage.NextStreamVersion.ShouldBe(expectedStreamEventsPage.NextStreamVersion);
                    streamEventsPage.ReadDirection.ShouldBe(expectedStreamEventsPage.ReadDirection);
                    streamEventsPage.IsEndOfStream.ShouldBe(expectedStreamEventsPage.IsEndOfStream);
                    streamEventsPage.Status.ShouldBe(expectedStreamEventsPage.Status);
                    streamEventsPage.StreamId.ShouldBe(expectedStreamEventsPage.StreamId);
                    streamEventsPage.Events.Length.ShouldBe(expectedStreamEventsPage.Events.Length);

                    for (int i = 0; i < streamEventsPage.Events.Length; i++)
                    {
                        var streamEvent   = streamEventsPage.Events.ToArray()[i];
                        var expectedEvent = expectedEvents[i];

                        streamEvent.EventId.ShouldBe(expectedEvent.EventId);
                        streamEvent.JsonData.ShouldBe(expectedEvent.JsonData);
                        streamEvent.JsonMetadata.ShouldBe(expectedEvent.JsonMetadata);
                        streamEvent.StreamId.ShouldBe(expectedEvent.StreamId);
                        streamEvent.StreamVersion.ShouldBe(expectedEvent.StreamVersion);
                        streamEvent.Type.ShouldBe(expectedEvent.Type);

                        // We don't care about streamEvent.Checkpoint and streamEvent.Checkpoint
                        // as they are non-deterministic
                    }
                }
            }
        }