@@ -66,5 +66,68 @@ public void GetDisplayUrlFromRequest()
66
66
67
67
Assert . Equal ( "http://my.hoψst:80/un?escaped/base/un?escaped?name=val%23ue" , request . GetDisplayUrl ( ) ) ;
68
68
}
69
+
70
+ [ Theory ]
71
+ [ InlineData ( "http://example.com" , "http" , "example.com" , "" , "" , "" ) ]
72
+ [ InlineData ( "https://example.com" , "https" , "example.com" , "" , "" , "" ) ]
73
+ [ InlineData ( "http://example.com/foo/bar" , "http" , "example.com" , "/foo/bar" , "" , "" ) ]
74
+ [ InlineData ( "http://example.com/foo/bar?baz=1" , "http" , "example.com" , "/foo/bar" , "?baz=1" , "" ) ]
75
+ [ InlineData ( "http://example.com/foo#col=2" , "http" , "example.com" , "/foo" , "" , "#col=2" ) ]
76
+ [ InlineData ( "http://example.com/foo?bar=1#col=2" , "http" , "example.com" , "/foo" , "?bar=1" , "#col=2" ) ]
77
+ [ InlineData ( "http://example.com?bar=1#col=2" , "http" , "example.com" , "" , "?bar=1" , "#col=2" ) ]
78
+ [ InlineData ( "http://example.com#frag?stillfrag/stillfrag" , "http" , "example.com" , "" , "" , "#frag?stillfrag/stillfrag" ) ]
79
+ [ InlineData ( "http://example.com?q/stillq#frag?stillfrag/stillfrag" , "http" , "example.com" , "" , "?q/stillq" , "#frag?stillfrag/stillfrag" ) ]
80
+ [ InlineData ( "http://example.com/fo%23o#col=2" , "http" , "example.com" , "/fo#o" , "" , "#col=2" ) ]
81
+ [ InlineData ( "http://example.com/fo%3Fo#col=2" , "http" , "example.com" , "/fo?o" , "" , "#col=2" ) ]
82
+ [ InlineData ( "ftp://example.com/" , "ftp" , "example.com" , "/" , "" , "" ) ]
83
+ [ InlineData ( "https://127.0.0.0:80/bar" , "https" , "127.0.0.0:80" , "/bar" , "" , "" ) ]
84
+ [ InlineData ( "http://[1080:0:0:0:8:800:200C:417A]/index.html" , "http" , "[1080:0:0:0:8:800:200C:417A]" , "/index.html" , "" , "" ) ]
85
+ [ InlineData ( "http://example.com///" , "http" , "example.com" , "///" , "" , "" ) ]
86
+ [ InlineData ( "http://example.com///" , "http" , "example.com" , "///" , "" , "" ) ]
87
+ public void FromAbsoluteUriParsingChecks (
88
+ string uri ,
89
+ string expectedScheme ,
90
+ string expectedHost ,
91
+ string expectedPath ,
92
+ string expectedQuery ,
93
+ string expectedFragment )
94
+ {
95
+ string scheme = null ;
96
+ var host = new HostString ( ) ;
97
+ var path = new PathString ( ) ;
98
+ var query = new QueryString ( ) ;
99
+ var fragment = new FragmentString ( ) ;
100
+ UriHelper . FromAbsolute ( uri , out scheme , out host , out path , out query , out fragment ) ;
101
+
102
+ Assert . Equal ( scheme , expectedScheme ) ;
103
+ Assert . Equal ( host , new HostString ( expectedHost ) ) ;
104
+ Assert . Equal ( path , new PathString ( expectedPath ) ) ;
105
+ Assert . Equal ( query , new QueryString ( expectedQuery ) ) ;
106
+ Assert . Equal ( fragment , new FragmentString ( expectedFragment ) ) ;
107
+ }
108
+
109
+ [ Fact ]
110
+ public void FromAbsoluteToBuildAbsolute ( )
111
+ {
112
+ var scheme = "http" ;
113
+ var host = new HostString ( "example.com" ) ;
114
+ var path = new PathString ( "/index.html" ) ;
115
+ var query = new QueryString ( "?foo=1" ) ;
116
+ var fragment = new FragmentString ( "#col=1" ) ;
117
+ var request = UriHelper . BuildAbsolute ( scheme , host , path : path , query : query , fragment : fragment ) ;
118
+
119
+ string resScheme = null ;
120
+ var resHost = new HostString ( ) ;
121
+ var resPath = new PathString ( ) ;
122
+ var resQuery = new QueryString ( ) ;
123
+ var resFragment = new FragmentString ( ) ;
124
+ UriHelper . FromAbsolute ( request , out resScheme , out resHost , out resPath , out resQuery , out resFragment ) ;
125
+
126
+ Assert . Equal ( scheme , resScheme ) ;
127
+ Assert . Equal ( host , resHost ) ;
128
+ Assert . Equal ( path , resPath ) ;
129
+ Assert . Equal ( query , resQuery ) ;
130
+ Assert . Equal ( fragment , resFragment ) ;
131
+ }
69
132
}
70
133
}
0 commit comments