public void Test_that_expose_the_issue_with_the_current_codebase_assuming_that_routes_can_be_updated() { var router = new StaticMessageRouter(new Type[0]); var overrideAddress = Address.Parse("override"); router.RegisterMessageRoute(typeof(Message1), Address.Parse("first")); router.RegisterMessageRoute(typeof(Message1), overrideAddress); Assert.AreEqual(overrideAddress, router.GetDestinationFor(typeof(Message1)).Single()); }
public void Test_that_expose_the_issue_with_the_current_codebase_assuming_that_routes_can_be_updated() { var router = new StaticMessageRouter(new Type[0]); var overrideAddress = Address.Parse("override"); router.RegisterMessageRoute(typeof(Message1), Address.Parse("first")); router.RegisterMessageRoute(typeof(Message1), overrideAddress); Assert.AreEqual(overrideAddress, router.GetDestinationFor(typeof(Message1)).Single()); }
public void When_registered_registering_multiple_addresses_for_same_type_and_using_plainmessages_last_one_wins() { var baseType = typeof(BaseMessage); var router = new StaticMessageRouter(Enumerable.Empty <Type>()); var addressA = new Address("BaseMessage", "A"); router.RegisterMessageRoute(baseType, addressA); var addressB = new Address("BaseMessage", "b"); router.RegisterMessageRoute(baseType, addressB); Assert.AreEqual(1, router.GetDestinationFor(baseType).Count); }
public void When_registered_registering_multiple_addresses_for_same_type_and_using_plainmessages_last_one_wins() { SettingsHolder.SetProperty <DefaultAutoSubscriptionStrategy>(s => s.SubscribePlainMessages, true); var baseType = typeof(BaseMessage); var router = new StaticMessageRouter(Enumerable.Empty <Type>()); var addressA = new Address("BaseMessage", "A"); router.RegisterMessageRoute(baseType, addressA); var addressB = new Address("BaseMessage", "b"); router.RegisterMessageRoute(baseType, addressB); Assert.AreEqual(1, router.GetDestinationFor(baseType).Count); }
public void When_inherited_registered_after_base_correct_address_is_returned_for_both() { var baseType = typeof(BaseMessage); var inheritedType = typeof(InheritedMessage); var router = new StaticMessageRouter(new[] { baseType, inheritedType }); var baseAddress = new Address("baseAddress", "b"); router.RegisterMessageRoute(baseType, baseAddress); var inheritedAddress = new Address("inheritedAddress", "b"); router.RegisterMessageRoute(inheritedType, inheritedAddress); Assert.Contains(baseAddress, router.GetDestinationFor(baseType)); Assert.Contains(inheritedAddress, router.GetDestinationFor(baseType)); Assert.AreSame(inheritedAddress, router.GetDestinationFor(inheritedType).Single()); }
public void When_inherited_registered_after_base_correct_address_is_returned_for_both() { var baseType = typeof(BaseMessage); var inheritedType = typeof(InheritedMessage); var router = new StaticMessageRouter(new[] { baseType, inheritedType }); var baseAddress = new Address("baseAddress", "b"); router.RegisterMessageRoute(baseType, baseAddress); var inheritedAddress = new Address("inheritedAddress", "b"); router.RegisterMessageRoute(inheritedType, inheritedAddress); Assert.Contains(baseAddress, router.GetDestinationFor(baseType)); Assert.Contains(inheritedAddress, router.GetDestinationFor(baseType)); Assert.AreSame(inheritedAddress, router.GetDestinationFor(inheritedType).Single()); }
public void When_getting_route_correct_address_is_returned() { var router = new StaticMessageRouter(new[] { typeof(Message1) }); var address = new Address("a", "b"); router.RegisterMessageRoute(typeof(Message1), address); Assert.AreSame(address, router.GetDestinationFor(typeof(Message1)).Single()); }
public void When_getting_route_correct_address_is_returned() { var router = new StaticMessageRouter(new[] { typeof(Message1) }); var address = new Address("a", "b"); router.RegisterMessageRoute(typeof(Message1), address); Assert.AreSame(address, router.GetDestinationFor(typeof(Message1)).Single()); }
void RegisterMessageOwnersAndBusAddress(FeatureConfigurationContext context, IEnumerable <Type> knownMessages) { var unicastConfig = context.Settings.GetConfigSection <UnicastBusConfig>(); var router = new StaticMessageRouter(knownMessages); var key = typeof(AutoSubscriptionStrategy).FullName + ".SubscribePlainMessages"; if (context.Settings.HasSetting(key)) { router.SubscribeToPlainMessages = context.Settings.Get <bool>(key); } context.Container.RegisterSingleton(router); if (unicastConfig == null) { return; } if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo)) { var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo); context.Container.ConfigureProperty <ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress); } if (unicastConfig.TimeToBeReceivedOnForwardedMessages != TimeSpan.Zero) { context.Container.ConfigureProperty <ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); } var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast <MessageEndpointMapping>() .OrderByDescending(m => m) .ToList(); foreach (var mapping in messageEndpointMappings) { mapping.Configure((messageType, address) => { var conventions = context.Settings.Get <Conventions>(); if (!(conventions.IsMessageType(messageType) || conventions.IsEventType(messageType) || conventions.IsCommandType(messageType))) { return; } if (conventions.IsEventType(messageType)) { router.RegisterEventRoute(messageType, address); return; } router.RegisterMessageRoute(messageType, address); }); } }
void RegisterMessageOwnersAndBusAddress(IEnumerable <Type> knownMessages) { var unicastConfig = Configure.GetConfigSection <UnicastBusConfig>(); var router = new StaticMessageRouter(knownMessages); var key = typeof(DefaultAutoSubscriptionStrategy).FullName + ".SubscribePlainMessages"; if (SettingsHolder.HasSetting(key)) { router.SubscribeToPlainMessages = SettingsHolder.Get <bool>(key); } Configure.Instance.Configurer.RegisterSingleton <StaticMessageRouter>(router); if (unicastConfig == null) { return; } if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo)) { var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo); Configure.Instance.Configurer.ConfigureProperty <UnicastBus>(b => b.ForwardReceivedMessagesTo, forwardAddress); Configure.Instance.Configurer.ConfigureProperty <ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress); } Configure.Instance.Configurer.ConfigureProperty <UnicastBus>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); Configure.Instance.Configurer.ConfigureProperty <ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast <MessageEndpointMapping>() .OrderByDescending(m => m) .ToList(); foreach (var mapping in messageEndpointMappings) { mapping.Configure((messageType, address) => { if (!(MessageConventionExtensions.IsMessageType(messageType) || MessageConventionExtensions.IsEventType(messageType) || MessageConventionExtensions.IsCommandType(messageType))) { return; } if (MessageConventionExtensions.IsEventType(messageType)) { router.RegisterEventRoute(messageType, address); return; } router.RegisterMessageRoute(messageType, address); }); } }
void RegisterMessageOwnersAndBusAddress(IEnumerable<Type> knownMessages) { var unicastConfig = Configure.GetConfigSection<UnicastBusConfig>(); var router = new StaticMessageRouter(knownMessages); var key = typeof(DefaultAutoSubscriptionStrategy).FullName + ".SubscribePlainMessages"; if (SettingsHolder.HasSetting(key)) { router.SubscribeToPlainMessages = SettingsHolder.Get<bool>(key); } Configure.Instance.Configurer.RegisterSingleton<StaticMessageRouter>(router); if (unicastConfig == null) { return; } if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo)) { var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo); Configure.Instance.Configurer.ConfigureProperty<UnicastBus>(b => b.ForwardReceivedMessagesTo, forwardAddress); Configure.Instance.Configurer.ConfigureProperty<ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress); } Configure.Instance.Configurer.ConfigureProperty<UnicastBus>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); Configure.Instance.Configurer.ConfigureProperty<ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast<MessageEndpointMapping>() .OrderByDescending(m => m) .ToList(); foreach (var mapping in messageEndpointMappings) { mapping.Configure((messageType, address) => { if (!(MessageConventionExtensions.IsMessageType(messageType) || MessageConventionExtensions.IsEventType(messageType) || MessageConventionExtensions.IsCommandType(messageType))) { return; } if (MessageConventionExtensions.IsEventType(messageType)) { router.RegisterEventRoute(messageType, address); return; } router.RegisterMessageRoute(messageType, address); }); } }
void RegisterMessageOwnersAndBusAddress(FeatureConfigurationContext context, IEnumerable<Type> knownMessages) { var unicastConfig = context.Settings.GetConfigSection<UnicastBusConfig>(); var router = new StaticMessageRouter(knownMessages); var key = typeof(AutoSubscriptionStrategy).FullName + ".SubscribePlainMessages"; if (context.Settings.HasSetting(key)) { router.SubscribeToPlainMessages = context.Settings.Get<bool>(key); } context.Container.RegisterSingleton(router); if (unicastConfig == null) { return; } if (!string.IsNullOrWhiteSpace(unicastConfig.ForwardReceivedMessagesTo)) { var forwardAddress = Address.Parse(unicastConfig.ForwardReceivedMessagesTo); context.Container.ConfigureProperty<ForwardBehavior>(b => b.ForwardReceivedMessagesTo, forwardAddress); } if (unicastConfig.TimeToBeReceivedOnForwardedMessages != TimeSpan.Zero) { context.Container.ConfigureProperty<ForwardBehavior>(b => b.TimeToBeReceivedOnForwardedMessages, unicastConfig.TimeToBeReceivedOnForwardedMessages); } var messageEndpointMappings = unicastConfig.MessageEndpointMappings.Cast<MessageEndpointMapping>() .OrderByDescending(m => m) .ToList(); foreach (var mapping in messageEndpointMappings) { mapping.Configure((messageType, address) => { var conventions = context.Settings.Get<Conventions>(); if (!(conventions.IsMessageType(messageType) || conventions.IsEventType(messageType) || conventions.IsCommandType(messageType))) { return; } if (conventions.IsEventType(messageType)) { router.RegisterEventRoute(messageType, address); return; } router.RegisterMessageRoute(messageType, address); }); } }
protected void RegisterOwnedMessageType <T>() { router.RegisterMessageRoute(typeof(T), configure.LocalAddress); }
public void When_registered_registering_multiple_addresses_for_same_type_and_using_plainmessages_last_one_wins() { SettingsHolder.SetProperty<DefaultAutoSubscriptionStrategy>(s => s.SubscribePlainMessages, true); var baseType = typeof(BaseMessage); var router = new StaticMessageRouter(Enumerable.Empty<Type>()); var addressA = new Address("BaseMessage", "A"); router.RegisterMessageRoute(baseType, addressA); var addressB = new Address("BaseMessage", "b"); router.RegisterMessageRoute(baseType, addressB); Assert.AreEqual(1, router.GetDestinationFor(baseType).Count); }
public void When_route_with_undefined_address_is_registered_exception_is_thrown() { var router = new StaticMessageRouter(new Type[0]); Assert.Throws <InvalidOperationException>(() => router.RegisterMessageRoute(typeof(Message1), Address.Undefined)); }
public void When_route_with_undefined_address_is_registered_exception_is_thrown() { var router = new StaticMessageRouter(new Type[0]); Assert.Throws<InvalidOperationException>(() => router.RegisterMessageRoute(typeof(Message1), Address.Undefined)); }
public void When_registered_registering_multiple_addresses_for_same_type_and_using_plainmessages_last_one_wins() { var baseType = typeof(BaseMessage); var router = new StaticMessageRouter(Enumerable.Empty<Type>()); var addressA = new Address("BaseMessage", "A"); router.RegisterMessageRoute(baseType, addressA); var addressB = new Address("BaseMessage", "b"); router.RegisterMessageRoute(baseType, addressB); Assert.AreEqual(1, router.GetDestinationFor(baseType).Count); }
protected void RegisterOwnedMessageType <T>() { router.RegisterMessageRoute(typeof(T), Address.Local); }