コード例 #1
0
        public void NestedAttributedObjectIsCorrectlySerialized(
            XmlContentSerializer sut,
            XmlAttributedChangeset changeset,
            XmlAttributedTestEventX tex,
            XmlAttributedTestEventY tey)
        {
            changeset.Items = new object[] { tex, tey };

            var sb = new StringBuilder();

            using (var w = XmlWriter.Create(sb))
            {
                sut.Serialize(w, changeset);
                w.Flush();
                var actual = sb.ToString();

                var expected = XDocument.Parse(
                    "<changeset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://grean:rocks\">" +
                    "  <id>" + changeset.Id + "</id>" +
                    "  <items>" +
                    "    <test-event-x>" +
                    "      <number>" + tex.Number + "</number>" +
                    "      <text>" + tex.Text + "</text>" +
                    "    </test-event-x>" +
                    "    <test-event-y>" +
                    "      <number>" + tey.Number + "</number>" +
                    "      <flag>" + tey.Flag.ToString().ToLowerInvariant() + "</flag>" +
                    "    </test-event-y>" +
                    "  </items>" +
                    "</changeset>");
                Assert.Equal(expected, XDocument.Parse(actual), new XNodeEqualityComparer());
            }
        }
コード例 #2
0
        public void NestedAttributedObjectCanRoundTrip(
            XmlContentSerializer sut,
            XmlAttributedChangeset changeset,
            XmlAttributedTestEventX tex,
            XmlAttributedTestEventY tey)
        {
            changeset.Items = new object[] { tex, tey };

            using (var ms = new MemoryStream())
                using (var w = XmlWriter.Create(ms))
                {
                    sut.Serialize(w, changeset);
                    w.Flush();
                    ms.Position = 0;
                    using (var r = XmlReader.Create(ms))
                    {
                        var content = sut.Deserialize(r);

                        var actual = Assert.IsAssignableFrom <XmlAttributedChangeset>(content.Item);
                        Assert.Equal(changeset.Id, actual.Id);
                        var actualTex = Assert.IsAssignableFrom <XmlAttributedTestEventX>(actual.Items[0]);
                        Assert.Equal(tex.Number, actualTex.Number);
                        Assert.Equal(tex.Text, actualTex.Text);
                        var actualTey = Assert.IsAssignableFrom <XmlAttributedTestEventY>(actual.Items[1]);
                        Assert.Equal(tey.Number, actualTey.Number);
                        Assert.Equal(tey.Flag, actualTey.Flag);
                    }
                }
        }