コード例 #1
0
        public async Task StartAsync_should_log_exceptions()
        {
            var messages = new[]
            {
                DummyMessage.New(),
            };
            var asyncMessages = GetMessagesAsync(messages);

            var processor = NSubstitute.Substitute.For <IMessageProcessor>();
            var ex        = new Exception("whoops");

            processor.When(p => p.ProcessAsync(messages[0], Arg.Any <CancellationToken>()))
            .Throw(ex);

            var reader = NSubstitute.Substitute.For <ChannelReader <DummyMessage> >();

            reader.ReadAllAsync()
            .ReturnsForAnyArgs(asyncMessages);

            var logger = new FakeLogger <InMemorySubscriber <DummyMessage> >();

            var sut = new InMemorySubscriber <DummyMessage>(processor, reader, logger);
            await sut.StartAsync();

            logger.Logs.Count.Should().Be(1);
            logger.Logs.Should().Contain(l => l.ex == ex);
        }
コード例 #2
0
        public async Task StartAsync_should_consume_messages()
        {
            var processor = NSubstitute.Substitute.For <IMessageProcessor>();

            var messages = new[]
            {
                DummyMessage.New(),
                DummyMessage.New(),
            };
            var asyncMessages = GetMessagesAsync(messages);

            var reader = NSubstitute.Substitute.For <ChannelReader <DummyMessage> >();

            reader.ReadAllAsync()
            .ReturnsForAnyArgs(asyncMessages);

            var logger = NSubstitute.Substitute.For <ILogger <InMemorySubscriber <DummyMessage> > >();

            var sut = new InMemorySubscriber <DummyMessage>(processor, reader, logger);
            await sut.StartAsync();

            foreach (var message in messages)
            {
                await processor.Received(1).ProcessAsync(message);
            }
        }
コード例 #3
0
        public void StopAsync_should_do_nothing() // just to make Sonarcloud happy
        {
            var processor = NSubstitute.Substitute.For <IMessageProcessor>();
            var reader    = NSubstitute.Substitute.For <ChannelReader <DummyMessage> >();
            var logger    = NSubstitute.Substitute.For <ILogger <InMemorySubscriber <DummyMessage> > >();
            var sut       = new InMemorySubscriber <DummyMessage>(processor, reader, logger);
            var result    = sut.StopAsync();

            result.Should().Be(Task.CompletedTask);
        }