public void ReadFromReturnsCorrectResult(
     XmlContentSerializer serializer,
     XmlAtomContent seed,
     XmlAttributedTestEventX tex)
 {
     var expected = seed.WithItem(tex);
     using (var sr = new StringReader(expected.ToXmlString(serializer)))
     using (var r = XmlReader.Create(sr))
     {
         XmlAtomContent actual = XmlAtomContent.ReadFrom(r, serializer);
         Assert.Equal(expected, actual);
     }
 }
        public void ClientCanReadWrittenFeed(
            AtomEventsInMemory sut,
            AtomFeedBuilder<XmlAttributedTestEventY> feedBuilder,
            XmlContentSerializer serializer)
        {
            var expected = feedBuilder.Build();

            using (var w = sut.CreateFeedWriterFor(expected))
                expected.WriteTo(w, serializer);
            using (var r = sut.CreateFeedReaderFor(expected.Locate()))
            {
                var actual = AtomFeed.ReadFrom(r, serializer);

                Assert.Equal(expected, actual, new AtomFeedComparer());
            }
        }
예제 #3
0
        public void ReadFromReturnsCorrectResult(
            XmlContentSerializer serializer,
            AtomFeed feed,
            Generator<XmlAttributedTestEventX> eventGenerator)
        {
            var entries = feed.Entries.Zip(
                eventGenerator,
                (entry, @event) => entry.WithContent(
                    entry.Content.WithItem(@event))).ToList();
            var expected = feed.WithEntries(entries);

            using (var sr = new StringReader(expected.ToXmlString(serializer)))
            using (var r = XmlReader.Create(sr))
            {
                AtomFeed actual = AtomFeed.ReadFrom(r, serializer);
                Assert.Equal(expected, actual, new AtomFeedComparer());
            }
        }
        public void FeedsReturnWrittenFeeds(
            AtomEventsInMemory sut,
            IEnumerable<AtomFeedBuilder<XmlAttributedTestEventY>> feedBuilders,
            XmlContentSerializer serializer)
        {
            var feeds = feedBuilders.Select(b => b.Build());
            foreach (var f in feeds)
                using (var w = sut.CreateFeedWriterFor(f))
                    f.WriteTo(w, serializer);

            var actual = sut.Feeds.Select(s => AtomFeed.Parse(s, serializer));

            var expected = new HashSet<AtomFeed>(feeds, new AtomFeedComparer());
            Assert.True(
                expected.SetEquals(actual),
                "Written feeds should be enumerated.");
        }
예제 #5
0
        public void SutCanRoundTripToString(
            XmlContentSerializer serializer,
            AtomFeedBuilder<XmlAttributedTestEventY> builder)
        {
            var expected = builder.Build();
            var xml = expected.ToXmlString(serializer);

            AtomFeed actual = AtomFeed.Parse(xml, serializer);

            Assert.Equal(expected, actual, new AtomFeedComparer());
        }
예제 #6
0
        public void WriteToXmlWriterWritesCorrectXml(
            XmlContentSerializer serializer,
            AtomXmlWriter<XmlContentSerializer> writer,
            AtomFeed feed,
            Generator<XmlAttributedTestEventX> eventGenerator)
        {
            // Fixture setup
            var sb = new StringBuilder();
            using (var w = XmlWriter.Create(sb))
            {
                var entries = feed.Entries.Zip(
                    eventGenerator,
                    (entry, @event) => entry.WithContent(
                        entry.Content.WithItem(@event))).ToList();
                var sut = feed.WithEntries(entries);

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

                // Verify outcome
                w.Flush();

                var expectedLinks = string.Concat(sut.Links.Select(writer.ToXml));
                var expectedEntries = string.Concat(entries.Select(writer.ToXml));

                var expected = XDocument.Parse(
                    "<feed xmlns=\"http://www.w3.org/2005/Atom\">" +
                    "  <id>" + sut.Id.ToString() + "</id>" +
                    "  <title type=\"text\">" + sut.Title + "</title>" +
                    "  <updated>" + sut.Updated.ToString("o") + "</updated>" +
                    "  <author>" +
                    "    <name>" + sut.Author.Name + "</name>" +
                    "  </author>" +
                    expectedLinks +
                    expectedEntries +
                    "</feed>");

                var actual = XDocument.Parse(sb.ToString());
                Assert.Equal(expected, actual, new XNodeEqualityComparer());
            }
            // Teardown
        }
예제 #7
0
 public void ReadFromReturnsCorrectResult(
     AtomEntry seed,
     XmlAttributedTestEventX tex,
     XmlContentSerializer serializer)
 {
     var expected = seed.WithContent(seed.Content.WithItem(tex));
     using (var sr = new StringReader(expected.ToXmlString(serializer)))
     using (var r = XmlReader.Create(sr))
     {
         AtomEntry actual = AtomEntry.ReadFrom(r, serializer);
         Assert.Equal(expected, actual, new AtomEntryComparer());
     }
 }
        public void SutCanRoundTripToString(
            XmlContentSerializer serializer,
            XmlAtomContent seed,
            XmlAttributedTestEventX tex)
        {
            var expected = seed.WithItem(tex);
            var xml = expected.ToXmlString(serializer);

            XmlAtomContent actual = XmlAtomContent.Parse(xml, serializer);

            Assert.Equal(expected, actual);
        }
        public void WriteToXmlWriterWritesCorrectXml(
            XmlContentSerializer serializer,
            XmlAtomContent content,
            AtomEntry entry,
            XmlAttributedTestEventX tex)
        {
            // Fixture setup
            var sb = new StringBuilder();
            using (var w = XmlWriter.Create(sb))
            {
                var sut = content.WithItem(tex);

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

                // Verify outcome
                w.Flush();

                var expected = XDocument.Parse(
                    "<content type=\"application/xml\" xmlns=\"http://www.w3.org/2005/Atom\">" +
                    "  <test-event-x xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://grean:rocks\">" +
                    "    <number>" + tex.Number + "</number>" +
                    "    <text>" + tex.Text + "</text>" +
                    "  </test-event-x>" +
                    "</content>");

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

                // Teardown
            }
        }