From 47fe5bfce24bd2bd03c134dd6f3c12b06df07619 Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Thu, 5 Dec 2013 14:37:36 -0800 Subject: [PATCH 01/10] Fixes #1832 --- ...d_by_an_event_published_by_another_saga.cs | 67 ++++++++++++++++++- src/NServiceBus.Core/Sagas/Sagas.cs | 37 +--------- 2 files changed, 69 insertions(+), 35 deletions(-) diff --git a/src/NServiceBus.AcceptanceTests/Sagas/When_a_saga_is_started_by_an_event_published_by_another_saga.cs b/src/NServiceBus.AcceptanceTests/Sagas/When_a_saga_is_started_by_an_event_published_by_another_saga.cs index 6eb27d46c8..c3f1ec8b62 100644 --- a/src/NServiceBus.AcceptanceTests/Sagas/When_a_saga_is_started_by_an_event_published_by_another_saga.cs +++ b/src/NServiceBus.AcceptanceTests/Sagas/When_a_saga_is_started_by_an_event_published_by_another_saga.cs @@ -46,6 +46,39 @@ public class Context : ScenarioContext public bool IsEventSubscriptionReceived { get; set; } } + + [Test] + public void Should_start_the_saga_when_set_up_to_start_for_the_base_event() + { + Scenario.Define() + .WithEndpoint(b => + b.Given( + (bus, context) => + Subscriptions.OnEndpointSubscribed(s => + { + if (s.SubscriberReturnAddress.Queue.Contains("SagaThatIsStartedByABaseEvent")) + { + context.IsEventSubscriptionReceived = true; + } + })) + .When(c => c.IsEventSubscriptionReceived, + bus => + bus.Publish(m=> { m.DataId = Guid.NewGuid(); })) + ) + .WithEndpoint( + b => b.Given((bus, context) => bus.Subscribe())) + .Done(c => c.DidSagaComplete) + .Repeat(r => r.For(Transports.Default)) + .Should(c => Assert.True(c.DidSagaComplete)) + .Run(); + } + + public class SagaContext : ScenarioContext + { + public bool IsEventSubscriptionReceived { get; set; } + public bool DidSagaComplete { get; set; } + } + public class SagaThatPublishesAnEvent : EndpointConfigurationBuilder { public SagaThatPublishesAnEvent() @@ -125,13 +158,45 @@ public class Saga2Timeout } } + public class SagaThatIsStartedByABaseEvent : EndpointConfigurationBuilder + { + public SagaThatIsStartedByABaseEvent() + { + EndpointSetup(c => Configure.Features.Disable()) + .AddMapping(typeof(SagaThatPublishesAnEvent)); + } + + public class SagaStartedByBaseEvent : Saga, IAmStartedByMessages + { + public SagaContext Context { get; set; } + + public void Handle(BaseEvent message) + { + Data.DataId = message.DataId; + MarkAsComplete(); + Context.DidSagaComplete = true; + } + + public class SagaData : ContainSagaData + { + [Unique] + public virtual Guid DataId { get; set; } + } + } + } + [Serializable] public class StartSaga : ICommand { public Guid DataId { get; set; } } - public interface SomethingHappenedEvent : IEvent + public interface SomethingHappenedEvent : BaseEvent + { + + } + + public interface BaseEvent : IEvent { Guid DataId { get; set; } } diff --git a/src/NServiceBus.Core/Sagas/Sagas.cs b/src/NServiceBus.Core/Sagas/Sagas.cs index 612f9a3a93..9a199d5d79 100644 --- a/src/NServiceBus.Core/Sagas/Sagas.cs +++ b/src/NServiceBus.Core/Sagas/Sagas.cs @@ -122,41 +122,10 @@ public static bool ShouldMessageStartSaga(Type sagaType, Type messageType) if (messageTypes == null) return false; - return messageTypes.Contains(messageType); - } - - /// - /// Gets the saga type to instantiate and invoke if an existing saga couldn't be found by - /// the given finder using the given message. - /// - public static Type GetSagaTypeToStartIfMessageNotFoundByFinder(object message, IFinder finder) - { - Type sagaEntityType; - FinderTypeToSagaEntityTypeLookup.TryGetValue(finder.GetType(), out sagaEntityType); - - if (sagaEntityType == null) - return null; - - Type sagaType; - SagaEntityTypeToSagaTypeLookup.TryGetValue(sagaEntityType, out sagaType); - - if (sagaType == null) - return null; - - List messageTypes; - SagaTypeToMessageTypesRequiringSagaStartLookup.TryGetValue(sagaType, out messageTypes); - - if (messageTypes == null) - return null; - - if (messageTypes.Contains(message.GetType())) - return sagaType; - - foreach (var msgTypeHandleBySaga in messageTypes) - if (msgTypeHandleBySaga.IsInstanceOfType(message)) - return sagaType; + if (messageTypes.Contains(messageType)) + return true; - return null; + return messageTypes.Any(msgTypeHandleBySaga => msgTypeHandleBySaga.IsAssignableFrom(messageType)); } /// From 591a8e9906d6836c146ca34e53b163ba23cfb6c4 Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Mon, 9 Dec 2013 00:51:32 -0800 Subject: [PATCH 02/10] Relates to #1832. Adding the obsolete attribute instead of removing the unused public function. --- src/NServiceBus.Core/Sagas/Sagas.cs | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/NServiceBus.Core/Sagas/Sagas.cs b/src/NServiceBus.Core/Sagas/Sagas.cs index 9a199d5d79..342121bd04 100644 --- a/src/NServiceBus.Core/Sagas/Sagas.cs +++ b/src/NServiceBus.Core/Sagas/Sagas.cs @@ -128,6 +128,41 @@ public static bool ShouldMessageStartSaga(Type sagaType, Type messageType) return messageTypes.Any(msgTypeHandleBySaga => msgTypeHandleBySaga.IsAssignableFrom(messageType)); } + /// + /// Gets the saga type to instantiate and invoke if an existing saga couldn't be found by + /// the given finder using the given message. + /// + [ObsoleteEx(RemoveInVersion = "5.0", TreatAsErrorFromVersion = "4.4")] + public static Type GetSagaTypeToStartIfMessageNotFoundByFinder(object message, IFinder finder) + { + Type sagaEntityType; + FinderTypeToSagaEntityTypeLookup.TryGetValue(finder.GetType(), out sagaEntityType); + + if (sagaEntityType == null) + return null; + + Type sagaType; + SagaEntityTypeToSagaTypeLookup.TryGetValue(sagaEntityType, out sagaType); + + if (sagaType == null) + return null; + + List messageTypes; + SagaTypeToMessageTypesRequiringSagaStartLookup.TryGetValue(sagaType, out messageTypes); + + if (messageTypes == null) + return null; + + if (messageTypes.Contains(message.GetType())) + return sagaType; + + foreach (var msgTypeHandleBySaga in messageTypes) + if (msgTypeHandleBySaga.IsInstanceOfType(message)) + return sagaType; + + return null; + } + /// /// Returns the saga type configured for the given entity type. /// From e5a5dece716f1cd5020fac7f1f32f8e876bb89c2 Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Tue, 10 Dec 2013 01:43:05 -0800 Subject: [PATCH 03/10] Fixes https://github.com/Particular/NServiceBus/issues/1837 --- src/NServiceBus.Core/Unicast/UnicastBus.cs | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/NServiceBus.Core/Unicast/UnicastBus.cs b/src/NServiceBus.Core/Unicast/UnicastBus.cs index bf584b6acc..907811df53 100644 --- a/src/NServiceBus.Core/Unicast/UnicastBus.cs +++ b/src/NServiceBus.Core/Unicast/UnicastBus.cs @@ -18,6 +18,7 @@ namespace NServiceBus.Unicast using Routing; using Satellites; using Serialization; + using Settings; using Subscriptions; using Subscriptions.MessageDrivenSubscriptions.SubcriberSideFiltering; using Support; @@ -369,6 +370,20 @@ public virtual void Subscribe(Type messageType, Predicate condition) } var addresses = GetAddressForMessageType(messageType); + var transportDefinition = SettingsHolder.GetOrDefault("NServiceBus.Transport.SelectedTransport"); + if (transportDefinition.HasSupportForCentralizedPubSub) + { + // We are dealing with a brokered transport wired for auto pub/sub. + SubscriptionManager.Subscribe(messageType, null); + if (addresses.Count > 0) + { + Log.WarnFormat(@"MessageEndpointMappings for event {0} has been defined in the app.config in the UnicastBusConfig section. +MessageEndpointMappings are not necessary for defining event subscriptions, since you are using a brokered transport which supports pub/sub natively. +MessageEndpointMappings is only needed for specifying commands, i.e. Bus.Send destinations.", messageType.ToString()); + } + return; + } + if (addresses.Count == 0) { throw new InvalidOperationException(string.Format("No destination could be found for message type {0}. Check the section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.", messageType)); @@ -419,6 +434,20 @@ public virtual void Unsubscribe(Type messageType) } var addresses = GetAddressForMessageType(messageType); + var transportDefinition = SettingsHolder.GetOrDefault("NServiceBus.Transport.SelectedTransport"); + if (transportDefinition.HasSupportForCentralizedPubSub) + { + // We are dealing with a brokered transport wired for auto pub/sub. + SubscriptionManager.Unsubscribe(messageType, null); + if (addresses.Count > 0) + { + Log.WarnFormat(@"MessageEndpointMappings for event {0} has been defined in the app.config in the UnicastBusConfig section. +MessageEndpointMappings are not necessary for defining event subscriptions, since you are using a brokered transport which supports pub/sub natively. +MessageEndpointMappings is only needed for specifying commands, i.e. Bus.Send destinations.", messageType.ToString()); + } + return; + } + if (addresses.Count == 0) { throw new InvalidOperationException(string.Format("No destination could be found for message type {0}. Check the section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.", messageType)); From 06f948f88bf4960ca545cab50d50674f6e418d50 Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Tue, 10 Dec 2013 02:00:22 -0800 Subject: [PATCH 04/10] Relates to #1837 - Removed the warnings when the user has defined mappings in app.config. In the next version, we can try and warn the user much earlier, as soon as we detect that we have mappings for events as opposed to at Subscribe and Unsubscribe time. --- src/NServiceBus.Core/Unicast/UnicastBus.cs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/NServiceBus.Core/Unicast/UnicastBus.cs b/src/NServiceBus.Core/Unicast/UnicastBus.cs index 907811df53..3282e3776f 100644 --- a/src/NServiceBus.Core/Unicast/UnicastBus.cs +++ b/src/NServiceBus.Core/Unicast/UnicastBus.cs @@ -369,21 +369,15 @@ public virtual void Subscribe(Type messageType, Predicate condition) throw new InvalidOperationException("No subscription manager is available"); } - var addresses = GetAddressForMessageType(messageType); var transportDefinition = SettingsHolder.GetOrDefault("NServiceBus.Transport.SelectedTransport"); if (transportDefinition.HasSupportForCentralizedPubSub) { // We are dealing with a brokered transport wired for auto pub/sub. SubscriptionManager.Subscribe(messageType, null); - if (addresses.Count > 0) - { - Log.WarnFormat(@"MessageEndpointMappings for event {0} has been defined in the app.config in the UnicastBusConfig section. -MessageEndpointMappings are not necessary for defining event subscriptions, since you are using a brokered transport which supports pub/sub natively. -MessageEndpointMappings is only needed for specifying commands, i.e. Bus.Send destinations.", messageType.ToString()); - } return; } + var addresses = GetAddressForMessageType(messageType); if (addresses.Count == 0) { throw new InvalidOperationException(string.Format("No destination could be found for message type {0}. Check the section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.", messageType)); @@ -433,21 +427,15 @@ public virtual void Unsubscribe(Type messageType) throw new InvalidOperationException("No subscription manager is available"); } - var addresses = GetAddressForMessageType(messageType); var transportDefinition = SettingsHolder.GetOrDefault("NServiceBus.Transport.SelectedTransport"); if (transportDefinition.HasSupportForCentralizedPubSub) { // We are dealing with a brokered transport wired for auto pub/sub. SubscriptionManager.Unsubscribe(messageType, null); - if (addresses.Count > 0) - { - Log.WarnFormat(@"MessageEndpointMappings for event {0} has been defined in the app.config in the UnicastBusConfig section. -MessageEndpointMappings are not necessary for defining event subscriptions, since you are using a brokered transport which supports pub/sub natively. -MessageEndpointMappings is only needed for specifying commands, i.e. Bus.Send destinations.", messageType.ToString()); - } return; } + var addresses = GetAddressForMessageType(messageType); if (addresses.Count == 0) { throw new InvalidOperationException(string.Format("No destination could be found for message type {0}. Check the section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.", messageType)); From a3415d2166bbedc5c09333a620338afd074b525e Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Tue, 10 Dec 2013 16:49:47 -0800 Subject: [PATCH 05/10] Fixed failed unit tests related to #1837 --- ...akeCentralizedPubSubTransportDefinition.cs | 13 ++++++++++ .../NServiceBus.Core.Tests.csproj | 1 + .../Unicast/Receiving.cs | 9 +++++++ .../Unicast/Subscriptions.cs | 24 +++++++++++++++++-- 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/NServiceBus.Core.Tests/Fakes/FakeCentralizedPubSubTransportDefinition.cs diff --git a/src/NServiceBus.Core.Tests/Fakes/FakeCentralizedPubSubTransportDefinition.cs b/src/NServiceBus.Core.Tests/Fakes/FakeCentralizedPubSubTransportDefinition.cs new file mode 100644 index 0000000000..94d2a60ae1 --- /dev/null +++ b/src/NServiceBus.Core.Tests/Fakes/FakeCentralizedPubSubTransportDefinition.cs @@ -0,0 +1,13 @@ +namespace NServiceBus.Core.Tests.Fakes +{ + using Transports; + + public class FakeCentralizedPubSubTransportDefinition : TransportDefinition + { + public FakeCentralizedPubSubTransportDefinition() + { + HasNativePubSubSupport = true; + HasSupportForCentralizedPubSub = true; + } + } +} diff --git a/src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj b/src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj index 8a03d34d9f..7afc366799 100644 --- a/src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj +++ b/src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj @@ -132,6 +132,7 @@ + diff --git a/src/NServiceBus.Core.Tests/Unicast/Receiving.cs b/src/NServiceBus.Core.Tests/Unicast/Receiving.cs index e97261c578..ceacd087c9 100644 --- a/src/NServiceBus.Core.Tests/Unicast/Receiving.cs +++ b/src/NServiceBus.Core.Tests/Unicast/Receiving.cs @@ -7,6 +7,7 @@ using Contexts; using NUnit.Framework; using Rhino.Mocks; + using Settings; using Subscriptions; using Timeout; @@ -175,6 +176,14 @@ public void Handlers_should_not_be_invoked() [TestFixture] public class When_receiving_an_event_that_is_filtered_out_by_the_subscribe_predicate : using_the_unicastBus { + /// + /// Set Up + /// + [SetUp] + public new void SetUp() + { + SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); + } [Test] public void Should_not_invoke_the_handlers() { diff --git a/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs b/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs index 7572348f20..39beb1488b 100644 --- a/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs +++ b/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs @@ -2,7 +2,9 @@ namespace NServiceBus.Unicast.Tests { using System; using Contexts; + using Core.Tests.Fakes; using NUnit.Framework; + using Settings; [TestFixture] public class When_subscribing_to_messages : using_the_unicastBus @@ -14,7 +16,9 @@ public class When_subscribing_to_messages : using_the_unicastBus [SetUp] public new void SetUp() { + SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); router.RegisterMessageRoute(typeof(TestMessage), addressToOwnerOfTestMessage); + } [Test] public void Should_send_the_assemblyQualified_name_as_subscription_type() @@ -41,20 +45,36 @@ public void Should_set_the_message_intent_to_subscribe() public class When_subscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus { [Test] - public void Should_throw() + public void Should_throw_when_not_using_a_centralized_pub_sub_transport() { + SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); Assert.Throws(() => bus.Subscribe()); } + + [Test] + public void Should_not_throw_when_using_a_centralized_pub_sub_transport() + { + SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new FakeCentralizedPubSubTransportDefinition() ); + Assert.DoesNotThrow(() => bus.Subscribe()); + } } [TestFixture] public class When_unsubscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus { [Test] - public void Should_throw() + public void Should_throw_when_not_using_a_centralized_pub_sub_transport() { + SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); Assert.Throws(() => bus.Unsubscribe()); } + + [Test] + public void Should_not_throw_when_using_a_centralized_pub_sub_transport() + { + SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new FakeCentralizedPubSubTransportDefinition()); + Assert.DoesNotThrow(() => bus.Unsubscribe()); + } } [TestFixture] public class When_subscribing_to_command_messages : using_the_unicastBus From e88170e54bdd8d5f6e68e978606f365b5a861a4a Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 11 Dec 2013 13:02:50 +1100 Subject: [PATCH 06/10] force license dialog to be visible fixes #1840 --- src/NServiceBus.Core/Licensing/LicenseExpiredForm.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NServiceBus.Core/Licensing/LicenseExpiredForm.cs b/src/NServiceBus.Core/Licensing/LicenseExpiredForm.cs index 9c772fa542..5ba945b9a5 100644 --- a/src/NServiceBus.Core/Licensing/LicenseExpiredForm.cs +++ b/src/NServiceBus.Core/Licensing/LicenseExpiredForm.cs @@ -12,7 +12,13 @@ partial class LicenseExpiredForm : Form static ILog Logger = LogManager.GetLogger(typeof(LicenseExpiredForm)); public LicenseExpiredForm() { - InitializeComponent(); + InitializeComponent(); + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + Visible = true; } void browseButton_Click(object sender, EventArgs e) From a6ee022bcb8058966e0a4b8749919b471a2255cb Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Tue, 10 Dec 2013 22:47:36 -0800 Subject: [PATCH 07/10] Fixes #1841 --- src/NServiceBus.Core/Licensing/LicenseExpiredForm.resx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/NServiceBus.Core/Licensing/LicenseExpiredForm.resx b/src/NServiceBus.Core/Licensing/LicenseExpiredForm.resx index 33632b4bd0..b278a1e02e 100644 --- a/src/NServiceBus.Core/Licensing/LicenseExpiredForm.resx +++ b/src/NServiceBus.Core/Licensing/LicenseExpiredForm.resx @@ -118,11 +118,11 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Your license has enxpired and a new license is needed to continue + Your license has expired and a new license is needed to continue. -Please purchase a license online or browse for a license file +Please purchase a license online or browse for a license file. -If you close this dialog NServiceBus will fall back to running in basic mode +If you close this dialog NServiceBus will fall back to running in basic mode. From 0d85ae02a1c9fd696bc5e8dd731cc4a25c4c8ae6 Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Thu, 12 Dec 2013 00:42:17 -0800 Subject: [PATCH 08/10] Cleaning up the unit tests for #1837 by adding TransportDefinition as an injectable property on the UnicastBus. --- ...oker_transport_with_centralized_routing.cs | 22 +++++--- .../Unicast/Contexts/using_the_unicastbus.cs | 5 +- .../Unicast/Receiving.cs | 9 ---- .../Unicast/Subscriptions.cs | 33 ++++++------ src/NServiceBus.Core/NServiceBus.Core.csproj | 1 + .../Transports/ConfigureTransport.cs | 53 +++++++++++++++++++ .../Transports/IConfigureTransport.cs | 49 ----------------- src/NServiceBus.Core/Unicast/UnicastBus.cs | 16 ++++-- 8 files changed, 101 insertions(+), 87 deletions(-) create mode 100644 src/NServiceBus.Core/Transports/ConfigureTransport.cs diff --git a/src/NServiceBus.AcceptanceTests/PubSub/When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs b/src/NServiceBus.AcceptanceTests/PubSub/When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs index 1924860173..22bcdf8e11 100644 --- a/src/NServiceBus.AcceptanceTests/PubSub/When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs +++ b/src/NServiceBus.AcceptanceTests/PubSub/When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs @@ -8,16 +8,20 @@ public class When_publishing_an_event_using_a_broker_transport_with_centralized_routing : NServiceBusAcceptanceTest { - [Test, Ignore("Not reliable!")] + [Test, Ignore] // Ignore because, test this test is unreliable. Passed on the build server without the core fix! public void Should_be_delivered_to_allsubscribers_without_the_need_for_config() { Scenario.Define() - .WithEndpoint(b => b.When(c => c.EndpointsStarted, (bus, context) => - { - bus.Publish(new MyEvent()); - })) - .WithEndpoint() - .WithEndpoint() + .WithEndpoint + (b => b.When(c => c.IsSubscriptionProcessedForSub1 && c.IsSubscriptionProcessedForSub2, bus => bus.Publish(new MyEvent()))) + .WithEndpoint(b => b.Given((bus, context) => + { + context.IsSubscriptionProcessedForSub1 = true; + })) + .WithEndpoint(b => b.Given((bus, context) => + { + context.IsSubscriptionProcessedForSub2 = true; + })) .Done(c => c.Subscriber1GotTheEvent && c.Subscriber2GotTheEvent) .Repeat(r => r.For()) .Should(c => @@ -32,8 +36,10 @@ public void Should_be_delivered_to_allsubscribers_without_the_need_for_config() public class Context : ScenarioContext { public bool Subscriber1GotTheEvent { get; set; } - public bool Subscriber2GotTheEvent { get; set; } + + public bool IsSubscriptionProcessedForSub1 { get; set; } + public bool IsSubscriptionProcessedForSub2 { get; set; } } public class CentralizedPublisher : EndpointConfigurationBuilder diff --git a/src/NServiceBus.Core.Tests/Unicast/Contexts/using_the_unicastbus.cs b/src/NServiceBus.Core.Tests/Unicast/Contexts/using_the_unicastbus.cs index 363923a35c..e616cc88d0 100644 --- a/src/NServiceBus.Core.Tests/Unicast/Contexts/using_the_unicastbus.cs +++ b/src/NServiceBus.Core.Tests/Unicast/Contexts/using_the_unicastbus.cs @@ -53,6 +53,7 @@ public class using_a_configured_unicastBus protected StaticMessageRouter router; protected MessageHandlerRegistry handlerRegistry; + protected TransportDefinition transportDefinition; PipelineFactory pipelineFactory; @@ -60,7 +61,7 @@ public class using_a_configured_unicastBus public void SetUp() { - + transportDefinition = new Msmq(); LicenseManager.Verify(); HandlerInvocationCache.Clear(); @@ -134,6 +135,8 @@ public void SetUp() FuncBuilder.Register(() => new CreatePhysicalMessageBehavior()); FuncBuilder.Register(() => pipelineFactory); + FuncBuilder.Register(() => transportDefinition); + var messagePublisher = new StorageDrivenPublisher { diff --git a/src/NServiceBus.Core.Tests/Unicast/Receiving.cs b/src/NServiceBus.Core.Tests/Unicast/Receiving.cs index ceacd087c9..e97261c578 100644 --- a/src/NServiceBus.Core.Tests/Unicast/Receiving.cs +++ b/src/NServiceBus.Core.Tests/Unicast/Receiving.cs @@ -7,7 +7,6 @@ using Contexts; using NUnit.Framework; using Rhino.Mocks; - using Settings; using Subscriptions; using Timeout; @@ -176,14 +175,6 @@ public void Handlers_should_not_be_invoked() [TestFixture] public class When_receiving_an_event_that_is_filtered_out_by_the_subscribe_predicate : using_the_unicastBus { - /// - /// Set Up - /// - [SetUp] - public new void SetUp() - { - SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); - } [Test] public void Should_not_invoke_the_handlers() { diff --git a/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs b/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs index 39beb1488b..016867f1f7 100644 --- a/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs +++ b/src/NServiceBus.Core.Tests/Unicast/Subscriptions.cs @@ -4,8 +4,7 @@ namespace NServiceBus.Unicast.Tests using Contexts; using Core.Tests.Fakes; using NUnit.Framework; - using Settings; - + [TestFixture] public class When_subscribing_to_messages : using_the_unicastBus { @@ -16,10 +15,9 @@ public class When_subscribing_to_messages : using_the_unicastBus [SetUp] public new void SetUp() { - SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); router.RegisterMessageRoute(typeof(TestMessage), addressToOwnerOfTestMessage); - } + [Test] public void Should_send_the_assemblyQualified_name_as_subscription_type() { @@ -42,40 +40,43 @@ public void Should_set_the_message_intent_to_subscribe() } [TestFixture] - public class When_subscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus + public class When_using_a_non_centralized_pub_sub_transport : using_the_unicastBus { [Test] - public void Should_throw_when_not_using_a_centralized_pub_sub_transport() + public void Should_throw_when_subscribing_to_a_message_that_has_no_configured_address() { - SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); Assert.Throws(() => bus.Subscribe()); } [Test] - public void Should_not_throw_when_using_a_centralized_pub_sub_transport() + public void Should_throw_when_unsubscribing_to_a_message_that_has_no_configured_address() { - SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new FakeCentralizedPubSubTransportDefinition() ); - Assert.DoesNotThrow(() => bus.Subscribe()); + Assert.Throws(() => bus.Unsubscribe()); } } [TestFixture] - public class When_unsubscribing_to_a_message_that_has_no_configured_address : using_the_unicastBus + public class When_using_a_centralized_pub_sub_transport : using_the_unicastBus { + [SetUp] + public new void SetUp() + { + transportDefinition = new FakeCentralizedPubSubTransportDefinition(); + } + [Test] - public void Should_throw_when_not_using_a_centralized_pub_sub_transport() + public void Should_not_throw_when_subscribing_to_a_message_that_has_no_configured_address() { - SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new Msmq()); - Assert.Throws(() => bus.Unsubscribe()); + Assert.DoesNotThrow(() => bus.Subscribe()); } [Test] - public void Should_not_throw_when_using_a_centralized_pub_sub_transport() + public void Should_not_throw_When_unsubscribing_to_a_message_that_has_no_configured_address() { - SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", new FakeCentralizedPubSubTransportDefinition()); Assert.DoesNotThrow(() => bus.Unsubscribe()); } } + [TestFixture] public class When_subscribing_to_command_messages : using_the_unicastBus { diff --git a/src/NServiceBus.Core/NServiceBus.Core.csproj b/src/NServiceBus.Core/NServiceBus.Core.csproj index bea72dede0..f0df10729c 100644 --- a/src/NServiceBus.Core/NServiceBus.Core.csproj +++ b/src/NServiceBus.Core/NServiceBus.Core.csproj @@ -149,6 +149,7 @@ + diff --git a/src/NServiceBus.Core/Transports/ConfigureTransport.cs b/src/NServiceBus.Core/Transports/ConfigureTransport.cs new file mode 100644 index 0000000000..db764e2264 --- /dev/null +++ b/src/NServiceBus.Core/Transports/ConfigureTransport.cs @@ -0,0 +1,53 @@ +namespace NServiceBus.Transports +{ + using System; + using Features; + using Settings; + using Unicast.Transport; + + public abstract class ConfigureTransport : Feature, IConfigureTransport where T : TransportDefinition + { + public void Configure(Configure config) + { + var connectionString = TransportConnectionString.GetConnectionStringOrNull(); + + if (connectionString == null && RequiresConnectionString) + { + throw new InvalidOperationException(String.Format(Message, GetConfigFileIfExists(), typeof(T).Name, ExampleConnectionStringForErrorMessage)); + } + + SettingsHolder.Set("NServiceBus.Transport.ConnectionString", connectionString); + + var selectedTransportDefinition = Activator.CreateInstance(); + SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", selectedTransportDefinition); + config.Configurer.RegisterSingleton(selectedTransportDefinition); + InternalConfigure(config); + } + + protected abstract void InternalConfigure(Configure config); + + protected abstract string ExampleConnectionStringForErrorMessage { get; } + + protected virtual bool RequiresConnectionString + { + get { return true; } + } + + + static string GetConfigFileIfExists() + { + return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile ?? "App.config"; + } + + const string Message = + @"No default connection string found in your config file ({0}) for the {1} Transport. + +To run NServiceBus with {1} Transport you need to specify the database connectionstring. +Here is an example of what is required: + + + + "; + + } +} \ No newline at end of file diff --git a/src/NServiceBus.Core/Transports/IConfigureTransport.cs b/src/NServiceBus.Core/Transports/IConfigureTransport.cs index a60d5d5a5b..b0f3542003 100644 --- a/src/NServiceBus.Core/Transports/IConfigureTransport.cs +++ b/src/NServiceBus.Core/Transports/IConfigureTransport.cs @@ -1,10 +1,5 @@ namespace NServiceBus.Transports { - using System; - using Features; - using Settings; - using Unicast.Transport; - /// /// Configures the given transport using the default settings /// @@ -18,48 +13,4 @@ public interface IConfigureTransport /// The generic counterpart to IConfigureTransports /// public interface IConfigureTransport : IConfigureTransport where T : TransportDefinition { } - - public abstract class ConfigureTransport : Feature, IConfigureTransport where T : TransportDefinition - { - public void Configure(Configure config) - { - var connectionString = TransportConnectionString.GetConnectionStringOrNull(); - - if (connectionString == null && RequiresConnectionString) - { - throw new InvalidOperationException(String.Format(Message, GetConfigFileIfExists(), typeof(T).Name, ExampleConnectionStringForErrorMessage)); - } - - SettingsHolder.Set("NServiceBus.Transport.ConnectionString", connectionString); - SettingsHolder.Set("NServiceBus.Transport.SelectedTransport", Activator.CreateInstance()); - - InternalConfigure(config); - } - - protected abstract void InternalConfigure(Configure config); - - protected abstract string ExampleConnectionStringForErrorMessage { get; } - - protected virtual bool RequiresConnectionString - { - get { return true; } - } - - - static string GetConfigFileIfExists() - { - return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile ?? "App.config"; - } - - const string Message = - @"No default connection string found in your config file ({0}) for the {1} Transport. - -To run NServiceBus with {1} Transport you need to specify the database connectionstring. -Here is an example of what is required: - - - - "; - - } } \ No newline at end of file diff --git a/src/NServiceBus.Core/Unicast/UnicastBus.cs b/src/NServiceBus.Core/Unicast/UnicastBus.cs index 3282e3776f..0f076901f7 100644 --- a/src/NServiceBus.Core/Unicast/UnicastBus.cs +++ b/src/NServiceBus.Core/Unicast/UnicastBus.cs @@ -369,8 +369,7 @@ public virtual void Subscribe(Type messageType, Predicate condition) throw new InvalidOperationException("No subscription manager is available"); } - var transportDefinition = SettingsHolder.GetOrDefault("NServiceBus.Transport.SelectedTransport"); - if (transportDefinition.HasSupportForCentralizedPubSub) + if (TransportDefinition.HasSupportForCentralizedPubSub) { // We are dealing with a brokered transport wired for auto pub/sub. SubscriptionManager.Subscribe(messageType, null); @@ -427,8 +426,7 @@ public virtual void Unsubscribe(Type messageType) throw new InvalidOperationException("No subscription manager is available"); } - var transportDefinition = SettingsHolder.GetOrDefault("NServiceBus.Transport.SelectedTransport"); - if (transportDefinition.HasSupportForCentralizedPubSub) + if (TransportDefinition.HasSupportForCentralizedPubSub) { // We are dealing with a brokered transport wired for auto pub/sub. SubscriptionManager.Unsubscribe(messageType, null); @@ -1170,5 +1168,15 @@ LogicalMessageFactory LogicalMessageFactory return Builder.Build(); } } + + TransportDefinition TransportDefinition + { + get + { + return Builder.Build(); + } + } + + } } From 5fe8e108ddc56b20eecdb94df533cc3ba2f7e2b3 Mon Sep 17 00:00:00 2001 From: Yves Goeleven Date: Fri, 13 Dec 2013 14:02:34 +0100 Subject: [PATCH 09/10] fixes #1843 --- src/NServiceBus.Core/ConfigureQueueCreation.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/NServiceBus.Core/ConfigureQueueCreation.cs b/src/NServiceBus.Core/ConfigureQueueCreation.cs index cbf7dcfc67..a7c2611bf7 100644 --- a/src/NServiceBus.Core/ConfigureQueueCreation.cs +++ b/src/NServiceBus.Core/ConfigureQueueCreation.cs @@ -1,5 +1,7 @@ namespace NServiceBus { + using System.ComponentModel; + /// /// Contains extension methods to NServiceBus.Configure. /// @@ -15,6 +17,10 @@ public static Configure DoNotCreateQueues(this Configure config) return config; } - internal static bool DontCreateQueues { get; private set; } + /// + /// Gets whether or not queues should be created + /// + [EditorBrowsable(EditorBrowsableState.Advanced)] + public static bool DontCreateQueues { get; private set; } } } From ee1bb2d95575f8084ae1f720aa5f99e382fd6398 Mon Sep 17 00:00:00 2001 From: indualagarsamy Date: Fri, 13 Dec 2013 10:23:50 -0800 Subject: [PATCH 10/10] This will be automatic from version v4.4 --- src/NServiceBus/NServiceBusVersion.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NServiceBus/NServiceBusVersion.cs b/src/NServiceBus/NServiceBusVersion.cs index f7403394e4..fe91fdcdf6 100644 --- a/src/NServiceBus/NServiceBusVersion.cs +++ b/src/NServiceBus/NServiceBusVersion.cs @@ -8,6 +8,6 @@ public static class NServiceBusVersion /// /// The semver version of NServiceBus /// - public const string Version = "4.3.0"; + public const string Version = "4.3.1"; } }