Ejemplo n.º 1
0
        public void TestSetProperties()
        {
            var obj = JsonConverter.ToMap(
                "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 }, \"value3\": [ 444, { \"value311\": 555 } ] }"
                );

            var values = new Dictionary <string, object> {
                //{ "", null },
                { "value1", "AAA" },
                { "value2", "BBB" },
                { "value3.1.value312", "CCC" },
                { "value3.3", "DDD" },
                { "value4.1", "EEE" }
            };

            RecursiveObjectWriter.SetProperties(obj, values);

            var resultValues = RecursiveObjectReader.GetProperties(obj);

            Assert.Equal(9, resultValues.Count);
            Assert.Equal("AAA", resultValues["value1"]);
            Assert.Equal("BBB", resultValues["value2"]);
            Assert.False(resultValues.ContainsKey("value2.value21"));
            Assert.Equal(444, (int)(long)resultValues["value3.0"]);
            Assert.Equal(555, (int)(long)resultValues["value3.1.value311"]);
            Assert.Equal("CCC", resultValues["value3.1.value312"]);
            Assert.Null(resultValues["value3.2"]);
            Assert.Equal("DDD", resultValues["value3.3"]);
            Assert.Null(resultValues["value4.0"]);
            Assert.Equal("EEE", resultValues["value4.1"]);
        }
        public void TestSetProperties()
        {
            var obj = JsonConverter.ToMap(
                "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 }, \"value3\": [ 444, { \"value311\": 555 } ] }"
                );

            var values = Parameters.FromTuples(
                //"", null,
                "value1", "AAA",
                "value2", "BBB",
                "value3.1.value312", "CCC",
                "value3.3", "DDD",
                "value4.1", "EEE"
                );

            RecursiveObjectWriter.SetProperties(obj, values);

            var resultValues = RecursiveObjectReader.GetProperties(obj);

            Assert.Equal(8, resultValues.Count);
            Assert.Equal("AAA", resultValues["value1"]);
            Assert.Equal("BBB", resultValues["value2"]);
            Assert.False(resultValues.ContainsKey("value2.value21"));
            Assert.Equal(444, (int)(long)resultValues["value3.0"]);
            Assert.Equal(555, (int)(long)resultValues["value3.1.value311"]);
            Assert.Equal("CCC", resultValues["value3.1.value312"]);
            Assert.Null(resultValues["value3.2"]);
            Assert.Equal("DDD", resultValues["value3.3"]);
            Assert.Equal("EEE", resultValues["value4.1"]);
        }