Exemplo n.º 1
0
        /// <summary>
        /// Activates the test that has been set up passing in given message,
        /// setting the incoming headers and the message Id.
        /// </summary>
        public void OnMessage <TMessage>(TMessage message, string messageId)
        {
            var context = new MessageContext {
                Id = messageId, ReturnAddress = "client", Headers = incomingHeaders
            };

            bus.CurrentMessageContext = context;

            foreach (var keyValuePair in incomingHeaders)
            {
                bus.SetHeaderAction(message, keyValuePair.Key, keyValuePair.Value);
            }

            ExtensionMethods.CurrentMessageBeingHandled = message;

            try
            {
                var method = GetMessageHandler(handler.GetType(), typeof(TMessage));
                method.Invoke(handler, new object[] { message });
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }

            bus.ValidateAndReset(expectedInvocations);
            expectedInvocations.Clear();

            ExtensionMethods.CurrentMessageBeingHandled = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Activates the test that has been set up passing in given message,
        /// setting the incoming headers and the message Id.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="message"></param>
        /// <param name="messageId"></param>
        public void OnMessage <TMessage>(TMessage message, string messageId)
        {
            var context = new MessageContext {
                Id = messageId, ReturnAddress = "client", Headers = incomingHeaders
            };

            bus.CurrentMessageContext = context;

            foreach (KeyValuePair <string, string> kvp in incomingHeaders)
            {
                ExtensionMethods.SetHeaderAction(message, kvp.Key, kvp.Value);
            }

            ExtensionMethods.CurrentMessageBeingHandled = message;

            MethodInfo method = GetMessageHandler(handler.GetType(), typeof(TMessage));

            method.Invoke(handler, new object[] { message });

            bus.ValidateAndReset(expectedInvocations);
            expectedInvocations.Clear();

            assertions.ForEach(a => a());

            assertions.Clear();
            ExtensionMethods.CurrentMessageBeingHandled = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Uses the given delegate to invoke the saga, checking all the expectations previously set up,
        /// and then clearing them for continued testing.
        /// </summary>
        /// <param name="sagaIsInvoked"></param>
        public Saga <T> When(Action <T> sagaIsInvoked)
        {
            var id = messageId();

            var context = new MessageContext {
                Id = id, ReturnAddress = saga.Entity.Originator, Headers = incomingHeaders
            };

            bus.CurrentMessageContext = context;

            sagaIsInvoked(saga);

            bus.ValidateAndReset(expectedInvocations);
            expectedInvocations.Clear();

            messageId = () => Guid.NewGuid().ToString();
            return(this);
        }