public void ProcessMessage_WhenProcessorExists_ShouldRaiseProcessorNotFoundException() { // Arrange var username = "******"; Message message = new PublicMessageRequest("Hello"); var logger = Substitute.For <ILogger <MessageProcessorService> >(); var serviceProvider = Substitute.For <IServiceProvider>(); var mockProcessor = Substitute.For <IMessageProcessor <PublicMessageRequest> >(); serviceProvider.GetService(Arg.Any <Type>()).Returns(null); MessageProcessorService messageProcessorService = new MessageProcessorService(logger, serviceProvider); // Act / Assert Assert.Throws <ProcessorNotFoundException>(() => messageProcessorService.ProcessMessage(username, message)); }
public void ProcessMessage_WhenProcessorExists_ShouldProcessMessage() { // Arrange var username = "******"; Message message = new PublicMessageRequest("Hello"); var logger = Substitute.For <ILogger <MessageProcessorService> >(); var serviceProvider = Substitute.For <IServiceProvider>(); var mockProcessor = Substitute.For <IMessageProcessor <PublicMessageRequest> >(); serviceProvider.GetService(Arg.Is(typeof(IMessageProcessor <PublicMessageRequest>))).Returns(mockProcessor); MessageProcessorService messageProcessorService = new MessageProcessorService(logger, serviceProvider); // Act messageProcessorService.ProcessMessage(username, message); // Assert mockProcessor.Received(1).HandleMessage(username, message); }