Exemple #1
0
        public void AccessMemberValueTest()
        {
            var emp1 = _department[0];

            Assert.Equal("Popeye Zhong", MemberAccess.GetMemberValue <string>(emp1, "Name"));
            Assert.Equal("Wuhan", MemberAccess.GetMemberValue <string>(emp1, "HomeAddress.City"));

            MemberAccess.SetMemberValue(emp1, "Name", "Popeye");
            Assert.Equal("Popeye", MemberAccess.GetMemberValue <string>(emp1, "Name"));

            MemberAccess.SetMemberValue(emp1, "HomeAddress.City", "Hunan Shaoyang");
            Assert.Equal("Hunan Shaoyang", MemberAccess.GetMemberValue <string>(emp1, "HomeAddress.City"));

            Assert.NotNull(MemberAccess.GetMemberValue <object>(_department, "[0]"));
            Assert.NotNull(MemberAccess.GetMemberValue <object>(_department, "['Popeye Zhong']"));
            Assert.Equal("Jason Yang", MemberAccess.GetMemberValue <string>(_department, "[1].Name"));
            Assert.Equal("Jason Yang", MemberAccess.GetMemberValue <string>(_department, "['Jason Yang'].Name"));

            Assert.NotNull(MemberAccess.GetMemberValue <object>(_department, "Employees[0]"));
            Assert.NotNull(MemberAccess.GetMemberValue <object>(_department, "Employees['Popeye Zhong']"));
            Assert.Equal("Jason Yang", MemberAccess.GetMemberValue <string>(_department, "Employees[1].Name"));
            Assert.Equal("Jason Yang", MemberAccess.GetMemberValue <string>(_department, "Employees['Jason Yang'].Name"));
        }