public async Task Resolve_ConsumerFound_TwoMethodsAreInvoked() { //Arrange var fakeService = Substitute.For <IFakeService>(); var fakeLogger = Substitute.For <ILogger <ConsumerResolver> >(); var thirdConsumer = new ThirdMessageConsumer(fakeService); var consumers = new IConsumer[] { 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(1).FirstMethod(); fakeService.Received(1).SecondMethod(); }
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); }
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(); }
public Task Consume(SecondMessage message, CancellationToken cancellationToken) { _fakeService.SecondMethod(); return(Task.CompletedTask); }