public When_a_user_handler_is_executed() { var consumerErrorStrategy = Substitute.For <IConsumerErrorStrategy>(); var eventBus = new EventBus(); var handlerRunner = new HandlerRunner(consumerErrorStrategy, eventBus); Func <byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) => Task.Factory.StartNew(() => { deliveredBody = body; deliveredProperties = properties; deliveredInfo = info; }); var consumer = Substitute.For <IBasicConsumer>(); channel = Substitute.For <IModel>(); consumer.Model.Returns(channel); var context = new ConsumerExecutionContext( userHandler, messageInfo, messageProperties, messageBody, consumer); var autoResetEvent = new AutoResetEvent(false); eventBus.Subscribe <AckEvent>(x => autoResetEvent.Set()); handlerRunner.InvokeUserMessageHandler(context); autoResetEvent.WaitOne(1000); }
public When_a_user_handler_is_cancelled() { consumerErrorStrategy = Substitute.For <IConsumerErrorStrategy>(); var eventBus = new EventBus(); var handlerRunner = new HandlerRunner(consumerErrorStrategy, eventBus); Func <byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) => Task.Run(() => throw new OperationCanceledException()); var consumer = Substitute.For <IBasicConsumer>(); var channel = Substitute.For <IModel>(); consumer.Model.Returns(channel); context = new ConsumerExecutionContext(userHandler, messageInfo, messageProperties, messageBody, consumer); var autoResetEvent = new AutoResetEvent(false); eventBus.Subscribe <AckEvent>(x => autoResetEvent.Set()); handlerRunner.InvokeUserMessageHandler(context); autoResetEvent.WaitOne(1000); }