Skip to content

Commit

Permalink
Merge branch 'hotfix-4.0.11' into support-4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
John Simons committed May 1, 2015
2 parents 86b3441 + 10e26b8 commit 3d672bb
Show file tree
Hide file tree
Showing 48 changed files with 939 additions and 429 deletions.
1 change: 1 addition & 0 deletions NServiceBus.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
namespace NServiceBus.AcceptanceTests.BasicMessaging
{
using System;
using System.Threading;
using EndpointTemplates;
using AcceptanceTesting;
using NUnit.Framework;

public class When_sending_a_message_that_is_registered_multiple_times_to_another_endpoint : NServiceBusAcceptanceTest
{
[Test]
public void First_registration_should_be_the_final_destination()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<Sender>(b => b.Given((bus, c) => bus.Send(new MyCommand1())))
.WithEndpoint<Receiver1>()
.WithEndpoint<Receiver2>()
.Done(c => c.WasCalled1 || c.WasCalled2)
.Run();

Assert.IsTrue(context.WasCalled1);
Assert.IsFalse(context.WasCalled2);
}

public class Context : ScenarioContext
{
public bool WasCalled1 { get; set; }
public bool WasCalled2 { get; set; }
}

public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
EndpointSetup<DefaultServer>()
.AddMapping<MyCommand1>(typeof(Receiver1))
.AddMapping<MyCommand2>(typeof(Receiver2));
}
}

public class Receiver1 : EndpointConfigurationBuilder
{
public Receiver1()
{
EndpointSetup<DefaultServer>();
}

public class MyMessageHandler : IHandleMessages<MyBaseCommand>
{
public Context Context { get; set; }

public IBus Bus { get; set; }

public void Handle(MyBaseCommand message)
{
Context.WasCalled1 = true;
Thread.Sleep(2000); // Just to be sure the other receiver is finished
}
}
}

public class Receiver2 : EndpointConfigurationBuilder
{
public Receiver2()
{
EndpointSetup<DefaultServer>();
}

public class MyMessageHandler : IHandleMessages<MyBaseCommand>
{
public Context Context { get; set; }

public IBus Bus { get; set; }

public void Handle(MyBaseCommand message)
{
Context.WasCalled2 = true;
Thread.Sleep(2000); // Just to be sure the other receiver is finished
}
}
}

[Serializable]
public abstract class MyBaseCommand : ICommand
{
}

[Serializable]
public class MyCommand1 : MyBaseCommand
{
}

[Serializable]
public class MyCommand2 : MyBaseCommand
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
Configure.Transactions.Disable();
EndpointSetup<DefaultServer>()
.AddMapping<Message>(typeof(Receiver));
EndpointSetup<DefaultServer>(configure =>
{
Configure.Transactions.Disable();
})
.AddMapping<Message>(typeof (Receiver));
}
}

Expand All @@ -44,8 +46,10 @@ public class Receiver : EndpointConfigurationBuilder
public Receiver()
{
SerializerCorrupter.Corrupt();
Configure.Transactions.Disable();
EndpointSetup<DefaultServer>()
EndpointSetup<DefaultServer>(configure =>
{
Configure.Transactions.Disable();
})
.AllowExceptions();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ public class Sender : EndpointConfigurationBuilder
{
public Sender()
{
Configure.Transactions.Advanced(settings => settings.DisableDistributedTransactions());
EndpointSetup<DefaultServer>()
.AddMapping<Message>(typeof(Receiver));
EndpointSetup<DefaultServer>(
configure =>
{
Configure.Transactions.Advanced(settings => settings.DisableDistributedTransactions());
})
.AddMapping<Message>(typeof (Receiver));
}
}

Expand All @@ -43,8 +46,11 @@ public class Receiver : EndpointConfigurationBuilder
public Receiver()
{
SerializerCorrupter.Corrupt();
Configure.Transactions.Advanced(settings => settings.DisableDistributedTransactions());
EndpointSetup<DefaultServer>()
EndpointSetup<DefaultServer>(
configure =>
{
Configure.Transactions.Advanced(settings => settings.DisableDistributedTransactions());
})
.AllowExceptions();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Audit\When_a_message_is_audited.cs" />
<Compile Include="BasicMessaging\When_sending_a_message_that_is_registered_multiple_times_to_another_endpoint.cs" />
<Compile Include="BasicMessaging\When_starting_a_send_only.cs" />
<Compile Include="BasicMessaging\When_registering_a_callback_for_a_local_message.cs" />
<Compile Include="BasicMessaging\When_using_a_custom_correlation_id.cs" />
Expand All @@ -130,8 +131,10 @@
<Compile Include="Performance\NServiceBusPerformanceTest.cs" />
<Compile Include="Performance\Receive\Receive_performance.cs" />
<Compile Include="Performance\Sagas\Saga_performance.cs" />
<Compile Include="PubSub\When_multi_subscribing_to_a_polymorphic_event.cs" />
<Compile Include="PubSub\When_publishing_an_event_with_the_subscriber_scaled_out.cs" />
<Compile Include="PubSub\PubSubAcceptanceTest.cs" />
<Compile Include="PubSub\When_subscribing_to_a_base_event_from_different_publishers.cs" />
<Compile Include="PubSub\When_subscribing_to_a_polymorphic_event.cs" />
<Compile Include="PubSub\When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs" />
<Compile Include="PubSub\When_publishing_an_event.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
namespace NServiceBus.AcceptanceTests.PubSub
{
using System;
using AcceptanceTesting;
using EndpointTemplates;
using Features;
using NUnit.Framework;

public class When_multi_subscribing_to_a_polymorphic_event : NServiceBusAcceptanceTest
{
[Test]
public void Both_events_should_be_delivered()
{
var rootContext = new Context();

Scenario.Define(rootContext)
.WithEndpoint<Publisher1>(b => b.Given((bus, context) => Subscriptions.OnEndpointSubscribed(args =>
{
if (args.MessageType.Contains(typeof(IMyEvent).Name))
{
context.SubscribedToIMyEvent = true;
}
if (args.MessageType.Contains(typeof(MyEvent2).Name))
{
context.SubscribedToMyEvent2 = true;
}
}))
.When(c => c.SubscribedToIMyEvent && c.SubscribedToMyEvent2, bus => bus.Publish(new MyEvent1())))
.WithEndpoint<Publisher2>(b => b.Given((bus, context) => Subscriptions.OnEndpointSubscribed(args =>
{
if (args.MessageType.Contains(typeof(IMyEvent).Name))
{
context.SubscribedToIMyEvent = true;
}
if (args.MessageType.Contains(typeof(MyEvent2).Name))
{
context.SubscribedToMyEvent2 = true;
}
}))
.When(c => c.SubscribedToIMyEvent && c.SubscribedToMyEvent2, bus => bus.Publish(new MyEvent2())))
.WithEndpoint<Subscriber1>(b => b.Given((bus, context) =>
{
bus.Subscribe<IMyEvent>();
bus.Subscribe<MyEvent2>();
}))
.Done(c => c.SubscriberGotIMyEvent && c.SubscriberGotMyEvent2)
.Run();

Assert.True(rootContext.SubscriberGotIMyEvent);
Assert.True(rootContext.SubscriberGotMyEvent2);
}

public class Context : ScenarioContext
{
public bool SubscriberGotIMyEvent { get; set; }
public bool SubscriberGotMyEvent2 { get; set; }
public bool SubscribedToIMyEvent { get; set; }
public bool SubscribedToMyEvent2 { get; set; }
}

public class Publisher1 : EndpointConfigurationBuilder
{
public Publisher1()
{
EndpointSetup<DefaultServer>();
}
}

public class Publisher2 : EndpointConfigurationBuilder
{
public Publisher2()
{
EndpointSetup<DefaultServer>();
}
}

public class Subscriber1 : EndpointConfigurationBuilder
{
public Subscriber1()
{
EndpointSetup<DefaultServer>(c => Configure.Features.Disable<AutoSubscribe>())
.AddMapping<IMyEvent>(typeof(Publisher1))
.AddMapping<MyEvent2>(typeof(Publisher2));
}

public class MyEventHandler : IHandleMessages<IMyEvent>
{
public Context Context { get; set; }

public void Handle(IMyEvent messageThatIsEnlisted)
{
if (messageThatIsEnlisted is MyEvent2)
{
Context.SubscriberGotMyEvent2 = true;
}
else
{
Context.SubscriberGotIMyEvent = true;
}
}
}
}


[Serializable]
public class MyEvent1 : IMyEvent
{
}

[Serializable]
public class MyEvent2 : IMyEvent
{
}

public interface IMyEvent : IEvent
{
}
}
}
Loading

0 comments on commit 3d672bb

Please sign in to comment.