public void ScanCanRoundTripAttributedClassInstance(
            DataContractTestEventX @event)
        {
            var actual =
                DataContractContentSerializer.Scan(@event.GetType().Assembly);

            var expected =
                Assert.IsAssignableFrom <DataContractTestEventX>(
                    @event.RoundTrip(actual));

            Assert.Equal(expected.Number, @event.Number);
            Assert.Equal(expected.Text, @event.Text);
        }
Пример #2
0
        public void WriteToXmlWriterWritesCorrectXml(
            AtomEntry entry,
            Generator <AtomLink> linkGenerator,
            DataContractTestEventX tex,
            DataContractContentSerializer serializer)
        {
            // Fixture setup
            var sb = new StringBuilder();

            using (var w = XmlWriter.Create(sb))
            {
                var links = linkGenerator.Take(2).ToList();
                var sut   = entry
                            .WithContent(new XmlAtomContent(tex))
                            .WithLinks(links);

                // Exercise system
                sut.WriteTo(w, serializer);

                // Verify outcome
                w.Flush();

                var expected = XDocument.Parse(
                    "<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
                    "  <id>" + sut.Id.ToString() + "</id>" +
                    "  <title type=\"text\">" + sut.Title + "</title>" +
                    "  <published>" + sut.Published.ToString("o") + "</published>" +
                    "  <updated>" + sut.Updated.ToString("o") + "</updated>" +
                    "  <author>" +
                    "    <name>" + sut.Author.Name + "</name>" +
                    "  </author>" +
                    "  <link href=\"" + links[0].Href.ToString() + "\" rel=\"" + links[0].Rel + "\" />" +
                    "  <link href=\"" + links[1].Href.ToString() + "\" rel=\"" + links[1].Rel + "\" />" +
                    "  <content type=\"application/xml\">" +
                    "    <test-event-x xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://grean.rocks/dc\">" +
                    "      <number>" + tex.Number + "</number>" +
                    "      <text>" + tex.Text + "</text>" +
                    "    </test-event-x>" +
                    "  </content>" +
                    "</entry>");

                var actual = XDocument.Parse(sb.ToString());
                Assert.Equal(expected, actual, new XNodeEqualityComparer());

                // Teardown
            }
        }
        public void ScanCorrectlySerializesAttributedClassInstance(
            DataContractTestEventX @event)
        {
            var actual =
                DataContractContentSerializer.Scan(@event.GetType().Assembly);

            var expected = XDocument.Parse(
                "<test-event-x xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://grean.rocks/dc\">" +
                "  <number>" + @event.Number + "</number>" +
                "  <text>" + @event.Text + "</text>" +
                "</test-event-x>");

            Assert.Equal(
                expected,
                XDocument.Parse(@event.AsSerializedString(actual)),
                new XNodeEqualityComparer());
        }
        public void SutCanRoundTripAttributedClassInstance(
            DataContractContentSerializer sut,
            DataContractTestEventX dctex)
        {
            using (var ms = new MemoryStream())
                using (var w = XmlWriter.Create(ms))
                {
                    sut.Serialize(w, dctex);
                    w.Flush();
                    ms.Position = 0;
                    using (var r = XmlReader.Create(ms))
                    {
                        var content = sut.Deserialize(r);

                        var actual = Assert.IsAssignableFrom <DataContractTestEventX>(content.Item);
                        Assert.Equal(dctex.Number, actual.Number);
                        Assert.Equal(dctex.Text, actual.Text);
                    }
                }
        }
        public void SerializeCorrectlySerializesAttributedClassInstance(
            DataContractContentSerializer sut,
            DataContractTestEventX dctex)
        {
            var sb = new StringBuilder();

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

                var expected = XDocument.Parse(
                    "<test-event-x xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://grean.rocks/dc\">" +
                    "  <number>" + dctex.Number + "</number>" +
                    "  <text>" + dctex.Text + "</text>" +
                    "</test-event-x>");
                Assert.Equal(expected, XDocument.Parse(actual), new XNodeEqualityComparer());
            }
        }