public void Resolve_ConsumerNotFound_ConsumerNotFoundExceptionThrown()
        {
            //Arrange
            var fakeService      = Substitute.For <IFakeService>();
            var fakeLogger       = Substitute.For <ILogger <ConsumerResolver> >();
            var firstConsumer    = new FirstMessageConsumer(fakeService);
            var secondConsumer   = new SecondMessageConsumer(fakeService);
            var consumers        = new IConsumer[] { firstConsumer, secondConsumer };
            var consumerResolver = new ConsumerResolver(consumers, fakeLogger);
            var message          = new SecondMessage {
                Value = "First Message"
            };
            var messageAsString = JsonConvert.SerializeObject(message);
            var messageType     = "fakeMessageType";
            var sqsMessage      = new Message
            {
                MessageAttributes = new Dictionary <string, MessageAttributeValue>
                {
                    { "MessageType", new MessageAttributeValue {
                          StringValue = messageType
                      } }
                },
                Body = messageAsString
            };

            //Act
            var task = consumerResolver.Resolve(sqsMessage, CancellationToken.None);

            //Assert
            Should.Throw <ConsumerNotFoundException>(task);
        }
        public async Task Resolve_SecondMessageConsumerFound_HandleMethodIsInvoked()
        {
            //Arrange
            var fakeService      = Substitute.For <IFakeService>();
            var fakeLogger       = Substitute.For <ILogger <ConsumerResolver> >();
            var firstConsumer    = new FirstMessageConsumer(fakeService);
            var secondConsumer   = new SecondMessageConsumer(fakeService);
            var consumers        = new IConsumer[] { firstConsumer, secondConsumer };
            var consumerResolver = new ConsumerResolver(consumers, fakeLogger);
            var message          = new SecondMessage {
                Value = "First Message"
            };
            var messageAsString = JsonConvert.SerializeObject(message);
            var messageType     = nameof(SecondMessage);
            var sqsMessage      = new Message
            {
                MessageAttributes = new Dictionary <string, MessageAttributeValue>
                {
                    { "MessageType", new MessageAttributeValue {
                          StringValue = messageType
                      } }
                },
                Body = messageAsString
            };

            //Act
            await consumerResolver.Resolve(sqsMessage, CancellationToken.None);

            //Assert
            fakeService.DidNotReceive().FirstMethod();
            fakeService.Received(1).SecondMethod();
        }
        public async Task Resolve_ConsumersFound_TwoMethodsAreInvokedTwice()
        {
            //Arrange
            var fakeService      = Substitute.For <IFakeService>();
            var fakeLogger       = Substitute.For <ILogger <ConsumerResolver> >();
            var firstConsumer    = new FirstMessageConsumer(fakeService);
            var secondConsumer   = new SecondMessageConsumer(fakeService);
            var thirdConsumer    = new ThirdMessageConsumer(fakeService);
            var consumers        = new IConsumer[] { firstConsumer, secondConsumer, thirdConsumer };
            var consumerResolver = new ConsumerResolver(consumers, fakeLogger);
            var firstMessage     = new FirstMessage {
                Value = "First Message"
            };
            var firstSqsMessage = new Message
            {
                MessageAttributes = new Dictionary <string, MessageAttributeValue>
                {
                    { "MessageType", new MessageAttributeValue {
                          StringValue = nameof(FirstMessage)
                      } }
                },
                Body = JsonConvert.SerializeObject(firstMessage)
            };

            var secondMessage = new SecondMessage {
                Value = "Second Message"
            };
            var secondSqsMessage = new Message
            {
                MessageAttributes = new Dictionary <string, MessageAttributeValue>
                {
                    { "MessageType", new MessageAttributeValue {
                          StringValue = nameof(SecondMessage)
                      } }
                },
                Body = JsonConvert.SerializeObject(secondMessage)
            };

            //Act
            await consumerResolver.Resolve(firstSqsMessage, CancellationToken.None);

            await consumerResolver.Resolve(secondSqsMessage, CancellationToken.None);

            //Assert
            fakeService.Received(2).FirstMethod();
            fakeService.Received(2).SecondMethod();
        }
Beispiel #4
0
        public void Resolve_ConsumerNotFound_ConsumerNotFoundExceptionThrown()
        {
            //Arrange
            var fakeService      = Substitute.For <IFakeService>();
            var firstConsumer    = new FirstMessageConsumer(fakeService);
            var secondConsumer   = new SecondMessageConsumer(fakeService);
            var consumers        = new IConsumer[] { firstConsumer, secondConsumer };
            var consumerResolver = new ConsumerResolver(consumers);
            var message          = new SecondMessage {
                Value = "First Message"
            };
            var messageAsString = JsonConvert.SerializeObject(message);
            var messageType     = "fakeMessageType";

            //Act
            var task = consumerResolver.Resolve(messageAsString, messageType, CancellationToken.None);

            //Assert
            Should.Throw <ConsumerNotFoundException>(task);
        }
Beispiel #5
0
        public async Task Resolve_SecondMessageConsumerFound_HandleMethodIsInvoked()
        {
            //Arrange
            var fakeService      = Substitute.For <IFakeService>();
            var firstConsumer    = new FirstMessageConsumer(fakeService);
            var secondConsumer   = new SecondMessageConsumer(fakeService);
            var consumers        = new IConsumer[] { firstConsumer, secondConsumer };
            var consumerResolver = new ConsumerResolver(consumers);
            var message          = new SecondMessage {
                Value = "First Message"
            };
            var messageAsString = JsonConvert.SerializeObject(message);
            var messageType     = nameof(SecondMessage);

            //Act
            await consumerResolver.Resolve(messageAsString, messageType, CancellationToken.None);

            //Assert
            fakeService.DidNotReceive().FirstMethod();
            fakeService.Received(1).SecondMethod();
        }