Esempio n. 1
0
        public void FindPath()
        {
            var obj = new TestTraversableObject {
                ["A"] = 1,
                ["B"] = ImmutableArray.Create(new TestTraversableObject {
                    ["C"] = "lol",
                    ["D"] = 1
                }),
                ["X"] = 2
            };

            Assert.Equal(
                new [] { "X" },
                TraversableObject.FindObjects(obj, (int a) => a == 2).Select(x => string.Join(".", x))
                );
            Assert.Equal(
                new [] { "A", "B.0.D" },
                TraversableObject.FindObjects(obj, (int a) => a == 1).Select(x => string.Join(".", x))
                );
            Assert.Equal(
                new [] { "B.0.C" },
                TraversableObject.FindObjects(obj, (string a) => a == "lol").Select(x => string.Join(".", x))
                );
            Assert.Equal(
                new [] { "A", "B", "X" },
                TraversableObject.FindObjects(obj, (object a) => true).Select(x => string.Join(".", x))
                );
            Assert.Equal(
                new [] { "A", "B", "B.0", "B.0.C", "B.0.D", "X" },
                TraversableObject.FindObjects(obj, (object a) => true, true).Select(x => string.Join(".", x))
                );
        }
Esempio n. 2
0
        public void GetArrayProperty()
        {
            var list = ImmutableArray.Create(1, 2, 3);
            var obj  = new TestTraversableObject {
                ["A"] = 1,
                ["B"] = list
            };

            Assert.Equal(1, TraversableObject.GetValue(obj, "A"));
            Assert.Equal(2, TraversableObject.GetValue(TraversableObject.GetValue(obj, "B"), "1"));

            Assert.ThrowsAny <Exception>(() => TraversableObject.GetValue(list, "3"));
        }
Esempio n. 3
0
        public void GetObjectProperty()
        {
            var obj = new TestTraversableObject {
                ["A"] = 1,
                ["B"] = new TestTraversableObject {
                    ["C"] = "lol"
                }
            };

            Assert.Equal(1, TraversableObject.GetValue(obj, "A"));
            Assert.Equal("lol", TraversableObject.GetValue(TraversableObject.GetValue(obj, "B"), "C"));

            var exception = Assert.ThrowsAny <Exception>(() => TraversableObject.GetValue(obj, "no-property"));

            Assert.Contains("no-property", exception.Message);
        }