public void InterfaceMessageCreation() { IBus Bus = null; #region 4to5InterfaceMessageCreation Bus.Publish <MyInterfaceMessage>(o => { o.OrderNumber = 1234; }); #endregion IMessageCreator messageCreator = null; #region 4to5ReflectionInterfaceMessageCreation //This type would be derived from some other runtime information Type messageType = typeof(MyInterfaceMessage); object instance = messageCreator.CreateInstance(messageType); //use reflection to set properties on the constructed instance Bus.Publish(instance); #endregion }
//IMessageCreator is available via dependency injection void PublishEvent(IMessageCreator messageCreator) { var eventMessage = messageCreator.CreateInstance <IMyEvent>(message => { message.SomeProperty = "Hello world"; }); bus.Publish(eventMessage); }
//IMessageCreator is available via dependency injection async Task PublishEvent(IMessageCreator messageCreator) { var eventMessage = messageCreator.CreateInstance <IMyEvent>(message => { message.SomeProperty = "Hello world"; }); await messageSession.Publish(eventMessage); //or if on a message handler await context.Publish(eventMessage); }
/// <summary> /// Activates the test that has been set up passing in the given message, /// setting the incoming headers and the message Id. /// </summary> /// <param name="initializeMessage"></param> /// <param name="messageId"></param> public void OnMessage <TMessage>(Action <TMessage> initializeMessage, string messageId) where TMessage : IMessage { var context = new MessageContext { Id = messageId, ReturnAddress = "client", Headers = incomingHeaders }; var msg = messageCreator.CreateInstance(initializeMessage); foreach (KeyValuePair <string, string> kvp in incomingHeaders) { ExtensionMethods.SetHeaderAction(msg, kvp.Key, kvp.Value); } ExtensionMethods.CurrentMessageBeingHandled = msg; MethodInfo method = GetMessageHandler(handler.GetType(), typeof(TMessage)); helper.Go(context, () => method.Invoke(handler, new object[] { msg })); assertions.ForEach(a => a()); assertions.Clear(); ExtensionMethods.CurrentMessageBeingHandled = null; }
private Delegate GetDelegateForBusGenericMethods <TMessage>() where TMessage : IMessage { return(new HandleMessageDelegate( delegate { Action <TMessage> act = null; string destination = null; bus.CreateInstance <TMessage>(); LastCall.Repeat.Any().IgnoreArguments().Return(null).WhenCalled(mi => { mi.ReturnValue = messageCreator.CreateInstance <TMessage>(); } ); bus.CreateInstance(act); LastCall.Repeat.Any().IgnoreArguments().Return(null).WhenCalled(mi => { var action = mi.Arguments[0] as Action <TMessage>; mi.ReturnValue = messageCreator.CreateInstance(action); } ); bus.Reply(act); LastCall.Repeat.Any().IgnoreArguments().WhenCalled(mi => { var action = mi.Arguments[0] as Action <TMessage>; bus.Reply(messageCreator.CreateInstance(action)); } ); bus.Send(act); LastCall.Repeat.Any().IgnoreArguments().Return(null).WhenCalled(mi => { var action = mi.Arguments[0] as Action <TMessage>; bus.Send(messageCreator.CreateInstance(action)); } ); bus.Send(destination, act); LastCall.Repeat.Any().IgnoreArguments().Return(null).WhenCalled(mi => { var dest = mi.Arguments[0] as string; var action = mi.Arguments[1] as Action <TMessage>; bus.Send(dest, messageCreator.CreateInstance(action)); } ); bus.SendLocal(act); LastCall.Repeat.Any().IgnoreArguments().Return(null).WhenCalled(mi => { var action = mi.Arguments[0] as Action <TMessage>; bus.SendLocal(messageCreator.CreateInstance(action)); } ); bus.Publish(act); LastCall.Repeat.Any().IgnoreArguments().WhenCalled(mi => { var action = mi.Arguments[0] as Action <TMessage>; bus.Publish(messageCreator.CreateInstance(action)); } ); } )); }
public void Publish <T>(Action <T> messageConstructor) { Publish(messageCreator.CreateInstance(messageConstructor)); }
public void Dispatch <TEvent>(Action <TEvent> action) { var @event = _eventFactory.CreateInstance(action); this.Dispatch(@event); }
public T Create <T>(Action <T> action) { return(_messageCreator.CreateInstance(action)); }
/// <summary> /// Activates the test that has been set up passing in the given message, /// setting the incoming headers and the message Id. /// </summary> /// <param name="initializeMessage"></param> /// <param name="messageId"></param> public void OnMessage <TMessage>(Action <TMessage> initializeMessage, string messageId) { var msg = messageCreator.CreateInstance(initializeMessage); OnMessage(msg, messageId); }