Пример #1
0
        public void Can_Serialize_And_Deserialize_Xml()
        {
            var ser = new XmlSerializer();
            var testObject = new TestObject {PropertyOne = "propertyOne", PropertyTwo = 42};
            var str = new MemoryStream();
            ser.Serialize(str, testObject);

            str.Seek(0, SeekOrigin.Begin);

            var resultObject = ser.Deserialize<TestObject>(str);

            Assert.AreEqual(testObject.PropertyOne, resultObject.PropertyOne);
            Assert.AreEqual(testObject.PropertyTwo, resultObject.PropertyTwo);
        }
Пример #2
0
        public void Cannot_Deserialize_Without_Type_Parameter()
        {
            var ser = new XmlSerializer();
            var str = new MemoryStream();
            var contract = new TestObject { PropertyOne = "propertyOne", PropertyTwo = 42 };
            ser.Serialize(str, contract);

            str.Seek(0, SeekOrigin.Begin);
            try
            {
                ser.Deserialize(str);
                Assert.Fail("Should have thrown an exception.");
            }
            catch (NotImplementedException)
            {
                // Expected result.
            }
        }