void HandleTransportMessage(IBuilder childBuilder, TransportMessage msg) { // construct behavior chain - look at configuration and possibly the incoming transport message var chain = new BehaviorChain(childBuilder, contextStacker); chain.Add <MessageHandlingLoggingBehavior>(); if (ConfigureImpersonation.Impersonate) { chain.Add <ImpersonateSenderBehavior>(); } chain.Add <AuditBehavior>(); chain.Add <ForwardBehavior>(); chain.Add <UnitOfWorkBehavior>(); chain.Add <ApplyIncomingTransportMessageMutatorsBehavior>(); chain.Add <RaiseMessageReceivedBehavior>(); if (!disableMessageHandling) { chain.Add <ExtractLogicalMessagesBehavior>(); chain.Add <ApplyIncomingMessageMutatorsBehavior>(); chain.Add <CallbackInvocationBehavior>(); chain.Add <LoadHandlersBehavior>(); chain.Add <SagaPersistenceBehavior>(); chain.Add <InvokeHandlersBehavior>(); } chain.Invoke(msg); }
public void Raise <T>(T @event) { var chain = new BehaviorChain(Builder, contextStacker); chain.Add <LoadHandlersBehavior>(); chain.Add <InvokeHandlersBehavior>(); using (var context = new BehaviorContext(Builder, new TransportMessage(), contextStacker)) { var logicalMessages = new LogicalMessages { new LogicalMessage(typeof(T), @event) }; context.Set(logicalMessages); chain.Invoke(context); } }
public void When_exception_is_thrown_stack_trace_is_trimmed() { var behaviorChain = new BehaviorChain <FakeContext>(new List <Type> { typeof(SimpleBehavior1), typeof(SimpleBehavior2), typeof(BehaviorThatThrows), }); var exception = Assert.Throws <FakeException>(() => behaviorChain.Invoke(new FakeContext(null))); var stackTraceLines = exception.StackTrace .Split(new [] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(1, CountStringOccurrences(exception.StackTrace, ".Invoke(FakeContext"), "Should be only one 'Behavior.Invoke' in the stack trace"); Assert.IsTrue(stackTraceLines[0].Contains("BehaviorThatThrows.Invoke(FakeContext context, Action next)"), "First line should be the method that threw"); Assert.IsTrue(stackTraceLines[1].Contains("BehaviorChain`1.InvokeNext(T context)"), "Second line should be the Recursive Invoke"); Assert.AreEqual(exception.Message, "Exception Message"); }