public void ReadingOutsideEndElementThrows() { var actual = new ReadingOutsideEndElement { Value = 2 }; var ex = Assert.Throws<AssertException>(() => XmlSerializerAssert.Roundtrip(actual)); var expectedMessage = " Roundtrip of item in ContainerClass Failed.\r\n" + " This means there is an error in serialization.\r\n" + " If you are implementing IXmlSerializable check that you handle ReadEndElement properly as it is a common source of bugs."; Assert.AreEqual(expectedMessage, ex.Message); }
public void SimpleRoundtripReadingOutsideEndElementDoesNotThrow() { // this test is just to show that a simple roundtrip does not catch this. var actual = new ReadingOutsideEndElement { Value = 2 }; var serializer = new DataContractSerializer(typeof(ReadingOutsideEndElement)); var stringBuilder = new StringBuilder(); using (var writer = XmlWriter.Create(stringBuilder)) { serializer.WriteObject(writer, actual); } var xml = stringBuilder.ToString(); using (var reader = XmlReader.Create(new StringReader(xml))) { var roundtrip = (ReadingOutsideEndElement)serializer.ReadObject(reader); Assert.AreEqual(actual.Value, roundtrip.Value); } }
public void SimpleRoundtripReadingOutsideEndElementDoesNotThrow() { // this test is just to show that a simple roundtrip does not catch this. var actual = new ReadingOutsideEndElement { Value = 2 }; var serializer = new XmlSerializer(typeof(ReadingOutsideEndElement)); string xml = null; using (var writer = new StringWriter()) { serializer.Serialize(writer, actual); xml = writer.ToString(); } using (var reader = new StringReader(xml)) { var roundtrip = (ReadingOutsideEndElement)serializer.Deserialize(reader); Assert.AreEqual(actual.Value, roundtrip.Value); } }
public void ReadingOutsideEndElementEqual() { var actual = new ReadingOutsideEndElement { Value = 2 }; var expectedXml = "<ReadingOutsideEndElement><Value>2</Value></ReadingOutsideEndElement>"; Assert.Throws<AssertException>(() => DataContractSerializerAssert.Equal(expectedXml, actual, XmlAssertOptions.IgnoreNamespaces | XmlAssertOptions.IgnoreDeclaration)); //var ex = Assert.Throws<AssertException>(() => DataContractSerializerAssert.Equal(expectedXml, actual, XmlAssertOptions.IgnoreNamespaces | XmlAssertOptions.IgnoreDeclaration)); //var expectedMessage = " Roundtrip of actual in ContainerClass Failed.\r\n" + // " This means there is an error in serialization.\r\n" + // " If you are implementing IXmlSerializable check that you handle ReadEndElement properly as it is a common source of bugs."; //Assert.AreEqual(expectedMessage, ex.Message); }