@@ -29,19 +29,28 @@ namespace MongoDB.DriverUnitTests
29
29
public class MongoServerAddressTests
30
30
{
31
31
[ Test ]
32
- public void TestCreateWithHost ( )
32
+ [ TestCase ( "host" ) ]
33
+ [ TestCase ( "192.168.0.1" ) ]
34
+ [ TestCase ( "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]" ) ]
35
+ public void TestConstructor ( string host )
33
36
{
34
- var credentials = new MongoServerAddress ( " host" ) ;
35
- Assert . AreEqual ( " host" , credentials . Host ) ;
36
- Assert . AreEqual ( 27017 , credentials . Port ) ;
37
+ var address = new MongoServerAddress ( host ) ;
38
+ Assert . AreEqual ( host , address . Host ) ;
39
+ Assert . AreEqual ( 27017 , address . Port ) ;
37
40
}
38
41
39
42
[ Test ]
40
- public void TestCreateWithHostAndPort ( )
43
+ [ TestCase ( "host" , 27017 ) ]
44
+ [ TestCase ( "host" , 27018 ) ]
45
+ [ TestCase ( "192.168.0.1" , 27017 ) ]
46
+ [ TestCase ( "192.168.0.1" , 27018 ) ]
47
+ [ TestCase ( "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]" , 27017 ) ]
48
+ [ TestCase ( "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]" , 27018 ) ]
49
+ public void TestConstructor ( string host , int port )
41
50
{
42
- var credentials = new MongoServerAddress ( " host" , 123 ) ;
43
- Assert . AreEqual ( " host" , credentials . Host ) ;
44
- Assert . AreEqual ( 123 , credentials . Port ) ;
51
+ var address = new MongoServerAddress ( host , port ) ;
52
+ Assert . AreEqual ( host , address . Host ) ;
53
+ Assert . AreEqual ( port , address . Port ) ;
45
54
}
46
55
47
56
[ Test ]
@@ -73,35 +82,35 @@ public void TestEquals()
73
82
}
74
83
75
84
[ Test ]
76
- public void TestParseWithHost ( )
85
+ [ TestCase ( "host" , 27017 , "host" ) ]
86
+ [ TestCase ( "host" , 27017 , "host:27017" ) ]
87
+ [ TestCase ( "host" , 27018 , "host:27018" ) ]
88
+ [ TestCase ( "192.168.0.1" , 27017 , "192.168.0.1" ) ]
89
+ [ TestCase ( "192.168.0.1" , 27017 , "192.168.0.1:27017" ) ]
90
+ [ TestCase ( "192.168.0.1" , 27018 , "192.168.0.1:27018" ) ]
91
+ [ TestCase ( "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]" , 27017 , "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]" ) ]
92
+ [ TestCase ( "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]" , 27017 , "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]:27017" ) ]
93
+ [ TestCase ( "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]" , 27018 , "[2001:0db8:85a3:0042:0000:8a2e:0370:7334]:27018" ) ]
94
+ public void TestParse ( string host , int port , string value )
77
95
{
78
- var credentials = MongoServerAddress . Parse ( "host" ) ;
79
- Assert . AreEqual ( " host" , credentials . Host ) ;
80
- Assert . AreEqual ( 27017 , credentials . Port ) ;
96
+ var address = MongoServerAddress . Parse ( value ) ;
97
+ Assert . AreEqual ( host , address . Host ) ;
98
+ Assert . AreEqual ( port , address . Port ) ;
81
99
}
82
100
83
101
[ Test ]
84
- public void TestParseWithHostAndPort ( )
102
+ [ TestCase ( null ) ]
103
+ [ TestCase ( "" ) ]
104
+ [ TestCase ( "abc:def" ) ]
105
+ [ TestCase ( "abc:123:456" ) ]
106
+ [ TestCase ( "[]" ) ]
107
+ [ TestCase ( "a[]" ) ]
108
+ [ TestCase ( "[]b" ) ]
109
+ [ TestCase ( "a[]b" ) ]
110
+ public void TestParse_InvalidValue ( string value )
85
111
{
86
- var credentials = MongoServerAddress . Parse ( "host:123" ) ;
87
- Assert . AreEqual ( "host" , credentials . Host ) ;
88
- Assert . AreEqual ( 123 , credentials . Port ) ;
89
- }
90
-
91
- [ Test ]
92
- [ ExpectedException ( ExpectedException = typeof ( FormatException ) ,
93
- ExpectedMessage = "'' is not a valid server address." ) ]
94
- public void TestParseNullParam ( )
95
- {
96
- MongoServerAddress . Parse ( null ) ;
97
- }
98
-
99
- [ Test ]
100
- [ ExpectedException ( ExpectedException = typeof ( FormatException ) ,
101
- ExpectedMessage = "'' is not a valid server address." ) ]
102
- public void TestParseEmptyParam ( )
103
- {
104
- MongoServerAddress . Parse ( String . Empty ) ;
112
+ var message = string . Format ( "'{0}' is not a valid server address." , value ) ;
113
+ Assert . Throws < FormatException > ( ( ) => { var address = MongoServerAddress . Parse ( value ) ; } , message ) ;
105
114
}
106
115
}
107
116
}
0 commit comments