/
When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs
94 lines (82 loc) · 3.2 KB
/
When_publishing_an_event_using_a_broker_transport_with_centralized_routing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
namespace NServiceBus.AcceptanceTests.PubSub
{
using System;
using EndpointTemplates;
using AcceptanceTesting;
using NUnit.Framework;
using ScenarioDescriptors;
public class When_publishing_an_event_using_a_broker_transport_with_centralized_routing : NServiceBusAcceptanceTest
{
[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<Context>()
.WithEndpoint<CentralizedPublisher>
(b => b.When(c => c.IsSubscriptionProcessedForSub1 && c.IsSubscriptionProcessedForSub2, bus => bus.Publish(new MyEvent())))
.WithEndpoint<CentralizedSubscriber1>(b => b.Given((bus, context) =>
{
context.IsSubscriptionProcessedForSub1 = true;
}))
.WithEndpoint<CentralizedSubscriber2>(b => b.Given((bus, context) =>
{
context.IsSubscriptionProcessedForSub2 = true;
}))
.Done(c => c.Subscriber1GotTheEvent && c.Subscriber2GotTheEvent)
.Repeat(r => r.For<AllTransportsWithCentralizedPubSubSupport>())
.Should(c =>
{
Assert.True(c.Subscriber1GotTheEvent);
Assert.True(c.Subscriber2GotTheEvent);
})
.Run();
}
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
{
public CentralizedPublisher()
{
EndpointSetup<DefaultServer>();
}
}
public class CentralizedSubscriber1 : EndpointConfigurationBuilder
{
public CentralizedSubscriber1()
{
EndpointSetup<DefaultServer>();
}
public class MyEventHandler : IHandleMessages<MyEvent>
{
public Context Context { get; set; }
public void Handle(MyEvent messageThatIsEnlisted)
{
Context.Subscriber1GotTheEvent = true;
}
}
}
public class CentralizedSubscriber2 : EndpointConfigurationBuilder
{
public CentralizedSubscriber2()
{
EndpointSetup<DefaultServer>();
}
public class MyEventHandler : IHandleMessages<MyEvent>
{
public Context Context { get; set; }
public void Handle(MyEvent messageThatIsEnlisted)
{
Context.Subscriber2GotTheEvent = true;
}
}
}
[Serializable]
public class MyEvent : IEvent
{
}
}
}