@@ -11,17 +11,73 @@ namespace EasyNetQ.Tests.ConnectionString
11
11
{
12
12
public class ConnectionStringParserTests
13
13
{
14
- private ConnectionStringParser connectionStringParser ;
14
+ public ConnectionStringParserTests ( )
15
+ {
16
+ connectionStringParser = new ConnectionStringParser ( ) ;
17
+ }
18
+
19
+ private readonly ConnectionStringParser connectionStringParser ;
15
20
16
21
private const string connectionString =
17
22
"virtualHost=Copa;username=Copa;host=192.168.1.1;password=abc_xyz;port=12345;" +
18
23
"requestedHeartbeat=3;prefetchcount=2;timeout=12;publisherConfirms=true;" +
19
24
"useBackgroundThreads=true;" +
20
25
"name=unit-test" ;
21
26
22
- public ConnectionStringParserTests ( )
27
+ [ Theory ]
28
+ [ MemberData ( nameof ( AppendixAExamples ) ) ]
29
+ public void Should_parse_Examples ( AmqpSpecification spec )
23
30
{
24
- connectionStringParser = new ConnectionStringParser ( ) ;
31
+ var connectionConfiguration = connectionStringParser . Parse ( spec . amqpUri . ToString ( ) ) ;
32
+
33
+ connectionConfiguration . Port . Should ( ) . Be ( ( ushort ) spec . port ) ;
34
+ connectionConfiguration . AMQPConnectionString . Should ( ) . Be ( spec . amqpUri ) ;
35
+ connectionConfiguration . Hosts . First ( ) . Host . Should ( ) . Be ( spec . host ) ;
36
+ connectionConfiguration . Hosts . First ( ) . Port . Should ( ) . Be ( ( ushort ) spec . port ) ;
37
+ connectionConfiguration . VirtualHost . Should ( ) . Be ( spec . vhost ) ;
38
+ }
39
+
40
+ // ReSharper disable UnusedMethodReturnValue.Local
41
+ public static IEnumerable < object [ ] > AppendixAExamples ( )
42
+ // ReSharper restore UnusedMethodReturnValue.Local
43
+ {
44
+ yield return new [ ] { new AmqpSpecification ( new Uri ( "amqp://user:pass@host:10000/vhost" ) , "host" , 10000 , "vhost" ) } ;
45
+ yield return new [ ] { new AmqpSpecification ( new Uri ( "amqp://" ) , "" , 5672 , "/" ) } ;
46
+ yield return new [ ] { new AmqpSpecification ( new Uri ( "amqp://host" ) , "host" , 5672 , "/" ) } ;
47
+ yield return new [ ] { new AmqpSpecification ( new Uri ( "amqps://host" ) , "host" , 5671 , "/" ) } ;
48
+ }
49
+
50
+ public class AmqpSpecification
51
+ {
52
+ public readonly Uri amqpUri ;
53
+ public readonly string host ;
54
+
55
+ public readonly int port ;
56
+
57
+ public readonly string vhost ;
58
+
59
+ public AmqpSpecification ( Uri amqpUri , string host , int port , string vhost )
60
+ {
61
+ this . host = host ;
62
+ this . port = port ;
63
+ this . vhost = vhost ;
64
+ this . amqpUri = amqpUri ;
65
+ }
66
+
67
+ public override string ToString ( )
68
+ {
69
+ return string . Format ( "AmqpUri: {0}" , amqpUri ) ;
70
+ }
71
+ }
72
+
73
+ [ Fact ]
74
+ public void Should_AddHost_ToHosts ( )
75
+ {
76
+ var connectionConfiguration = connectionStringParser . Parse ( "host=local;amqp=amqp://amqphost:1234/" ) ;
77
+
78
+ connectionConfiguration . Hosts . Count ( ) . Should ( ) . Be ( 2 ) ;
79
+ connectionConfiguration . Hosts . First ( ) . Host . Should ( ) . Be ( "local" ) ;
80
+ connectionConfiguration . Hosts . Last ( ) . Host . Should ( ) . Be ( "amqphost" ) ;
25
81
}
26
82
27
83
[ Fact ]
@@ -33,22 +89,21 @@ public void Should_correctly_parse_connection_string()
33
89
connectionConfiguration . VirtualHost . Should ( ) . Be ( "Copa" ) ;
34
90
connectionConfiguration . UserName . Should ( ) . Be ( "Copa" ) ;
35
91
connectionConfiguration . Password . Should ( ) . Be ( "abc_xyz" ) ;
36
- connectionConfiguration . Port . Should ( ) . Be ( ( ushort ) 12345 ) ;
37
- connectionConfiguration . RequestedHeartbeat . Should ( ) . Be ( ( ushort ) 3 ) ;
38
- connectionConfiguration . PrefetchCount . Should ( ) . Be ( ( ushort ) 2 ) ;
39
- connectionConfiguration . Timeout . Should ( ) . Be ( ( ushort ) 12 ) ;
92
+ connectionConfiguration . Port . Should ( ) . Be ( 12345 ) ;
93
+ connectionConfiguration . RequestedHeartbeat . Should ( ) . Be ( 3 ) ;
94
+ connectionConfiguration . PrefetchCount . Should ( ) . Be ( 2 ) ;
95
+ connectionConfiguration . Timeout . Should ( ) . Be ( 12 ) ;
40
96
connectionConfiguration . PublisherConfirms . Should ( ) . BeTrue ( ) ;
41
97
connectionConfiguration . UseBackgroundThreads . Should ( ) . BeTrue ( ) ;
42
98
connectionConfiguration . Name . Should ( ) . Be ( "unit-test" ) ;
43
99
}
44
100
45
101
[ Fact ]
46
- public void Should_parse_global_timeout ( )
102
+ public void Should_NotUsePort_From_ConnectionString ( )
47
103
{
48
- const string connectionStringWithTimeout = "host=localhost;timeout=13" ;
49
- var connectionConfiguration = connectionStringParser . Parse ( connectionStringWithTimeout ) ;
104
+ var connectionConfiguration = connectionStringParser . Parse ( "amqp=amqp://host:1234/" ) ;
50
105
51
- connectionConfiguration . Timeout . Should ( ) . Be ( 13 ) ;
106
+ connectionConfiguration . Port . Should ( ) . Be ( 1234 ) ;
52
107
}
53
108
54
109
[ Fact ]
@@ -61,9 +116,12 @@ public void Should_parse_global_persistentMessages()
61
116
}
62
117
63
118
[ Fact ]
64
- public void Should_Throw_Exception_OnInvalidAmqp ( )
119
+ public void Should_parse_global_timeout ( )
65
120
{
66
- Assert . Throws < EasyNetQException > ( ( ) => connectionStringParser . Parse ( "amqp=Foo" ) ) ;
121
+ const string connectionStringWithTimeout = "host=localhost;timeout=13" ;
122
+ var connectionConfiguration = connectionStringParser . Parse ( connectionStringWithTimeout ) ;
123
+
124
+ connectionConfiguration . Timeout . Should ( ) . Be ( 13 ) ;
67
125
}
68
126
69
127
[ Fact ]
@@ -78,27 +136,10 @@ public void Should_throw_exception_for_unknown_key_at_the_end()
78
136
Assert . Throws < EasyNetQException > ( ( ) => connectionStringParser . Parse ( "host=localhost;unknownKey=true" ) ) ;
79
137
}
80
138
81
- [ Theory ]
82
- [ MemberData ( nameof ( AppendixAExamples ) ) ]
83
- public void Should_parse_Examples ( AmqpSpecification spec )
84
- {
85
- var connectionConfiguration = connectionStringParser . Parse ( spec . amqpUri . ToString ( ) ) ;
86
-
87
- connectionConfiguration . Port . Should ( ) . Be ( ( ushort ) spec . port ) ;
88
- connectionConfiguration . AMQPConnectionString . Should ( ) . Be ( spec . amqpUri ) ;
89
- connectionConfiguration . Hosts . First ( ) . Host . Should ( ) . Be ( spec . host ) ;
90
- connectionConfiguration . Hosts . First ( ) . Port . Should ( ) . Be ( ( ushort ) spec . port ) ;
91
- connectionConfiguration . VirtualHost . Should ( ) . Be ( spec . vhost ) ;
92
- }
93
-
94
- // ReSharper disable UnusedMethodReturnValue.Local
95
- public static IEnumerable < object [ ] > AppendixAExamples ( )
96
- // ReSharper restore UnusedMethodReturnValue.Local
139
+ [ Fact ]
140
+ public void Should_Throw_Exception_OnInvalidAmqp ( )
97
141
{
98
- yield return new [ ] { new AmqpSpecification ( new Uri ( "amqp://user:pass@host:10000/vhost" ) , "host" , 10000 , "vhost" ) } ;
99
- yield return new [ ] { new AmqpSpecification ( new Uri ( "amqp://" ) , "" , 5672 , "/" ) } ;
100
- yield return new [ ] { new AmqpSpecification ( new Uri ( "amqp://host" ) , "host" , 5672 , "/" ) } ;
101
- yield return new [ ] { new AmqpSpecification ( new Uri ( "amqps://host" ) , "host" , 5671 , "/" ) } ;
142
+ Assert . Throws < EasyNetQException > ( ( ) => connectionStringParser . Parse ( "amqp=Foo" ) ) ;
102
143
}
103
144
104
145
[ Fact ]
@@ -108,49 +149,7 @@ public void Should_UsePort_From_ConnectionString()
108
149
109
150
connectionConfiguration . Port . Should ( ) . Be ( 123 ) ;
110
151
}
111
-
112
- [ Fact ]
113
- public void Should_NotUsePort_From_ConnectionString ( )
114
- {
115
- var connectionConfiguration = connectionStringParser . Parse ( "amqp=amqp://host:1234/" ) ;
116
-
117
- connectionConfiguration . Port . Should ( ) . Be ( 1234 ) ;
118
- }
119
-
120
- [ Fact ]
121
- public void Should_AddHost_ToHosts ( )
122
- {
123
- var connectionConfiguration = connectionStringParser . Parse ( "host=local;amqp=amqp://amqphost:1234/" ) ;
124
-
125
- connectionConfiguration . Hosts . Count ( ) . Should ( ) . Be ( 2 ) ;
126
- connectionConfiguration . Hosts . First ( ) . Host . Should ( ) . Be ( "local" ) ;
127
- connectionConfiguration . Hosts . Last ( ) . Host . Should ( ) . Be ( "amqphost" ) ;
128
- }
129
-
130
- public class AmqpSpecification
131
- {
132
- public readonly string host ;
133
-
134
- public readonly int port ;
135
-
136
- public readonly Uri amqpUri ;
137
-
138
- public readonly string vhost ;
139
-
140
- public AmqpSpecification ( Uri amqpUri , string host , int port , string vhost )
141
- {
142
- this . host = host ;
143
- this . port = port ;
144
- this . vhost = vhost ;
145
- this . amqpUri = amqpUri ;
146
- }
147
-
148
- public override string ToString ( )
149
- {
150
- return string . Format ( "AmqpUri: {0}" , amqpUri ) ;
151
- }
152
- }
153
152
}
154
153
}
155
154
156
- // ReSharper restore InconsistentNaming
155
+ // ReSharper restore InconsistentNaming
0 commit comments