public void RC_UrlToken() { UrlTokenTestModel model = new UrlTokenTestModel(); RuntimeCompiler compiler = new RuntimeCompiler(new CompilerOptions()); Assert.AreEqual("%22english%20text%2C%20%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%20%D1%82%D0%B5%D0%BA%D1%81%D1%82%22", (String)compiler.Compile(model.GetType(), "{url/p:TextProperty}", OutputFormat.Text).DynamicInvoke(model, null)); Assert.AreEqual("%22english%20text,%20%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9%20%D1%82%D0%B5%D0%BA%D1%81%D1%82%22", (String)compiler.Compile(model.GetType(), "{url:TextProperty}", OutputFormat.Text).DynamicInvoke(model, null)); Assert.AreEqual(EncodeUtility.UrlEncodeAsUrl(model.UrlProperty, false), (String)compiler.Compile(model.GetType(), "{url:UrlProperty}", OutputFormat.Text).DynamicInvoke(model, null)); Assert.AreEqual(EncodeUtility.UrlEncode(model.UrlProperty, false), (String)compiler.Compile(model.GetType(), "{url/p:UrlProperty}", OutputFormat.Text).DynamicInvoke(model, null)); Assert.AreEqual(EncodeUtility.UrlEncodeAsUrl(model.UrlProperty, true), (String)compiler.Compile(model.GetType(), "{url/a:UrlProperty}", OutputFormat.Text).DynamicInvoke(model, null)); Assert.AreEqual(EncodeUtility.HtmlEncode(EncodeUtility.UrlEncodeAsUrl(model.UrlProperty, false)), (String)compiler.Compile(model.GetType(), "{url:UrlProperty}", OutputFormat.Html).DynamicInvoke(model, null)); Assert.AreEqual(EncodeUtility.HtmlEncode(EncodeUtility.UrlEncodeAsUrl(model.UrlProperty, true)), (String)compiler.Compile(model.GetType(), "{url/a:UrlProperty}", OutputFormat.Html).DynamicInvoke(model, null)); }
public void ENC_UrlEncode() { String sourceSet = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" + "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" + "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" + "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f" + "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" + "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f" + "АБВГДЕЁЖЗИЙКЛМНО" + "ПРСТУФХЦЧШЩъЫьЭЮ" + "Яабвгдеёжзийклмн" + "опрстуфхцчшщъыьэ" + "юя"; String resultAsUrlWithoutUnicodeEncoding = "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F" + "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F" + "%20!%22#$%&'()*+,-./" + "0123456789:;%3C=%3E?" + "@ABCDEFGHIJKLMNO" + "PQRSTUVWXYZ[%5C]%5E_" + "%60abcdefghijklmno" + "pqrstuvwxyz%7B%7C%7D~%7F" + "АБВГДЕЁЖЗИЙКЛМНО" + "ПРСТУФХЦЧШЩъЫьЭЮ" + "Яабвгдеёжзийклмн" + "опрстуфхцчшщъыьэ" + "юя"; String resultAsUrlWithUnicodeEncoding = "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F" + "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F" + "%20!%22#$%&'()*+,-./" + "0123456789:;%3C=%3E?" + "@ABCDEFGHIJKLMNO" + "PQRSTUVWXYZ[%5C]%5E_" + "%60abcdefghijklmno" + "pqrstuvwxyz%7B%7C%7D~%7F" + "%D0%90%D0%91%D0%92%D0%93%D0%94%D0%95%D0%81%D0%96%D0%97%D0%98%D0%99%D0%9A%D0%9B%D0%9C%D0%9D%D0%9E" + "%D0%9F%D0%A0%D0%A1%D0%A2%D0%A3%D0%A4%D0%A5%D0%A6%D0%A7%D0%A8%D0%A9%D1%8A%D0%AB%D1%8C%D0%AD%D0%AE" + "%D0%AF%D0%B0%D0%B1%D0%B2%D0%B3%D0%B4%D0%B5%D1%91%D0%B6%D0%B7%D0%B8%D0%B9%D0%BA%D0%BB%D0%BC%D0%BD" + "%D0%BE%D0%BF%D1%80%D1%81%D1%82%D1%83%D1%84%D1%85%D1%86%D1%87%D1%88%D1%89%D1%8A%D1%8B%D1%8C%D1%8D" + "%D1%8E%D1%8F"; String resultAsSegmentWithoutUnicodeEncoding = "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F" + "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F" + "%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F" + "0123456789%3A%3B%3C%3D%3E%3F" + "%40ABCDEFGHIJKLMNO" + "PQRSTUVWXYZ%5B%5C%5D%5E_" + "%60abcdefghijklmno" + "pqrstuvwxyz%7B%7C%7D~%7F" + "АБВГДЕЁЖЗИЙКЛМНО" + "ПРСТУФХЦЧШЩъЫьЭЮ" + "Яабвгдеёжзийклмн" + "опрстуфхцчшщъыьэ" + "юя"; String resultAsSegmentWithUnicodeEncoding = "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F" + "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F" + "%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F" + "0123456789%3A%3B%3C%3D%3E%3F" + "%40ABCDEFGHIJKLMNO" + "PQRSTUVWXYZ%5B%5C%5D%5E_" + "%60abcdefghijklmno" + "pqrstuvwxyz%7B%7C%7D~%7F" + "%D0%90%D0%91%D0%92%D0%93%D0%94%D0%95%D0%81%D0%96%D0%97%D0%98%D0%99%D0%9A%D0%9B%D0%9C%D0%9D%D0%9E" + "%D0%9F%D0%A0%D0%A1%D0%A2%D0%A3%D0%A4%D0%A5%D0%A6%D0%A7%D0%A8%D0%A9%D1%8A%D0%AB%D1%8C%D0%AD%D0%AE" + "%D0%AF%D0%B0%D0%B1%D0%B2%D0%B3%D0%B4%D0%B5%D1%91%D0%B6%D0%B7%D0%B8%D0%B9%D0%BA%D0%BB%D0%BC%D0%BD" + "%D0%BE%D0%BF%D1%80%D1%81%D1%82%D1%83%D1%84%D1%85%D1%86%D1%87%D1%88%D1%89%D1%8A%D1%8B%D1%8C%D1%8D" + "%D1%8E%D1%8F"; Assert.IsNull(EncodeUtility.UrlEncode(null, false)); Assert.AreEqual("", EncodeUtility.UrlEncode("", false)); Assert.AreEqual(resultAsSegmentWithoutUnicodeEncoding, EncodeUtility.UrlEncode(sourceSet, true)); Assert.AreEqual(resultAsSegmentWithUnicodeEncoding, EncodeUtility.UrlEncode(sourceSet, false)); Assert.IsNull(EncodeUtility.UrlEncodeAsUrl(null, false)); Assert.AreEqual("", EncodeUtility.UrlEncodeAsUrl("", false)); Assert.AreEqual(resultAsUrlWithoutUnicodeEncoding, EncodeUtility.UrlEncodeAsUrl(sourceSet, true)); Assert.AreEqual(resultAsUrlWithUnicodeEncoding, EncodeUtility.UrlEncodeAsUrl(sourceSet, false)); }