public When_a_user_handler_is_failed() { consumerErrorStrategy = Substitute.For <IConsumerErrorStrategy>(); consumerErrorStrategy.HandleConsumerError(null, null).ReturnsForAnyArgs(AckStrategies.Ack); var handlerRunner = new HandlerRunner(consumerErrorStrategy); var consumer = Substitute.For <IBasicConsumer>(); channel = Substitute.For <IModel>(); consumer.Model.Returns(channel); context = new ConsumerExecutionContext( async(body, properties, info) => throw new Exception(), messageInfo, messageProperties, messageBody ); var handlerTask = handlerRunner.InvokeUserMessageHandlerAsync(context) .ContinueWith(async x => { var ackStrategy = await x.ConfigureAwait(false); return(ackStrategy(channel, 42)); }, TaskContinuationOptions.ExecuteSynchronously) .Unwrap(); if (!handlerTask.Wait(5000)) { throw new TimeoutException(); } }
public When_a_user_handler_is_executed() { var consumerErrorStrategy = Substitute.For <IConsumerErrorStrategy>(); var handlerRunner = new HandlerRunner(consumerErrorStrategy); var consumer = Substitute.For <IBasicConsumer>(); channel = Substitute.For <IModel, IRecoverable>(); consumer.Model.Returns(channel); var context = new ConsumerExecutionContext( async(body, properties, info, cancellation) => { await Task.Run(() => { deliveredBody = body; deliveredProperties = properties; deliveredInfo = info; }).ConfigureAwait(false); return(AckStrategies.Ack); }, messageInfo, messageProperties, messageBody ); var handlerTask = handlerRunner.InvokeUserMessageHandlerAsync(context, default) .ContinueWith(async x => { var ackStrategy = await x.ConfigureAwait(false); return(ackStrategy(channel, 42)); }, TaskContinuationOptions.ExecuteSynchronously) .Unwrap(); if (!handlerTask.Wait(5000)) { throw new TimeoutException(); } }