Exemplo n.º 1
0
        public void CanParseAndSerialize(string[] pathKeys, string path)
        {
            JsonPlusPath jpPath  = new JsonPlusPath(pathKeys);
            JsonPlusPath jpPath2 = JsonPlusPath.Parse(path);

            // JsonPlusPath object created from constructor and `Parse` method should
            // serialize to the same value.
            Assert.Equal(path, jpPath.Value);
            Assert.Equal(path, jpPath2.Value);

            // JsonPlusPath object created from constructor and `Parse` method should
            // be equal (using equality comparer).
            Assert.Equal(jpPath, jpPath2);

            // JsonPlusPath object created from constructor and `Parse` method should
            // have the same number of keys
            Assert.Equal(pathKeys.Length, jpPath.Count);
            Assert.Equal(pathKeys.Length, jpPath2.Count);

            // assert each key in JsonPlusPath objects created
            for (int i = 0; i < pathKeys.Length; i++)
            {
                Assert.Equal(pathKeys[i], jpPath[i]);
                Assert.Equal(pathKeys[i], jpPath2[i]);
            }

            _output.WriteLine(string.Format("Path [{0}] serialized from: {1}", path, string.Join(", ", pathKeys)));
        }
Exemplo n.º 2
0
        public void PathToStringQuoteKeysContainingDot()
        {
            var path1 = new JsonPlusPath(new string[]
            {
                "kong.fu",
                "panda"
            });

            var path2 = new JsonPlusPath(new string[]
            {
                "kong",
                "fu",
                "panda"
            });

            Assert.NotEqual(path1.Value, path2.Value);

            // "kong.fu".panda
            Assert.Equal("\"kong.fu\".panda", path1.Value);
            // kong.fu.panda
            Assert.Equal("kong.fu.panda", path2.Value);
        }