public void RoundtripForgotReadEndElementThrows()
 {
     var actual = new ForgotReadEndElement { 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 SimpleRoundtripForgotReadEndElementDoesNotThrow()
        {
            // this test is just to show that a simple roundtrip does not catch this.
            var actual = new ForgotReadEndElement { Value = 2 };
            var serializer = new DataContractSerializer(typeof(ForgotReadEndElement));
            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 = (ForgotReadEndElement)serializer.ReadObject(reader);
                Assert.AreEqual(actual.Value, roundtrip.Value);
            }
        }
        public void SimpleRoundtripForgotReadEndElementDoesNotThrow()
        {
            // this test is just to show that a simple roundtrip does not catch this.
            var actual = new ForgotReadEndElement { Value = 2 };
            var serializer = new XmlSerializer(typeof(ForgotReadEndElement));
            string xml = null;
            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer, actual);
                xml = writer.ToString();
            }

            using (var reader = new StringReader(xml))
            {
                var roundtrip = (ForgotReadEndElement)serializer.Deserialize(reader);
                Assert.AreEqual(actual.Value, roundtrip.Value);
            }
        }
 public void EqualForgotReadEndElementThrows()
 {
     var actual = new ForgotReadEndElement { Value = 2 };
     var expectedXml = "<ForgotReadEndElement><Value>2</Value></ForgotReadEndElement>";
     var ex = Assert.Throws<AssertException>(()=> XmlSerializerAssert.Equal(expectedXml, actual, XmlAssertOptions.IgnoreNamespaces | XmlAssertOptions.IgnoreDeclaration));
     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);
 }