private void TestReduce(UriToStringDelegate toString, bool testRelative = true, string id = "") { foreach (var el in reduceElements) { TestLocations(reduceLocations, el + id, el, toString, testRelative); } }
private void TestLocations(string [] locations, string id, string str, UriToStringDelegate toString, bool testRelative = true) { foreach (string location in locations) { if (location.Contains("{0}")) { TestLocation(string.Format(location, id), string.Format(location, str), toString, testRelative); } else { TestLocation(location + id, location + str, toString, testRelative); } } }
private void TestLocation(string id, string str, UriToStringDelegate toString, bool testRelative = true) { TestScheme(scheme => { string uri = scheme + str; string actual = toString(new Uri(scheme + str, UriKind.Absolute)); StringTester.Assert(scheme + id, actual); }); if (!testRelative) { return; } string relActual = toString(new Uri("./" + str, UriKind.Relative)); StringTester.Assert("./" + id, relActual); }
private void TestPercentageEncoding(UriToStringDelegate toString, bool testRelative = false, string id = "") { TestChars(unescapedStr => { var sbUpper = new StringBuilder(); var sbLower = new StringBuilder(); foreach (char c in unescapedStr) { sbUpper.Append(HexEscapeMultiByte(c, true)); sbLower.Append(HexEscapeMultiByte(c, false)); } string escapedUpperStr = sbUpper.ToString(); string escapedLowerStr = sbLower.ToString(); TestLocations(componentLocations, unescapedStr + id, unescapedStr, toString, testRelative); TestLocations(componentLocations, escapedUpperStr + id + "[Upper]", escapedUpperStr, toString, testRelative); TestLocations(componentLocations, escapedLowerStr + id + "[Lower]", escapedLowerStr, toString, testRelative); }); TestLocations(specialCases, id, "", toString, testRelative); }
private void TestReduce (UriToStringDelegate toString, bool testRelative = true, string id = "") { foreach(var el in reduceElements) TestLocations (reduceLocations, el + id, el, toString, testRelative); }
private void TestPercentageEncoding (UriToStringDelegate toString, bool testRelative = false, string id = "") { TestChars (unescapedStr => { var sbUpper = new StringBuilder (); var sbLower = new StringBuilder (); foreach (char c in unescapedStr) { sbUpper.Append (HexEscapeMultiByte (c, true)); sbLower.Append (HexEscapeMultiByte (c, false)); } string escapedUpperStr = sbUpper.ToString (); string escapedLowerStr = sbLower.ToString (); TestLocations (componentLocations, unescapedStr+id, unescapedStr, toString, testRelative); TestLocations (componentLocations, escapedUpperStr+id+"[Upper]", escapedUpperStr, toString, testRelative); TestLocations (componentLocations, escapedLowerStr+id+"[Lower]", escapedLowerStr, toString, testRelative); }); TestLocations (specialCases, id, "", toString, testRelative); }
private void TestLocations (string [] locations, string id, string str, UriToStringDelegate toString, bool testRelative = true) { foreach (string location in locations) { if (location.Contains ("{0}")) TestLocation (string.Format (location, id), string.Format (location, str), toString, testRelative); else TestLocation (location + id, location + str, toString, testRelative); } }
private void TestLocation (string id, string str, UriToStringDelegate toString, bool testRelative = true) { TestScheme (scheme => { string uri = scheme + str; string actual = toString (new Uri (scheme + str, UriKind.Absolute)); StringTester.Assert (scheme + id, actual); }); if (!testRelative) return; string relActual = toString (new Uri ("./" + str, UriKind.Relative)); StringTester.Assert ("./" + id, relActual); }