Example #1
0
        /// <summary>
        /// Calls:
        /// - BinaryFormatterAssert.Roundtrip(item)
        /// - XmlSerializerAssert.Roundtrip(item)
        /// - DataContractSerializerAssert.Roundtrip(item)
        /// </summary>
        /// <returns>The roundtripped results.</returns>
        public static RoundtripResults <T> RoundtripAll <T>(T item)
        {
            var binary        = BinaryFormatterAssert.Roundtrip(item);
            var xmlSerializer = XmlSerializerAssert.Roundtrip(item);
            var dataContract  = DataContractSerializerAssert.Roundtrip(item);

            return(new RoundtripResults <T>(binary, xmlSerializer, dataContract));
        }
        public void HappyPath()
        {
            var actual = new Dummy {
                Value = 2
            };
            var roundtrip = XmlSerializerAssert.Roundtrip(actual);

            Assert.AreEqual(roundtrip.Value, actual.Value);
            FieldAssert.Equal(actual, roundtrip);
        }
        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 RoundtripForgotReadElementThrows()
        {
            var actual = new ForgotReadElement {
                Value = 2
            };
            var ex = Assert.Throws <AssertException>(() => XmlSerializerAssert.Roundtrip(actual));
            var expectedMessage = "  Simple roundtrip failed. Source is not equal to roundtripped.\r\n" +
                                  "  AssertException:   Found this difference between expected and actual:\r\n" +
                                  "  expected.value: 2\r\n" +
                                  "    actual.value: 0";

            Assert.AreEqual(expectedMessage, ex.Message);
        }