-
Notifications
You must be signed in to change notification settings - Fork 115
/
FIeldProblem_Nick.cs
90 lines (76 loc) · 3.36 KB
/
FIeldProblem_Nick.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Messaging;
using System.Threading;
using Castle.MicroKernel;
using Castle.Windsor;
using Rhino.ServiceBus.Castle;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.Messages;
using Rhino.ServiceBus.Msmq;
using Rhino.ServiceBus.Serializers;
using Xunit;
namespace Rhino.ServiceBus.Tests.Bugs
{
public static class SubscriptionTest
{
public static void Test(ITransport t, IQueueStrategy strategy,
Endpoint queueEndpoint, Action<Message> send, Func<MessageEnumerator>
enumer)
{
Guid id = Guid.NewGuid();
var serializer = new XmlMessageSerializer(new DefaultReflection(),
new CastleServiceLocator(new WindsorContainer()));
var subscriptionStorage = new MsmqSubscriptionStorage(new
DefaultReflection(),
serializer,
queueEndpoint.Uri,
new
EndpointRouter(),
strategy);
subscriptionStorage.Initialize();
var wait = new ManualResetEvent(false);
subscriptionStorage.SubscriptionChanged += () => wait.Set();
t.AdministrativeMessageArrived +=
subscriptionStorage.HandleAdministrativeMessage;
Message msg = new MsmqMessageBuilder
(serializer, new CastleServiceLocator(new WindsorContainer())).BuildFromMessageBatch(
new OutgoingMessageInformation
{
Messages = new[] { new AddInstanceSubscription
{
Endpoint = queueEndpoint.Uri.ToString(),
InstanceSubscriptionKey = id,
Type = typeof (TestMessage2).FullName,
}}
});
send(msg);
wait.WaitOne();
msg = new MsmqMessageBuilder
(serializer, new CastleServiceLocator(new WindsorContainer())).BuildFromMessageBatch(new OutgoingMessageInformation
{
Messages = new[] { new RemoveInstanceSubscription
{
Endpoint = queueEndpoint.Uri.ToString(),
InstanceSubscriptionKey = id,
Type = typeof (TestMessage2).FullName,
}}
});
wait.Reset();
send(msg);
wait.WaitOne();
IEnumerable<Uri> uris = subscriptionStorage
.GetSubscriptionsFor(typeof (TestMessage2));
Assert.Equal(0, uris.Count());
int count = 0;
MessageEnumerator copy = enumer();
while (copy.MoveNext()) count++;
Assert.Equal(0, count);
}
}
public class TestMessage2
{
}
}