public void Return_Expected_Result_Using_CompletedMessageType_Helper_Given_AdditionalProperties( string additionalPropertyKey, string additionalPropertyValue) { var additionalProperties = new Dictionary <string, object> { { additionalPropertyKey, additionalPropertyValue } }; var result = MessageHandlingResult.Completed(additionalProperties); result.Result.Should().Be(MessageHandlingResult.HandlingResult.Completed); result.AdditionalProperties[additionalPropertyKey].Should().Be(additionalPropertyValue); result.AdditionalProperties.Count.Should().Be(1); }
public async Task Handle_Deserialised_Message_Given_Valid_Message() { var message = NewMessageWithBody(); _mockSerialiser .Setup(s => s.Deserialise <MyEvent>(It.IsAny <Message>())) .Returns(MyEvent.Default); _mockHandler .Setup(h => h.HandleMessageAsync(MyEvent.Default, It.IsAny <MessageContext>(), CancellationToken.None)) .ReturnsAsync(MessageHandlingResult.Completed()); await _processor.ProcessMessageAsync(message, MyEndpointHandlingConfig.Default, CancellationToken.None).ConfigureAwait(false); _mockHandler.Verify(s => s.HandleMessageAsync(MyEvent.Default, It.IsAny <MessageContext>(), CancellationToken.None), Times.Once); }
public MultiMessageTypeListenerShould() { _mockProcessor = new Mock <IMessageProcessor <MyEvent> >(); _mockProcessor .Setup(m => m.ProcessMessageAsync(It.IsAny <Message>(), _options, CancellationToken.None)) .ReturnsAsync(MessageHandlingResult.Completed()); _mockProcessorDispatcher = new Mock <IMessageProcessorDispatcher>(); _mockProcessorDispatcher.Setup(m => m.GetProcessorForMessage(It.IsAny <Message>())).Returns(_mockProcessor.Object); _listener = new MultiMessageTypeListener <MyEndpointHandlingConfig>( new NullLogger <MultiMessageTypeListener <MyEndpointHandlingConfig> >(), _mockProcessorDispatcher.Object, new MessageReceiverFactory(), new VoidInstrumentor(), _options); }
public async Task <MessageHandlingResult> HandleMessageAsync( MySecondCommand message, MessageContext context, CancellationToken ct) { _logger.LogDebug(LogEventIds.HandlerStarted, $"{nameof(MySecondCommandHandler)}:{nameof(HandleMessageAsync)} started"); try { await FakeCallToPersistToSomeDatabase(message, ct); } catch (Exception ex) { _logger.LogError(LogEventIds.HandlerException, ex, $"Unhandled exception in {nameof(MySecondCommandHandler)}"); return(MessageHandlingResult.DeadLettered(ex, context.UserProperties)); } _logger.LogDebug(LogEventIds.HandlerFinished, $"{nameof(MySecondCommandHandler)}:{nameof(HandleMessageAsync)} finished"); return(MessageHandlingResult.Completed(context.UserProperties)); }
public async Task Track_Request_Telemetry_When_Handling_Messages(int count, bool isSuccessful, string customProperty) { var customProperties = new Dictionary <string, object> { { "customProperty", customProperty } }; _mockProcessor.Reset(); _mockProcessor .Setup(m => m.ProcessMessageAsync(It.IsAny <Message>(), _options, CancellationToken.None)) .ReturnsAsync(isSuccessful ? MessageHandlingResult.Completed(customProperties) : MessageHandlingResult.DeadLettered("BOOM", customProperties)); await _listener.StartListeningAsync(CancellationToken.None).ConfigureAwait(false); await ReceiveMessages(count).ConfigureAwait(false); _mockInstrumentor.Verify( i => i.TrackRequest( LogEventIds.ListenerHandlerFinished, It.IsAny <long>(), It.IsAny <DateTimeOffset>(), "MultiMessageTypeListener<MyEndpointHandlingConfig>", null, null, isSuccessful, It.Is <IDictionary <string, object> >(d => (string)d["customProperty"] == customProperty)), Times.Exactly(count)); }
public async Task <MessageHandlingResult> HandleMessageAsync( MyFirstCommand message, MessageContext context, CancellationToken ct) { _logger.LogDebug(LogEventIds.HandlerStarted, $"{nameof(MyFirstCommandHandler)}:{nameof(HandleMessageAsync)} started"); try { await FakeCallToHttpApiToPutAssociatedItem(message, ct).ConfigureAwait(false); await FakeSendingOfMessage(message, ct).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(LogEventIds.HandlerException, ex, $"Unhandled exception in {nameof(MyFirstCommandHandler)}"); return(MessageHandlingResult.DeadLettered(ex, context.UserProperties)); } _logger.LogDebug(LogEventIds.HandlerFinished, $"{nameof(MyFirstCommandHandler)}:{nameof(HandleMessageAsync)} finished"); return(MessageHandlingResult.Completed(context.UserProperties)); }
public MultiMessageTypeListenerShould() { _spyLogger = new SpyLogger <MultiMessageTypeListener <MyEndpointHandlingConfig> >(); _spyMessageReceiver = new SpyMessageReceiver(_options); _mockMessageReceiverFactory = new Mock <IMessageReceiverFactory>(); _mockMessageReceiverFactory.Setup(m => m.CreateMessageReceiver(_options, null)).Returns(_spyMessageReceiver); _mockInstrumentor = new Mock <IInstrumentor>(); _mockProcessor = new Mock <IMessageProcessor <MyEvent> >(); _mockProcessor .Setup(m => m.ProcessMessageAsync(It.IsAny <Message>(), _options, CancellationToken.None)) .ReturnsAsync(MessageHandlingResult.Completed()); _mockProcessorDispatcher = new Mock <IMessageProcessorDispatcher>(); _mockProcessorDispatcher.Setup(m => m.GetProcessorForMessage(It.IsAny <Message>())).Returns(_mockProcessor.Object); _listener = new MultiMessageTypeListener <MyEndpointHandlingConfig>( _spyLogger, _mockProcessorDispatcher.Object, _mockMessageReceiverFactory.Object, _mockInstrumentor.Object, _options); }
public async Task <MessageHandlingResult> HandleMessageAsync( MyEvent message, MessageContext context, CancellationToken ct) { _logger.LogDebug(LogEventIds.HandlerStarted, $"{nameof(MyEventHandler)}:{nameof(HandleMessageAsync)} started"); try { // Just some fake tasks to mimic doing something var associatedItem = await FakeCallToHttpApiToGetAssociatedItem(message, ct).ConfigureAwait(false); var dbContractItem = (message.Id, message.Name, associatedItem.Id, associatedItem.Name); await FakeCallToPersistToSomeDatabase(dbContractItem, ct); } catch (DivideByZeroException ex) { _logger.LogError(LogEventIds.HandlerException, ex, $"Unhandled exception in {nameof(MyEventHandler)}"); return(MessageHandlingResult.DeadLettered(ex, context.UserProperties)); } _logger.LogDebug(LogEventIds.HandlerFinished, $"{nameof(MyEventHandler)}:{nameof(HandleMessageAsync)} finished"); return(MessageHandlingResult.Completed(context.UserProperties)); }
public Task <MessageHandlingResult> HandleMessageAsync( MyEvent message, MessageContext context, CancellationToken ct) { return(Task.FromResult(MessageHandlingResult.Completed())); }