Beispiel #1
0
        public async Task StoreMessagesProviderTest()
        {
            // Arrange
            int             batchSize = 100;
            List <IMessage> messages  = GetNewMessages(batchSize * 3, 0).ToList();
            var             iterator  = new Mock <IMessageIterator>();

            iterator.SetupSequence(i => i.GetNext(It.IsAny <int>()))
            .ReturnsAsync(messages.Take(15))
            .ReturnsAsync(messages.Skip(15).Take(15))
            .ReturnsAsync(messages.Skip(30).Take(70))
            .ReturnsAsync(messages.Skip(100).Take(52))
            .ReturnsAsync(messages.Skip(152).Take(48))
            .ReturnsAsync(messages.Skip(200));

            // Act
            var messagesProvider = new StoringAsyncEndpointExecutor.StoreMessagesProvider(iterator.Object, 100);
            await Task.Delay(TimeSpan.FromSeconds(1));

            IMessage[] messagesBatch = await messagesProvider.GetMessages();

            // Assert
            Assert.NotNull(messagesBatch);
            Assert.Equal(batchSize, messagesBatch.Length);
            Assert.Equal(messages.Take(100), messagesBatch);

            // Act
            await Task.Delay(TimeSpan.FromSeconds(1));

            messagesBatch = await messagesProvider.GetMessages();

            // Assert
            Assert.NotNull(messagesBatch);
            Assert.Equal(batchSize, messagesBatch.Length);
            Assert.Equal(messages.Skip(100).Take(100), messagesBatch);

            // Assert
            await Task.Delay(TimeSpan.FromSeconds(1));

            iterator.VerifyAll();

            // Act
            messagesBatch = await messagesProvider.GetMessages();

            // Assert
            Assert.NotNull(messagesBatch);
            Assert.Equal(batchSize, messagesBatch.Length);
            Assert.Equal(messages.Skip(200).Take(100), messagesBatch);
        }
Beispiel #2
0
        public async Task StoreMessagesProviderIntermittantMessagesTest()
        {
            // Arrange
            int             batchSize = 10;
            List <IMessage> messages  = GetNewMessages(batchSize, 0).ToList();
            var             iterator  = new Mock <IMessageIterator>();

            iterator.SetupSequence(i => i.GetNext(It.IsAny <int>()))
            .ReturnsAsync(messages.Take(6))
            .ReturnsAsync(Enumerable.Empty <IMessage>())
            .ReturnsAsync(messages.Skip(6).Take(1))
            .ReturnsAsync(messages.Skip(7).Take(1))
            .ReturnsAsync(Enumerable.Empty <IMessage>())
            .ReturnsAsync(messages.Skip(8).Take(1))
            .ReturnsAsync(Enumerable.Empty <IMessage>());

            // Act
            var messagesProvider = new StoringAsyncEndpointExecutor.StoreMessagesProvider(iterator.Object, batchSize);
            await Task.Delay(TimeSpan.FromSeconds(1));

            IMessage[] messagesBatch = await messagesProvider.GetMessages();

            // Assert
            Assert.NotNull(messagesBatch);
            Assert.Equal(6, messagesBatch.Length);
            Assert.Equal(messages.Take(6), messagesBatch);

            // Act
            messagesBatch = await messagesProvider.GetMessages();

            // Assert
            Assert.NotNull(messagesBatch);
            Assert.Equal(2, messagesBatch.Length);
            Assert.Equal(messages.Skip(6).Take(2), messagesBatch);

            // Act
            messagesBatch = await messagesProvider.GetMessages();

            // Assert
            Assert.NotNull(messagesBatch);
            Assert.Single(messagesBatch);
            Assert.Equal(messages.Skip(8).Take(1), messagesBatch);

            // Assert
            iterator.VerifyAll();
        }