Exemplo n.º 1
0
        public async Task RememberConsumedStreamVersionAsync_WhenLatestManuallyCommitedVersionEqualsToStreamCurrent_SkipCommitOnReceiveAsync(
            [Frozen] StreamVersion version,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            [Frozen] Mock <IEventStreamReader> readerMock,
            [Frozen] JournaledEvent[] events,
            EventStreamConsumer consumer)
        {
            var streamVersion = version.Increment(events.Length);

            readerMock
            .Setup(self => self.StreamVersion)
            .Returns(streamVersion);

            await consumer.ReceiveEventsAsync();

            var handledEvents = 0;

            foreach (var e in consumer.EnumerateEvents())
            {
                handledEvents++;
                await consumer.CommitProcessedStreamVersionAsync();
            }

            await consumer.ReceiveEventsAsync();

            Assert.Equal(handledEvents, commitStreamVersionMock.CallsCount);
            Assert.Equal(streamVersion, commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 2
0
        public async Task ReceiveEventsAsync_WhenReceivingWasStartedAndAutoCommitDisabled_DoesNotCommitReaderVersion(
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            [Frozen] IEventStreamReader reader,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            await consumer.ReceiveEventsAsync();

            Assert.Equal(0, commitStreamVersionMock.CallsCount);
            Assert.Equal(StreamVersion.Unknown, commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 3
0
        public async Task ReceiveEventsAsync_WhenReceivingWasStarted_CommitsReaderVersion(
            [Frozen] StreamVersion streamVersion,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            [Frozen] IEventStreamReader reader,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync(); // starts receiving

            await consumer.ReceiveEventsAsync(); // continues receiving and commits previous events

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
            Assert.Equal(streamVersion.Increment(reader.Events.Count), commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 4
0
        public async Task RememberConsumedStreamVersionAsync_WhenSkipCurrentFlagIsTrue_CommitsOnlyProcessedEvents(
            [Frozen] StreamVersion version,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            [Frozen] Mock <IEventStreamReader> readerMock,
            [Frozen] JournaledEvent[] events,
            EventStreamConsumer consumer)
        {
            var streamVersion = version.Increment(events.Length);

            readerMock
            .Setup(self => self.StreamVersion)
            .Returns(streamVersion);

            await consumer.ReceiveEventsAsync();

            var handledEvents = 0;

            foreach (var e in consumer.EnumerateEvents())
            {
                handledEvents++;
                await consumer.CommitProcessedStreamVersionAsync(skipCurrent : true);
            }

            Assert.Equal(handledEvents - 1, commitStreamVersionMock.CallsCount);
            Assert.Equal(streamVersion.Decrement(), commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 5
0
        public async Task ReceiveAsync_WhenReaderIsNotEmpty_ReadEventsFromReader(
            [Frozen] Mock <IEventStreamReader> readerMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            readerMock.Verify(self => self.ReadEventsAsync(), Times.Once());
        }
Exemplo n.º 6
0
        public async Task ReceiveAsync_WhenReaderIsEmpty_FreesSession(
            [Frozen] Mock <IEventStreamConsumingSession> sessionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            sessionMock.Verify(self => self.FreeAsync(), Times.Once());
        }
Exemplo n.º 7
0
        public async Task CommitProcessedStreamVersionAsync_WhenReceivingWasStartedAndAutoCommitDisabled_DoesNotCommitReaderVersion(
            [Frozen] StreamVersion streamVersion,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            [Frozen] IEventStreamReader reader,
            EventStreamConsumer consumer)
        {
            var expectedVersion = reader.StreamVersion.Increment(reader.Events.Count * 2);

            await consumer.ReceiveEventsAsync();

            await consumer.ReceiveEventsAsync();

            await consumer.CommitProcessedStreamVersionAsync(false);

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
            Assert.Equal(expectedVersion, commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 8
0
        public async Task EnumerateEvents_WhenReceiveMethodWasCalled_ReturnsEventsFromReader(
            [Frozen] IReadOnlyList <JournaledEvent> events,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            var receivedEvents = consumer.EnumerateEvents();

            Assert.Equal(events, receivedEvents);
        }
Exemplo n.º 9
0
        public async Task CloseAsync_WhenReaderHasUnprocessedEventsAndNoMessagesWereConsumed_DoesNotThrow(
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            await consumer.CloseAsync();

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
        }
Exemplo n.º 10
0
        public async Task CloseAsync_FreesConsumingSessions(
            [Frozen] Mock <IEventStreamConsumingSession> sessionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            await consumer.CloseAsync();

            sessionMock.Verify(self => self.FreeAsync(), Times.Once());
        }
Exemplo n.º 11
0
        public async Task CloseAsync_WhenReaderInCompletedStateAndHasNoUnprocessedEvents_CommitsConsumedVersion(
            [Frozen] StreamVersion version,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            [Frozen] IEventStreamReader reader,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            consumer.EnumerateEvents().ToList();

            await consumer.CloseAsync();

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
            Assert.Equal(reader.StreamVersion.Increment(reader.Events.Count), commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 12
0
        public async Task RememberConsumedStreamVersionAsync_WhenSkipCurrentFlagIsTrue_CommitsOnlyProcessedEvents(
            [Frozen] StreamVersion version,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            var handledEvents = 0;

            foreach (var e in consumer.EnumerateEvents())
            {
                handledEvents++;
                await consumer.CommitProcessedStreamVersionAsync(skipCurrent : true);

                break;
            }

            Assert.Equal(0, commitStreamVersionMock.CallsCount);
        }
Exemplo n.º 13
0
        public async Task CloseAsync_WhenReaderHasUnprocessedEventsAndCurrentEventHasBeenCommited_SkipCommit(
            [Frozen] StreamVersion version,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            foreach (var e in consumer.EnumerateEvents())
            {
                await consumer.CommitProcessedStreamVersionAsync();

                break;
            }

            await consumer.CloseAsync();

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
            Assert.Equal(version.Increment(), commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 14
0
        public async Task RememberConsumedStreamVersionAsync_WhenAllEventsWereConsumed_CommitsReaderVersion(
            [Frozen] StreamVersion streamVersion,
            [Frozen] IEventStreamReader streamReader,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            var handledEvents = 0;

            foreach (var e in consumer.EnumerateEvents())
            {
                handledEvents++;
            }

            await consumer.CommitProcessedStreamVersionAsync(true);

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
            Assert.Equal(streamReader.StreamVersion.Increment(streamReader.Events.Count), commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 15
0
        public async Task RememberConsumedStreamVersionAsync_WhenEventWasConsumedAndAutoCommitDisabled_CommitsConsumedVersion(
            [Frozen] StreamVersion version,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            var handledEvents = 0;

            foreach (var e in consumer.EnumerateEvents())
            {
                handledEvents++;
                await consumer.CommitProcessedStreamVersionAsync();

                break;
            }

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
            Assert.Equal(version.Increment(handledEvents), commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 16
0
        public async Task CloseAsync_WhenReaderHasUnprocessedEventsAndOnMessagesWasConsumed_CommitsConsumedVersion(
            [Frozen] StreamVersion version,
            [Frozen] CommitStreamVersionFMock commitStreamVersionMock,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            var handledEventCount = 0;

            foreach (var e in consumer.EnumerateEvents())
            {
                if (handledEventCount >= 1)
                {
                    break;
                }

                handledEventCount++;
            }

            await consumer.CloseAsync();

            Assert.Equal(1, commitStreamVersionMock.CallsCount);
            Assert.Equal(version.Increment(), commitStreamVersionMock.CommitedVersion);
        }
Exemplo n.º 17
0
 public async Task ReceiveAsync_WhenReaderWasNotBeenPromotedToLeader_ReturnsPromotionFailedCode(
     EventStreamConsumer consumer)
 {
     Assert.Equal(ReceivingResultCode.PromotionFailed, await consumer.ReceiveEventsAsync());
 }
Exemplo n.º 18
0
 public async Task ReceiveAsync_WhenReaderIsNotEmpty_ReturnsEventsReceivedCode(
     EventStreamConsumer consumer)
 {
     Assert.Equal(ReceivingResultCode.EventsReceived, await consumer.ReceiveEventsAsync());
 }