Esempio n. 1
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. 2
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. 3
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);
        }
Esempio n. 4
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. 5
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. 6
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. 7
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);
        }