public void SutIsNotEqualToAnonymousObject(
     AtomAuthor sut,
     object anonymous)
 {
     var actual = sut.Equals(anonymous);
     Assert.False(actual);
 }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AtomFeed"/> class.
        /// </summary>
        /// <param name="id">The ID of the Atom Feed.</param>
        /// <param name="title">The title of the Atom Feed.</param>
        /// <param name="updated">
        /// The date and time the Atom Feed was last updated.
        /// </param>
        /// <param name="author">The author of the Atom Feed.</param>
        /// <param name="entries">The entries of the Atom Feed.</param>
        /// <param name="links">The links of the Atom Feed itself.</param>
        /// <remarks>
        /// <para>
        /// All values passed into this constructor are subsequently available
        /// as properties on the instance.
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="title" />
        /// or
        /// <paramref name="author" />
        /// or
        /// <paramref name="entries" />
        /// or
        /// <paramref name="links" />
        /// is <see langword="null" />.
        /// </exception>
        public AtomFeed(
            UuidIri id,
            string title,
            DateTimeOffset updated,
            AtomAuthor author,
            IEnumerable <AtomEntry> entries,
            IEnumerable <AtomLink> links)
        {
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }
            if (author == null)
            {
                throw new ArgumentNullException("author");
            }
            if (entries == null)
            {
                throw new ArgumentNullException("entries");
            }
            if (links == null)
            {
                throw new ArgumentNullException("links");
            }

            this.id      = id;
            this.title   = title;
            this.updated = updated;
            this.author  = author;
            this.entries = entries;
            this.links   = links;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AtomEntry"/> class.
        /// </summary>
        /// <param name="id">The ID of the entry.</param>
        /// <param name="title">The title of the entry.</param>
        /// <param name="published">The date and time of publication.</param>
        /// <param name="updated">
        /// The date and time the entry was last updated.
        /// </param>
        /// <param name="author">The author of the entry.</param>
        /// <param name="content">The content of the entry.</param>
        /// <param name="links">The links of the entry.</param>
        /// <remarks>
        /// <para>
        /// The constructor arguments are subsequently available on the object
        /// as properties.
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="title" />
        /// or
        /// <paramref name="author" />
        /// or
        /// <paramref name="content" />
        /// or
        /// <paramref name="content" /> is <see langword="null" />.
        /// </exception>
        public AtomEntry(
            UuidIri id,
            string title,
            DateTimeOffset published,
            DateTimeOffset updated,
            AtomAuthor author,
            XmlAtomContent content,
            IEnumerable <AtomLink> links)
        {
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }
            if (author == null)
            {
                throw new ArgumentNullException("author");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if (links == null)
            {
                throw new ArgumentNullException("links");
            }

            this.id        = id;
            this.title     = title;
            this.published = published;
            this.updated   = updated;
            this.author    = author;
            this.content   = content;
            this.links     = links;
        }
 public void SutCanRoundTripToString(
     AtomAuthor expected,
     IContentSerializer dummySerializer)
 {
     var xml = expected.ToXmlString(dummySerializer);
     AtomAuthor actual = AtomAuthor.Parse(xml);
     Assert.Equal(expected, actual);
 }
Beispiel #5
0
 /// <summary>
 /// Returns a new instance of <see cref="AtomFeed" /> with the supplied
 /// author, but all other values held constant.
 /// </summary>
 /// <param name="newAuthor">The new author.</param>
 /// <returns>
 /// A new instance of <see cref="AtomFeed" /> with the supplied author,
 /// but all other values held constant.
 /// </returns>
 /// <seealso cref="Author" />
 public AtomFeed WithAuthor(AtomAuthor newAuthor)
 {
     return(new AtomFeed(
                this.id,
                this.title,
                this.updated,
                newAuthor,
                this.entries,
                this.links));
 }
Beispiel #6
0
 /// <summary>
 /// Returns a new instance of <see cref="AtomEntry" /> with the
 /// supplied author, but all other values held constant.
 /// </summary>
 /// <param name="newAuthor">The new author.</param>
 /// <returns>
 /// A new instance of <see cref="AtomEntry" /> with the supplied
 /// author, but all other values held constant.
 /// </returns>
 /// <seealso cref="Author" />
 public AtomEntry WithAuthor(AtomAuthor newAuthor)
 {
     return(new AtomEntry(
                this.id,
                this.title,
                this.published,
                this.updated,
                newAuthor,
                this.content,
                this.links));
 }
 public void ReadFromReturnsCorrectResult(
     AtomAuthor expected,
     IContentSerializer dummySerializer)
 {
     using (var sr = new StringReader(expected.ToXmlString(dummySerializer)))
     using (var r = XmlReader.Create(sr))
     {
         AtomAuthor actual = AtomAuthor.ReadFrom(r);
         Assert.Equal(expected, actual);
     }
 }
Beispiel #8
0
        /// <summary>
        /// Creates an <see cref="AtomEntry" /> instance from XML.
        /// </summary>
        /// <param name="xmlReader">
        /// The <see cref="XmlReader" /> containing the XML representation of
        /// the Atom Entry.
        /// </param>
        /// <param name="serializer">
        /// The <see cref="IContentSerializer" /> used to serialize custom XML
        /// content.
        /// </param>
        /// <returns>
        /// A new instance of <see cref="AtomEntry" /> containing the data from
        /// the XML representation of the Atom Entry contained in
        /// <paramref name="xmlReader" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="serializer" /> is <see langword="null" />.
        /// </exception>
        public static AtomEntry ReadFrom(
            XmlReader xmlReader,
            IContentSerializer serializer)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            var navigator = new XPathDocument(xmlReader).CreateNavigator();

            var resolver = new XmlNamespaceManager(new NameTable());

            resolver.AddNamespace("atom", "http://www.w3.org/2005/Atom");

            var id = navigator
                     .Select("/atom:entry/atom:id", resolver).Cast <XPathNavigator>()
                     .Single().Value;
            var title = navigator
                        .Select("/atom:entry/atom:title[@type = 'text']", resolver).Cast <XPathNavigator>()
                        .Single().Value;
            var published = navigator
                            .Select("/atom:entry/atom:published", resolver).Cast <XPathNavigator>()
                            .Single().Value;
            var updated = navigator
                          .Select("/atom:entry/atom:updated", resolver).Cast <XPathNavigator>()
                          .Single().Value;
            var author = navigator
                         .Select("/atom:entry/atom:author", resolver).Cast <XPathNavigator>()
                         .Single().ReadSubtree();
            var content = navigator
                          .Select("/atom:entry/atom:content[@type = 'application/xml']", resolver).Cast <XPathNavigator>()
                          .Single().ReadSubtree();
            var links = navigator
                        .Select("/atom:entry/atom:link", resolver).Cast <XPathNavigator>();

            return(new AtomEntry(
                       UuidIri.Parse(id),
                       title,
                       DateTimeOffset.Parse(published, CultureInfo.InvariantCulture),
                       DateTimeOffset.Parse(updated, CultureInfo.InvariantCulture),
                       AtomAuthor.ReadFrom(author),
                       XmlAtomContent.ReadFrom(content, serializer),
                       links.Select(x => AtomLink.ReadFrom(x.ReadSubtree()))));
        }
Beispiel #9
0
        /// <summary>
        /// Parses the supplied XML into an instance of
        /// <see cref="AtomAuthor" />.
        /// </summary>
        /// <param name="xml">
        /// A string of characters containing the XML representation of an Atom
        /// Author.
        /// </param>
        /// <returns>
        /// A new instance of <see cref="AtomAuthor" /> containing the data
        /// from the supplied <paramref name="xml" />.
        /// </returns>
        public static AtomAuthor Parse(string xml)
        {
            var sr = new StringReader(xml);

            try
            {
                using (var r = XmlReader.Create(sr))
                {
                    sr = null;
                    return(AtomAuthor.ReadFrom(r));
                }
            }
            finally
            {
                if (sr != null)
                {
                    sr.Dispose();
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AtomFeed"/> class.
        /// </summary>
        /// <param name="id">The ID of the Atom Feed.</param>
        /// <param name="title">The title of the Atom Feed.</param>
        /// <param name="updated">
        /// The date and time the Atom Feed was last updated.
        /// </param>
        /// <param name="author">The author of the Atom Feed.</param>
        /// <param name="entries">The entries of the Atom Feed.</param>
        /// <param name="links">The links of the Atom Feed itself.</param>
        /// <remarks>
        /// <para>
        /// All values passed into this constructor are subsequently available
        /// as properties on the instance.
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="title" />
        /// or
        /// <paramref name="author" />
        /// or
        /// <paramref name="entries" />
        /// or
        /// <paramref name="links" />
        /// is <see langword="null" />.
        /// </exception>
        public AtomFeed(
            UuidIri id,
            string title, 
            DateTimeOffset updated,
            AtomAuthor author,
            IEnumerable<AtomEntry> entries,
            IEnumerable<AtomLink> links)
        {
            if (title == null)
                throw new ArgumentNullException("title");
            if (author == null)
                throw new ArgumentNullException("author");
            if (entries == null)
                throw new ArgumentNullException("entries");
            if (links == null)
                throw new ArgumentNullException("links");

            this.id = id;
            this.title = title;
            this.updated = updated;
            this.author = author;
            this.entries = entries;
            this.links = links;
        }
        public void WithAuthorReturnsCorrectResult(
            AtomFeed sut,
            AtomAuthor newAuthor)
        {
            AtomFeed actual = sut.WithAuthor(newAuthor);

            var expected = sut.AsSource().OfLikeness<AtomFeed>()
                .With(x => x.Author).EqualsWhen(
                    (s, d) => object.Equals(newAuthor, d.Author));
            expected.ShouldEqual(actual);
        }
 public void SutIsNotEqualToDifferentOther(
     AtomAuthor sut,
     AtomAuthor other)
 {
     var actual = sut.Equals(other);
     Assert.False(actual);
 }
 public void SutEqualsIdenticalOther(AtomAuthor sut)
 {
     var other = sut.WithName(sut.Name);
     var actual = sut.Equals(other);
     Assert.True(actual);
 }
        public void WriteToXmlWriterWritesCorrectXml(
            AtomAuthor sut)
        {
            // Fixture setup
            var sb = new StringBuilder();
            using (var w = XmlWriter.Create(sb))
            {
                // Exercise system
                sut.WriteTo(w);

                // Verify outcome
                w.Flush();

                var expected = XDocument.Parse(
                    "<author xmlns=\"http://www.w3.org/2005/Atom\">" +
                    "  <name>" + sut.Name + "</name>" +
                    "</author>");

                var actual = XDocument.Parse(sb.ToString());
                Assert.Equal(expected, actual, new XNodeEqualityComparer());
            }
            // Teardown
        }
 public void SutIsXmlWritable(AtomAuthor sut)
 {
     Assert.IsAssignableFrom<IXmlWritable>(sut);
 }
Beispiel #16
0
 /// <summary>
 /// Returns a new instance of <see cref="AtomFeed" /> with the supplied
 /// author, but all other values held constant.
 /// </summary>
 /// <param name="newAuthor">The new author.</param>
 /// <returns>
 /// A new instance of <see cref="AtomFeed" /> with the supplied author,
 /// but all other values held constant.
 /// </returns>
 /// <seealso cref="Author" />
 public AtomFeed WithAuthor(AtomAuthor newAuthor)
 {
     return new AtomFeed(
         this.id,
         this.title,
         this.updated,
         newAuthor,
         this.entries,
         this.links);
 }