Beispiel #1
0
        public void TestQueryData()
        {
            var json = @"{
    ""o"": [""abcdefg"", true, { ""uvw"": null }],
    ""p"": ""hijk\\\""lmn\"""", // rst
    ""q"": 1234567
}";
            var q    = QueryData.Parse(json);

            Assert.AreEqual(3, q.Count);
            Assert.AreEqual(q[0].Value, q["o"]);
            Assert.AreEqual(@"hijk\""lmn""", q[1].Value);
            Assert.AreEqual(q[1].Value, q["p"]);
            Assert.AreEqual("1234567", q[2].Value);
            Assert.AreEqual(q[2].Value, q["q"]);

            var query = "a=bcd\\efg+%20&hij=klmn&o=12345&p=67890&q=";

            q = QueryData.Parse(query);
            Assert.AreEqual(5, q.Count);
            Assert.AreEqual("bcd\\efg  ", q["a"]);
            Assert.AreEqual(q["a"], q[0].Value);
            Assert.AreEqual("klmn", q["hij"]);
            Assert.AreEqual(q["hij"], q[1].Value);
            Assert.AreEqual("12345", q[2].Value);
            Assert.AreEqual(q[2].Value, q["o"]);
            Assert.AreEqual("67890", q[3].Value);
            Assert.AreEqual(q[3].Value, q["p"]);
            Assert.AreEqual(string.Empty, q[4].Value);
            Assert.AreEqual(q[4].Value, q["q"]);
#if NETFRAMEWORK
            var backslash = "%5C";
#else
            var backslash = "%5c";
#endif
            Assert.AreEqual(query.Replace("%20", "+").Replace("\\", backslash), q.ToString());
        }