public void Process_MessageNotSerialized_ShouldNotSendResultAndUpdateTask() { TaskService.Invocations.Clear(); Sender.Invocations.Clear(); var taskId = Guid.NewGuid(); var queueName = $"{taskId}_queue"; var message = "queueName"; TaskService.Setup(x => x.UpdateStatus(taskId, TaskStatus.Completed, Result)); TaskService.Setup(x => x.SetError(taskId, ErrorMessage)); Sender.Setup(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>())); var service = new TestMessageProcessor1(TaskService.Object, Sender.Object); service.Process(message); TaskService.Verify(x => x.UpdateStatus(taskId, TaskStatus.Completed, Result), Times.Never); TaskService.Verify(x => x.SetError(taskId, ErrorMessage), Times.Never); Sender.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public async Task ShouldStartAllMessageProcessorsAndForwardTheMessage() { // Message Flow: // TestMessageProcessor1 --> TestMessageProcessor2 --> TestMessageProcessor3 // Message source for message processor 1 var inMemoryQueue1 = new Queue <TestMessage>(); var queueMessageSource1 = new InMemoryQueuePollingMessageSource(inMemoryQueue1, TimeSpan.FromSeconds(1)); // Message source for message processor 2 var inMemoryQueue2 = new Queue <TestMessage>(); var queueMessageSource2 = new InMemoryQueuePollingMessageSource(inMemoryQueue2, TimeSpan.FromSeconds(1)); // Message source for message processor 3 var inMemoryQueue3 = new Queue <TestMessage>(); var queueMessageSource3 = new InMemoryQueuePollingMessageSource(inMemoryQueue3, TimeSpan.FromSeconds(1)); var messageProcessor1 = new TestMessageProcessor1(queueMessageSource1); var messageProcessor2 = new TestMessageProcessor2(queueMessageSource2); var messageProcessor3 = new TestMessageProcessor3(queueMessageSource3); MessageProcessorHost host = new MessageProcessorHostBuilder() .AddMessageProcessor <TestMessage>(messageProcessor1) .AddMessageProcessor <TestMessage>(messageProcessor2) .AddMessageProcessor <TestMessage>(messageProcessor3) .Build(); await host.StartAsync(); // Put message to message processor 1's queue. var testMessage = new TestMessage(); inMemoryQueue1.Enqueue(testMessage); // Wait for message to be passed to message processor 3 await Task.Delay(TimeSpan.FromSeconds(5)); Assert.True(messageProcessor3.IsHoldingMessage(testMessage.MessageId)); }
public void Process_Success_ShouldSendResultAndUpdateTask() { TaskService.Invocations.Clear(); Sender.Invocations.Clear(); var taskId = Guid.NewGuid(); var queueName = $"{taskId}_queue"; var message = "{\"email\" : \"[email protected]\", \"name\": \"test\", \"task_id\":\"" + taskId + "\",\"callback_queue_name\":\"" + queueName + "\"}"; var callbackQueueName = string.Empty; var result = string.Empty; var sendingMessage = ""; TaskService.Setup(x => x.UpdateStatus(taskId, TaskStatus.Completed, Result)) .Callback <Guid, TaskStatus, string>((idParam, statusParam, messageParam) => { result = messageParam; }); TaskService.Setup(x => x.SetError(taskId, ErrorMessage)); Sender.Setup(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>())) .Callback <string, string>((queueParam, messageParam) => { callbackQueueName = queueParam; sendingMessage = messageParam; }); var service = new TestMessageProcessor1(TaskService.Object, Sender.Object); service.Process(message); TaskService.Verify(x => x.UpdateStatus(taskId, TaskStatus.Completed, Result), Times.Once); TaskService.Verify(x => x.SetError(taskId, ErrorMessage), Times.Never); Sender.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>()), Times.Once); Assert.AreEqual(callbackQueueName, queueName); Assert.AreEqual(sendingMessage, Result); }