Пример #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);
            }
        }