@@ -272,6 +272,92 @@ public void OnlySpecialCharactersShouldReturnOnlySpecialCharacters(string? value
272272 //Assert
273273 result . Should ( ) . Be ( expected ) ;
274274 }
275+
276+ [ Theory ]
277+ [ InlineData ( null ) ]
278+ [ InlineData ( "" ) ]
279+ [ InlineData ( "not a valid url" ) ]
280+ [ InlineData ( "?" ) ]
281+ public void ParseQueryString_ShouldReturnEmptyListWhenNotAValidInput ( string ? value )
282+ {
283+ var result = value . ParseQueryString ( ) ;
284+
285+ result . Should ( ) . BeEmpty ( ) ;
286+ }
287+
288+ [ Theory ]
289+ [ InlineData ( "http://yoursite.com?variable1=false" , "variable1" , false ) ]
290+ [ InlineData ( "http://yoursite.com?variable1=False" , "variable1" , false ) ]
291+ [ InlineData ( "http://yoursite.com?variable1=1" , "variable1" , 1 ) ]
292+ [ InlineData ( "http://yoursite.com?variable1=19.86" , "variable1" , 19.86 ) ]
293+ [ InlineData ( "?variable1=true" , "variable1" , true ) ]
294+ [ InlineData ( "?variable1=True" , "variable1" , true ) ]
295+ [ InlineData ( "?variable1=1" , "variable1" , 1 ) ]
296+ [ InlineData ( "?variable1=0.77" , "variable1" , 0.77 ) ]
297+ [ InlineData ( "?variable1=test" , "variable1" , "test" ) ]
298+ public void ParseQueryString_ConvertType_ShouldReturnListOfKeyValues ( string ? value , string expectedKey , object expectedValue )
299+ {
300+ var result = value . ParseQueryString ( autoConvertType : true ) ;
301+
302+ result . Should ( ) . NotBeEmpty ( ) ;
303+ result . Should ( ) . HaveCount ( 1 ) ;
304+ result . First ( ) . Key . Should ( ) . Be ( expectedKey ) ;
305+ result . First ( ) . Value . Should ( ) . Be ( expectedValue ) ;
306+ result . First ( ) . Value . Should ( ) . BeOfType ( expectedValue . GetType ( ) ) ;
307+ }
308+
309+ [ Theory ]
310+ [ InlineData ( "http://yoursite.com?variable1=false" , "variable1" , "false" ) ]
311+ [ InlineData ( "http://yoursite.com?variable1=False" , "variable1" , "False" ) ]
312+ [ InlineData ( "http://yoursite.com?variable1=1" , "variable1" , "1" ) ]
313+ [ InlineData ( "http://yoursite.com?variable1=19.86" , "variable1" , "19.86" ) ]
314+ [ InlineData ( "?variable1=true" , "variable1" , "true" ) ]
315+ [ InlineData ( "?variable1=True" , "variable1" , "True" ) ]
316+ [ InlineData ( "?variable1=1" , "variable1" , "1" ) ]
317+ [ InlineData ( "?variable1=0.77" , "variable1" , "0.77" ) ]
318+ [ InlineData ( "?variable1=test" , "variable1" , "test" ) ]
319+ public void ParseQueryString_WithoutConversion_ShouldReturnListOfKeyValues ( string ? value , string expectedKey , string expectedValue )
320+ {
321+ var result = value . ParseQueryString ( autoConvertType : false ) ;
322+
323+ result . Should ( ) . NotBeEmpty ( ) ;
324+ result . Should ( ) . HaveCount ( 1 ) ;
325+ result . First ( ) . Key . Should ( ) . Be ( expectedKey ) ;
326+ result . First ( ) . Value . Should ( ) . Be ( expectedValue ) ;
327+ result . First ( ) . Value . Should ( ) . BeOfType < string > ( ) ;
328+ }
329+
330+ [ Theory ]
331+ [ InlineData ( "?variable1=15&variable2=is that a question?&variable3=true&variable4=33.88&variable5=" , "variable1=15|variable2=is that a question?|variable3=true|variable4=33.88|variable5=" ) ]
332+ public void ParseQueryString_ShouldReturnListOfKeyValues ( string ? value , string expectedPipedString )
333+ {
334+ var result = value . ParseQueryString ( autoConvertType : false ) ;
335+
336+ var expected = expectedPipedString
337+ . Split ( '|' , StringSplitOptions . RemoveEmptyEntries )
338+ . Select ( s => s . Split ( '=' ) )
339+ . ToDictionary ( k => k [ 0 ] , v => v [ 1 ] ) ;
340+
341+ result . Should ( ) . NotBeEmpty ( ) ;
342+ result . Should ( ) . BeEquivalentTo ( expected ) ;
343+ }
344+
345+ [ Theory ]
346+ [ InlineData ( "?not a valid url" , "not a valid url=" ) ]
347+ [ InlineData ( "?not a valid url&&&&&" , "not a valid url=" ) ]
348+ [ InlineData ( "?not a valid url&&&&&=value" , "not a valid url=|=value" ) ]
349+ public void ParseQueryString_EdgeCasesShouldReturnListOfKeyValues ( string ? value , string expectedPipedString )
350+ {
351+ var result = value . ParseQueryString ( autoConvertType : false ) ;
352+
353+ var expected = expectedPipedString
354+ . Split ( '|' )
355+ . Select ( s => s . Split ( '=' ) )
356+ . ToDictionary ( k => k . Length > 0 ? k [ 0 ] : string . Empty , v => v . Length > 1 ? v [ 1 ] : string . Empty ) ;
357+
358+ result . Should ( ) . NotBeEmpty ( ) ;
359+ result . Should ( ) . BeEquivalentTo ( expected ) ;
360+ }
275361}
276362
277363public enum FakeEnum
0 commit comments