public async Task Should_trigger_the_consume_message_observer() { var observer = GetConsumeObserver(); TestConsumeMessageObserver <PingMessage> pingObserver = GetConsumeObserver <PingMessage>(); var mediator = MassTransit.Bus.Factory.CreateMediator(cfg => { }); mediator.ConnectConsumeObserver(observer); mediator.ConnectConsumeMessageObserver(pingObserver); TaskCompletionSource <ConsumeContext <PingMessage> > received = GetTask <ConsumeContext <PingMessage> >(); var handle = mediator.ConnectHandler <PingMessage>(x => { received.SetResult(x); return(TaskUtil.Completed); }); await mediator.Publish(new PingMessage()); await received.Task; handle.Disconnect(); await pingObserver.PostConsumed; IReceivedMessage <PingMessage> context = observer.Messages.Select <PingMessage>().First(); context.ShouldNotBeNull(); }
public async Task SetupObservers() { _pingObserver = GetConsumeObserver <PingMessage>(); Bus.ConnectConsumeMessageObserver(_pingObserver); _observer = GetConsumeObserver(); Bus.ConnectConsumeObserver(_observer); await Bus.Publish(new PingMessage()); }
public void Should_invoke_faulted() { var filter = CreateConsumePipe(); filter.ConnectHandler <MessageA>(async context => { throw new IntentionalTestException("This is a test"); }); TestConsumeMessageObserver <MessageA> interceptor = GetConsumeObserver <MessageA>(); filter.ConnectConsumeMessageObserver(interceptor); var consumeContext = GetConsumeContext(new MessageA()); Assert.That(async() => await filter.Send(consumeContext), Throws.TypeOf <IntentionalTestException>()); Assert.That(async() => await interceptor.ConsumeFaulted, Throws.TypeOf <IntentionalTestException>()); }
public async Task Should_invoke_pre() { var filter = CreateConsumePipe(); TaskCompletionSource <MessageA> received = GetTask <MessageA>(); filter.ConnectHandler <MessageA>(async context => received.TrySetResult(context.Message)); TestConsumeMessageObserver <MessageA> interceptor = GetConsumeObserver <MessageA>(); filter.ConnectConsumeMessageObserver(interceptor); var consumeContext = GetConsumeContext(new MessageA()); await filter.Send(consumeContext); await received.Task; await interceptor.PreConsumed; }
public async Task Should_invoke_post_consumer() { var filter = CreateConsumePipe(); TaskCompletionSource <MessageA> received = GetTask <MessageA>(); filter.ConnectConsumer(() => new OneMessageConsumer(received)); TestConsumeMessageObserver <MessageA> interceptor = GetConsumeObserver <MessageA>(); filter.ConnectConsumeMessageObserver(interceptor); var consumeContext = GetConsumeContext(new MessageA()); await filter.Send(consumeContext); await received.Task; await interceptor.PostConsumed; }
public async Task Should_trigger_the_consume_message_observer_for_both() { var observer = GetConsumeObserver(); TestConsumeMessageObserver <PingMessage> pingObserver = GetConsumeObserver <PingMessage>(); var mediator = MassTransit.Bus.Factory.CreateMediator(cfg => { }); mediator.ConnectConsumeObserver(observer); mediator.ConnectConsumeMessageObserver(pingObserver); TaskCompletionSource <ConsumeContext <PingMessage> > received = GetTask <ConsumeContext <PingMessage> >(); var handle = mediator.ConnectHandler <PingMessage>(x => { received.SetResult(x); return(x.RespondAsync(new PongMessage(x.Message.CorrelationId))); }); IRequestClient <PingMessage> client = mediator.CreateRequestClient <PingMessage>(); var pingMessage = new PingMessage(); Response <PongMessage> response = await client.GetResponse <PongMessage>(pingMessage); await received.Task; handle.Disconnect(); await pingObserver.PostConsumed; Assert.That(observer.Messages.Select <PingMessage>().First(), Is.Not.Null); Assert.That(observer.Messages.Select <PongMessage>().First(), Is.Not.Null); }