22{
33 using System ;
44 using System . Collections . Concurrent ;
5+ using System . Diagnostics ;
56 using Config ;
67 using EasyNetQ ;
78 using NUnit . Framework ;
@@ -20,7 +21,7 @@ protected void MakeSureQueueAndExchangeExists(string queueName)
2021 //to make sure we kill old subscriptions
2122 DeleteExchange ( queueName ) ;
2223
23- routingTopology . Initialize ( channel , queueName ) ;
24+ routingTopology . Initialize ( channel , queueName ) ;
2425 }
2526 }
2627
@@ -33,14 +34,18 @@ void DeleteExchange(string exchangeName)
3334 {
3435 channel . ExchangeDelete ( exchangeName ) ;
3536 }
36- // ReSharper disable EmptyGeneralCatchClause
37+ // ReSharper disable EmptyGeneralCatchClause
3738 catch ( Exception )
38- // ReSharper restore EmptyGeneralCatchClause
39+ // ReSharper restore EmptyGeneralCatchClause
3940 {
4041 }
4142 }
4243 }
4344
45+ public virtual int MaximumConcurrency
46+ {
47+ get { return 1 ; }
48+ }
4449
4550 [ SetUp ]
4651 public void SetUp ( )
@@ -50,27 +55,39 @@ public void SetUp()
5055
5156 var config = new ConnectionConfiguration ( ) ;
5257 config . ParseHosts ( "localhost:5672" ) ;
53-
58+
5459 var selectionStrategy = new DefaultClusterHostSelectionStrategy < ConnectionFactoryInfo > ( ) ;
5560 var connectionFactory = new ConnectionFactoryWrapper ( config , selectionStrategy ) ;
5661 connectionManager = new RabbitMqConnectionManager ( connectionFactory , config ) ;
5762
58- unitOfWork = new RabbitMqUnitOfWork { ConnectionManager = connectionManager , UsePublisherConfirms = true , MaxWaitTimeForConfirms = TimeSpan . FromSeconds ( 10 ) } ;
63+ unitOfWork = new RabbitMqUnitOfWork
64+ {
65+ ConnectionManager = connectionManager ,
66+ UsePublisherConfirms = true ,
67+ MaxWaitTimeForConfirms = TimeSpan . FromSeconds ( 10 )
68+ } ;
69+
70+ sender = new RabbitMqMessageSender
71+ {
72+ UnitOfWork = unitOfWork ,
73+ RoutingTopology = routingTopology
74+ } ;
5975
60- sender = new RabbitMqMessageSender { UnitOfWork = unitOfWork , RoutingTopology = routingTopology } ;
6176
77+ dequeueStrategy = new RabbitMqDequeueStrategy
78+ {
79+ ConnectionManager = connectionManager ,
80+ PurgeOnStartup = true
81+ } ;
6282
63- dequeueStrategy = new RabbitMqDequeueStrategy { ConnectionManager = connectionManager , PurgeOnStartup = true } ;
64-
6583 MakeSureQueueAndExchangeExists ( ReceiverQueue ) ;
6684
67-
6885
6986 MessagePublisher = new RabbitMqMessagePublisher
70- {
71- UnitOfWork = unitOfWork ,
72- RoutingTopology = routingTopology
73- } ;
87+ {
88+ UnitOfWork = unitOfWork ,
89+ RoutingTopology = routingTopology
90+ } ;
7491 subscriptionManager = new RabbitMqSubscriptionManager
7592 {
7693 ConnectionManager = connectionManager ,
@@ -84,20 +101,22 @@ public void SetUp()
84101 return true ;
85102 } , ( s , exception ) => { } ) ;
86103
87- dequeueStrategy . Start ( 1 ) ;
104+ dequeueStrategy . Start ( MaximumConcurrency ) ;
88105 }
89106
90107
91108 [ TearDown ]
92109 public void TearDown ( )
93110 {
94111 if ( dequeueStrategy != null )
112+ {
95113 dequeueStrategy . Stop ( ) ;
96-
114+ }
115+
97116 connectionManager . Dispose ( ) ;
98117 }
99118
100- protected virtual string ExchangeNameConvention ( Address address , Type eventType )
119+ protected virtual string ExchangeNameConvention ( Address address , Type eventType )
101120 {
102121 return "amq.topic" ;
103122 }
@@ -107,24 +126,25 @@ protected TransportMessage WaitForMessage()
107126 {
108127 var waitTime = TimeSpan . FromSeconds ( 1 ) ;
109128
110- if ( System . Diagnostics . Debugger . IsAttached )
129+ if ( Debugger . IsAttached )
130+ {
111131 waitTime = TimeSpan . FromMinutes ( 10 ) ;
132+ }
112133
113134 TransportMessage message ;
114135 receivedMessages . TryTake ( out message , waitTime ) ;
115136
116137 return message ;
117-
118138 }
119139
140+ protected const string ReceiverQueue = "testreceiver" ;
141+ protected RabbitMqMessagePublisher MessagePublisher ;
142+ protected RabbitMqConnectionManager connectionManager ;
143+ protected RabbitMqDequeueStrategy dequeueStrategy ;
120144 BlockingCollection < TransportMessage > receivedMessages ;
121145
122146 protected ConventionalRoutingTopology routingTopology ;
123- protected const string ReceiverQueue = "testreceiver" ;
124- protected RabbitMqDequeueStrategy dequeueStrategy ;
125- protected RabbitMqConnectionManager connectionManager ;
126147 protected RabbitMqMessageSender sender ;
127- protected RabbitMqMessagePublisher MessagePublisher ;
128148 protected RabbitMqSubscriptionManager subscriptionManager ;
129149 protected RabbitMqUnitOfWork unitOfWork ;
130150 }
0 commit comments