11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4- using System ;
4+ using System . Collections . Generic ;
55using System . Linq ;
66using Xunit ;
77
@@ -52,5 +52,63 @@ public void ParseQueryWithEmptyKeyWorks()
5252 Assert . Equal ( 1 , collection . Count ) ;
5353 Assert . Equal ( new [ ] { "value1" , "" } , collection [ "" ] ) ;
5454 }
55+
56+ [ Theory ]
57+ [ InlineData ( "http://contoso.com/" , "http://contoso.com/?hello=world" ) ]
58+ [ InlineData ( "http://contoso.com/someaction" , "http://contoso.com/someaction?hello=world" ) ]
59+ [ InlineData ( "http://contoso.com/someaction?q=test" , "http://contoso.com/someaction?q=test&hello=world" ) ]
60+ [ InlineData (
61+ "http://contoso.com/someaction?q=test#anchor" ,
62+ "http://contoso.com/someaction?q=test&hello=world#anchor" ) ]
63+ [ InlineData ( "http://contoso.com/someaction#anchor" , "http://contoso.com/someaction?hello=world#anchor" ) ]
64+ [ InlineData ( "http://contoso.com/#anchor" , "http://contoso.com/?hello=world#anchor" ) ]
65+ [ InlineData (
66+ "http://contoso.com/someaction?q=test#anchor?value" ,
67+ "http://contoso.com/someaction?q=test&hello=world#anchor?value" ) ]
68+ [ InlineData (
69+ "http://contoso.com/someaction#anchor?stuff" ,
70+ "http://contoso.com/someaction?hello=world#anchor?stuff" ) ]
71+ [ InlineData (
72+ "http://contoso.com/someaction?name?something" ,
73+ "http://contoso.com/someaction?name?something&hello=world" ) ]
74+ [ InlineData (
75+ "http://contoso.com/someaction#name#something" ,
76+ "http://contoso.com/someaction?hello=world#name#something" ) ]
77+ public void AddQueryStringWithKeyAndValue ( string uri , string expectedUri )
78+ {
79+ var result = QueryHelpers . AddQueryString ( uri , "hello" , "world" ) ;
80+ Assert . Equal ( expectedUri , result ) ;
81+ }
82+
83+ [ Theory ]
84+ [ InlineData ( "http://contoso.com/" , "http://contoso.com/?hello=world&some=text" ) ]
85+ [ InlineData ( "http://contoso.com/someaction" , "http://contoso.com/someaction?hello=world&some=text" ) ]
86+ [ InlineData ( "http://contoso.com/someaction?q=1" , "http://contoso.com/someaction?q=1&hello=world&some=text" ) ]
87+ [ InlineData ( "http://contoso.com/some#action" , "http://contoso.com/some?hello=world&some=text#action" ) ]
88+ [ InlineData ( "http://contoso.com/some?q=1#action" , "http://contoso.com/some?q=1&hello=world&some=text#action" ) ]
89+ [ InlineData ( "http://contoso.com/#action" , "http://contoso.com/?hello=world&some=text#action" ) ]
90+ [ InlineData (
91+ "http://contoso.com/someaction?q=test#anchor?value" ,
92+ "http://contoso.com/someaction?q=test&hello=world&some=text#anchor?value" ) ]
93+ [ InlineData (
94+ "http://contoso.com/someaction#anchor?stuff" ,
95+ "http://contoso.com/someaction?hello=world&some=text#anchor?stuff" ) ]
96+ [ InlineData (
97+ "http://contoso.com/someaction?name?something" ,
98+ "http://contoso.com/someaction?name?something&hello=world&some=text" ) ]
99+ [ InlineData (
100+ "http://contoso.com/someaction#name#something" ,
101+ "http://contoso.com/someaction?hello=world&some=text#name#something" ) ]
102+ public void AddQueryStringWithDictionary ( string uri , string expectedUri )
103+ {
104+ var queryStrings = new Dictionary < string , string > ( )
105+ {
106+ { "hello" , "world" } ,
107+ { "some" , "text" }
108+ } ;
109+
110+ var result = QueryHelpers . AddQueryString ( uri , queryStrings ) ;
111+ Assert . Equal ( expectedUri , result ) ;
112+ }
55113 }
56114}
0 commit comments