public async Task WrapsInvokersSoTheyCanRunInsideAnActivity() { var step = new IncomingDiagnosticsHandlerInvokerWrapper(); var headers = new Dictionary <string, string> { { Headers.Type, "MyType" } }; var transportMessage = new TransportMessage(headers, Array.Empty <byte>()); var message = new Message(headers, Array.Empty <byte>()); var innerInvoker = new TestInvoker(() => { }); var handlerInvokers = new HandlerInvokers(message, new[] { innerInvoker }); var scope = new RebusTransactionScope(); var context = new IncomingStepContext(transportMessage, scope.TransactionContext); context.Save(handlerInvokers); var callbackWasInvoked = false; await step.Process(context, () => { callbackWasInvoked = true; return(Task.CompletedTask); }); Assert.That(callbackWasInvoked); var updatedInvokers = context.Load <HandlerInvokers>(); Assert.That(updatedInvokers, Is.Not.SameAs(handlerInvokers)); Assert.That(updatedInvokers, Has.Exactly(1).Items.And.All.TypeOf <HandlerInvokerWrapper>()); }
public static void EnableDiagnosticSources(this OptionsConfigurer configurer) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } configurer.Decorate <IPipeline>(c => { var pipeline = c.Get <IPipeline>(); var injector = new PipelineStepInjector(pipeline); var outgoingStep = new OutgoingDiagnosticsStep(); injector.OnSend(outgoingStep, PipelineRelativePosition.Before, typeof(SendOutgoingMessageStep)); var incomingStep = new IncomingDiagnosticsStep(); var invokerWrapper = new IncomingDiagnosticsHandlerInvokerWrapper(); injector.OnReceive(invokerWrapper, PipelineRelativePosition.After, typeof(ActivateHandlersStep)); var concatenator = new PipelineStepConcatenator(injector); concatenator.OnReceive(incomingStep, PipelineAbsolutePosition.Front); return(concatenator); }); }