Esempio 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public async Task EnumerateEvents_WhenReceiveMethodWasCalled_ReturnsEventsFromReader(
            [Frozen] IReadOnlyList <JournaledEvent> events,
            EventStreamConsumer consumer)
        {
            await consumer.ReceiveEventsAsync();

            var receivedEvents = consumer.EnumerateEvents();

            Assert.Equal(events, receivedEvents);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
 public void EnumerateEvents_WhenReceiveMethodWasNotCalled_Throws(
     EventStreamConsumer consumer)
 {
     Assert.Throws <InvalidOperationException>(() => consumer.EnumerateEvents().ToList());
 }