private void AddTest(Uri internalUri, string expectedExternalValue, QueryStringDictionaryTest queryStringDictionary) { internalUris.Add(internalUri); expectedExternalValues.Add(expectedExternalValue); expectedQueryStringDictionaries.Add(queryStringDictionary); }
public UriParsingHelperTests() { // QS dictionaries that are used in many tests var emptyQS = new QueryStringDictionaryTest() { Count = 0 }; var id123QS = new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "id" }, Values = new string[] { "123" } }; var id123SortAscQS = new QueryStringDictionaryTest() { Count = 2, Keys = new string[] { "id", "sort" }, Values = new string[] { "123", "asc" } }; var idEmptyQS = new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "id" }, Values = new string[] { String.Empty } }; var idEmptySortAscQS = new QueryStringDictionaryTest() { Count = 2, Keys = new string[] { "id", "sort" }, Values = new string[] { String.Empty, "asc" } }; AddTest(RelativeUri("Page1.xaml"), "Page1.xaml", emptyQS); AddTest(RelativeUri("Page1.xaml?id=123"), // 1, query string only "Page1.xaml?id=123", id123QS); AddTest(RelativeUri("Page1.xaml#fragment1"), // 2, fragment only "Page1.xaml$fragment1", emptyQS); AddTest(RelativeUri("Page1.xaml?id=123#fragment1"), // 3, query string + fragment "Page1.xaml?id=123$fragment1", id123QS); AddTest(RelativeUri("Page1.xaml?id=123&sort=asc"), // 4, query string with multiple values "Page1.xaml?id=123&sort=asc", id123SortAscQS); AddTest(RelativeUri("Page1.xaml?id=123&sort=asc#fragment1"), // 5, query string with multiple values + fragment "Page1.xaml?id=123&sort=asc$fragment1", id123SortAscQS); AddTest(RelativeUri("Page1.xaml?id="), // 6, query string with empty value "Page1.xaml?id=", idEmptyQS); AddTest(RelativeUri("Page1.xaml?id=#fragment1"), // 7, query string with empty value + fragment "Page1.xaml?id=$fragment1", idEmptyQS); AddTest(RelativeUri("Page1.xaml?id=&sort=asc"), // 8, query string with empty value + multiple values "Page1.xaml?id=&sort=asc", idEmptySortAscQS); AddTest(RelativeUri("Page1.xaml?id=&sort=asc#fragment1"), // 9, query string with empty value + multiple values + fragment "Page1.xaml?id=&sort=asc$fragment1", idEmptySortAscQS); AddTest(RelativeUri("/Views/Page1.xaml"), // 10, folder paths "/Views/Page1.xaml", emptyQS); AddTest(RelativeUri("/Views/Page1.xaml?id=123"), // 11, folder paths + query string "/Views/Page1.xaml?id=123", id123QS); AddTest(RelativeUri("/Views/Page1.xaml#fragment1"), // folder paths + fragment "/Views/Page1.xaml$fragment1", emptyQS); AddTest(RelativeUri("/Views/Page1.xaml?id=123#fragment1"), // folder paths + query string + fragment "/Views/Page1.xaml?id=123$fragment1", id123QS); AddTest(RelativeUri("/Views/Page1$.xaml?id=123#fragment1"), // path that includes "$", which should get encoded "/Views/Page1%24.xaml?id=123$fragment1", id123QS); AddTest(RelativeUri("/Views/Page1.xaml?id=12$3"), // query string value includes "$" "/Views/Page1.xaml?id=12%243", new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "id" }, Values = new string[] { "12$3" } }); AddTest(RelativeUri("/Views/Page1.xaml?id=12?3"), // query string value includes "?" "/Views/Page1.xaml?id=12?3", new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "id" }, Values = new string[] { "12?3" } }); AddTest(RelativeUri("/Views/Page1.xaml?i$d=123"), // query string key includes "$" "/Views/Page1.xaml?i%24d=123", new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "i$d" }, Values = new string[] { "123" } }); AddTest(RelativeUri("/Views/Page1.xaml?i?d=123"), // query string key includes "?" "/Views/Page1.xaml?i?d=123", new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "i?d" }, Values = new string[] { "123" } }); AddTest(RelativeUri("/Views/Page1.xaml#fragment$1"), // fragment includes "$" "/Views/Page1.xaml$fragment%241", emptyQS); AddTest(RelativeUri("/Views/Page1.xaml#fragment?1"), // fragment includes "?" "/Views/Page1.xaml$fragment?1", emptyQS); AddTest(RelativeUri("/Views/完全采用统.xaml"), // global characters in path "/Views/%E5%AE%8C%E5%85%A8%E9%87%87%E7%94%A8%E7%BB%9F.xaml", emptyQS); AddTest(RelativeUri("/Views/Page1.xaml?完全采用统=123"), // global characters in query string key "/Views/Page1.xaml?%E5%AE%8C%E5%85%A8%E9%87%87%E7%94%A8%E7%BB%9F=123", new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "完全采用统" }, Values = new string[] { "123" } }); AddTest(RelativeUri("/Views/Page1.xaml?id=完全采用统"), // global characters in query string value "/Views/Page1.xaml?id=%E5%AE%8C%E5%85%A8%E9%87%87%E7%94%A8%E7%BB%9F", new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "id" }, Values = new string[] { "完全采用统" } }); AddTest(RelativeUri("/Views/Page1.xaml#完全采用统"), // global characters in fragment "/Views/Page1.xaml$%E5%AE%8C%E5%85%A8%E9%87%87%E7%94%A8%E7%BB%9F", emptyQS); AddTest(RelativeUri("/Views/Page1.xaml?page=/Views/Page2.xaml"), // path passed as a query string parameter "/Views/Page1.xaml?page=/Views/Page2.xaml", new QueryStringDictionaryTest() { Count = 1, Keys = new string[] { "page" }, Values = new string[] { "/Views/Page2.xaml" } }); AddTest(RelativeUri("/Views/Page1.xaml?id=1%262&sort=asc"), // query string value includes escaped "&" "/Views/Page1.xaml?id=1%262&sort=asc", new QueryStringDictionaryTest() { Count = 2, DecodeResults = true, Keys = new string[] { "id", "sort" }, Values = new string[] { "1&2", "asc" } }); AddTest(RelativeUri("/Views/Page1.xaml?id=1%262&sort=asc"), // query string value includes escaped "&", don't decode dictionary "/Views/Page1.xaml?id=1%262&sort=asc", new QueryStringDictionaryTest() { Count = 2, Keys = new string[] { "id", "sort" }, Values = new string[] { "1%262", "asc" } }); AddTest(RelativeUri("/Views/Page1.xaml?i%26d=1&sort=asc"), // query string key includes escaped "&" "/Views/Page1.xaml?i%26d=1&sort=asc", new QueryStringDictionaryTest() { Count = 2, DecodeResults = true, Keys = new string[] { "i&d", "sort" }, Values = new string[] { "1", "asc" } }); AddTest(RelativeUri("/Views/Page1.xaml?i%26d=1&sort=asc"), // query string key includes escaped "&", don't decode dictionary "/Views/Page1.xaml?i%26d=1&sort=asc", new QueryStringDictionaryTest() { Count = 2, Keys = new string[] { "i%26d", "sort" }, Values = new string[] { "1", "asc" } }); AddTest(RelativeUri("/Views/Page1.xaml?id=1=2&sort=asc"), // query string value includes "=" "/Views/Page1.xaml?id=1=2&sort=asc", new QueryStringDictionaryTest() { Count = 2, Keys = new string[] { "id", "sort" }, Values = new string[] { "1=2", "asc" } }); }