private async Task <MessageWaiter <T> > PublishRealMessage <T>(T testMessage, MessageProperties messageProperties, IMessageGenerator messageGenerator) { messageGenerator = messageGenerator ?? new MessageGenerator(); var messagePublisher = new MessagePublisher( _serviceProvider.GetService <IMessageSender>(), messageGenerator, new MessageProperties(_serviceProvider.GetService <ICorrelationIdProvider>())); var messageWaiter = new MessageWaiter <T>( _serviceProvider.GetService <MessageReceivedNotifier <T> >(), capturedEvent => capturedEvent.CorrelationId == messageProperties.CorrelationIdProvider.CorrelationId); await messagePublisher.PublishEvent(testMessage, messageProperties).ConfigureAwait(false); return(messageWaiter); }
public async Task WhenPublishEvent_Adds_CustomConstructorProperty() { const string testKey = "testKey"; const string testValue = "test value"; var customProperties = new Dictionary <string, string> { { testKey, testValue } }; var messageSender = Substitute.For <IMessageSender>(); var messagePublisher = new MessagePublisher(messageSender, new MessageGenerator(), new MessageProperties(new NewCorrelationIdProvider()) { CustomProperties = customProperties }); await messagePublisher.PublishEvent(new Event1()); await messageSender.Received(1) .SendMessages(Arg.Is <IEnumerable <Message> >(p => p.Any(m => ((string)m.UserProperties[testKey]).Equals(testValue)))); }
public async Task PublishEventThroughPipeline() { var publisher = new MessagePublisher( mockPipeline.Object, FullNameTypeMap.Instance, new Collection <CommandRoute>()); var @event = new ExampleEvent { Property = "Hello world" }; await publisher .PublishEvent(@event) .ConfigureAwait(false); mockPipeline.Verify( m => m.Process( It.Is <IEnumerable <OutgoingMessage> >( value => value.Single().Body == @event && value.Single().MessageTypeNames.First() == FullNameTypeMap.Instance.GetNameForType(typeof(ExampleEvent)) && value.Single().SpecificReceivingEndpointName == null)), Times.Once); }