コード例 #1
0
        public void DeserializeUnknownNode()
        {
            MockConfiguration text = new MockConfiguration
            {
                Name  = "Hi",
                Data  = 1,
                Data3 = 3
            };

            XElement element = text.SerializeAsXElement("x");

            Assert.Throws <InvalidOperationException>(() => element.XmlDeserialize <MockConfiguration>("xx"));
        }
コード例 #2
0
        public void Deserialize()
        {
            MockConfiguration text = new MockConfiguration
            {
                Name  = "Hi",
                Data  = 1,
                Data3 = 3
            };
            XElement element  = text.SerializeAsXElement("x");
            var      instance = element.XmlDeserialize <MockConfiguration>("x");

            Assert.AreEqual("Hi", instance.Name);
            Assert.AreEqual(1, instance.Data);
            Assert.AreEqual(3, instance.Data3);
        }
コード例 #3
0
        public void SerializeAsXElement()
        {
            MockConfiguration text = new MockConfiguration
            {
                Name  = "Hi",
                Data  = 1,
                Data3 = 3
            };
            XElement element = text.SerializeAsXElement("x");

            Assert.IsNotNull(element);
            Assert.AreEqual("x", element.Name.LocalName);
            Assert.AreEqual("Hi", element.Element("Name").Value);
            Assert.AreEqual("1", element.Element("Data").Value);
            Assert.AreEqual("3", element.Element("Data3").Value);
        }
コード例 #4
0
        public void SerializeAsXElementNull()
        {
            MockConfiguration text = null;

            Assert.Throws <ArgumentNullException>(() => text.SerializeAsXElement("x"));
        }