Exemple #1
0
        public void TestParseBasicJsonString()
        {
            IJsonParser jsonParser = this.GetJsonParserInstance();

            IJsonNode jsonNode = jsonParser.Parse(this.basicJson);

            Assert.IsNull(jsonNode.Key);

            Assert.IsTrue(jsonNode.KeyExists("id"));
            Assert.IsTrue(jsonNode["id"].IsString());
            Assert.AreEqual <string>("91939", (string)jsonNode["id"].InnerValue);
            Assert.AreEqual <Type>(typeof(string), jsonNode["id"].InnerType);

            Assert.IsTrue(jsonNode.KeyExists("name"));
            Assert.IsTrue(jsonNode["name"].IsString());
            Assert.AreEqual <string>("Bruce Wayne", (string)jsonNode["name"].InnerValue);
            Assert.AreEqual <Type>(typeof(string), jsonNode["name"].InnerType);

            Assert.IsTrue(jsonNode.KeyExists("p4ssw@rd"));
            Assert.IsTrue(jsonNode["p4ssw@rd"].IsString());
            Assert.AreEqual <string>("Th4D4rkKn!ghtR3turns", (string)jsonNode["p4ssw@rd"].InnerValue);
            Assert.AreEqual <Type>(typeof(string), jsonNode["p4ssw@rd"].InnerType);

            Assert.IsTrue(jsonNode.KeyExists("info"));
            Assert.IsTrue(jsonNode["info"].IsString());
            Assert.AreEqual <string>("\\\"You don\'t get it son. This isn\'t a mudhole . . . it\'s an operating table . . . And I\'m the surgeon.\\\"", (string)jsonNode["info"].InnerValue);
            Assert.AreEqual <Type>(typeof(string), jsonNode["info"].InnerType);
        }
        public void TestKeyExists()
        {
            IJsonNode jsonNode = this.GetJsonNodeInstance(this.RootKey);

            jsonNode[this.KeyA] = this.JsonValueA;

            Assert.IsTrue(jsonNode.KeyExists(this.KeyA));
            Assert.IsFalse(jsonNode.KeyExists(this.KeyB));
        }