1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Runtime . InteropServices ;
4
5
using System . Text ;
5
6
using Xunit ;
6
7
using System . Globalization ;
8
+ using Xunit . Extensions ;
7
9
8
10
namespace RestSharp . Tests {
9
11
public class RestRequestTests {
@@ -17,5 +19,56 @@ public void Can_Add_Object_With_IntegerArray_property() {
17
19
var request = new RestRequest ( ) ;
18
20
request . AddObject ( new { Items = new int [ ] { 2 , 3 , 4 } } ) ;
19
21
}
22
+
23
+ [ Fact ]
24
+ public void Cannot_Set_Empty_Host_Header ( )
25
+ {
26
+ var request = new RestRequest ( ) ;
27
+
28
+ var exception = Assert . Throws < ArgumentException > ( ( ) => request . AddHeader ( "Host" , string . Empty ) ) ;
29
+ Assert . Equal ( "value" , exception . ParamName ) ;
30
+ }
31
+
32
+ [ Theory ]
33
+ [ InlineData ( "http://localhost" ) ]
34
+ [ InlineData ( "hostname 1234" ) ]
35
+ [ InlineData ( "-leading.hyphen.not.allowed" ) ]
36
+ [ InlineData ( "bad:port" ) ]
37
+ [ InlineData ( " no.leading.white-space" ) ]
38
+ [ InlineData ( "no.trailing.white-space " ) ]
39
+ [ InlineData ( ".leading.dot.not.allowed" ) ]
40
+ [ InlineData ( "double.dots..not.allowed" ) ]
41
+ [ InlineData ( "." ) ]
42
+ [ InlineData ( ".:2345" ) ]
43
+ [ InlineData ( ":5678" ) ]
44
+ [ InlineData ( "" ) ]
45
+ [ InlineData ( "foo:bar:baz" ) ]
46
+ public void Cannot_Set_Invalid_Host_Header ( string value )
47
+ {
48
+ var request = new RestRequest ( ) ;
49
+
50
+ var exception = Assert . Throws < ArgumentException > ( ( ) => request . AddHeader ( "Host" , value ) ) ;
51
+ Assert . Equal ( "value" , exception . ParamName ) ;
52
+ }
53
+
54
+ [ Theory ]
55
+ [ InlineData ( "localhost" ) ]
56
+ [ InlineData ( "localhost:1234" ) ]
57
+ [ InlineData ( "host.local" ) ]
58
+ [ InlineData ( "anotherhost.local:2345" ) ]
59
+ [ InlineData ( "www.w3.org" ) ]
60
+ [ InlineData ( "www.w3.org:3456" ) ]
61
+ [ InlineData ( "8.8.8.8" ) ]
62
+ [ InlineData ( "a.1.b.2" ) ]
63
+ [ InlineData ( "10.20.30.40:1234" ) ]
64
+ [ InlineData ( "0host" ) ]
65
+ [ InlineData ( "hypenated-hostname" ) ]
66
+ [ InlineData ( "multi--hyphens" ) ]
67
+ public void Can_Set_Valid_Host_Header ( string value )
68
+ {
69
+ var request = new RestRequest ( ) ;
70
+
71
+ Assert . DoesNotThrow ( ( ) => request . AddHeader ( "Host" , value ) ) ;
72
+ }
20
73
}
21
74
}
0 commit comments