コード例 #1
0
        public void CheckData()
        {
            try
            {
                dynamic xml = new XmlItem(xmlFile);
                Assert.IsNotNull(xml, "Xml is not loaded");

                // Element value
                string name  = xml.Personal.Name;                // short conversion to string
                string name2 = xml.Personal.Name.Value;
                Assert.AreEqual("Mipo", name);
                Assert.AreEqual("Mipo", name2);

                // Attribute value
                string year = xml.Personal.Birth["year"];
                Assert.AreEqual("1984", year);

                // Element by position
                var jobs = xml.Jobs();
                Assert.AreEqual("WPF developer", (string)jobs[0]);
                Assert.AreEqual("ASP.NET MVC developer", (string)jobs[1]);

                // Find element by attribute value
                var sqlExp = xml.Experiences.Experience("name", "SQL");
                Assert.IsNotNull(sqlExp, "Experience not found");
                Assert.AreEqual("5", sqlExp["years"], false, "Another experience found");
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }