public void Typical_Feed()
        {
            var xml = @"<feed xmlns=""http://www.w3.org/2005/Atom""
                              xmlns:sync=""http://schemas.sage.com/sdata/sync/2008/1"">
                          <sync:syncMode>catchUp</sync:syncMode>
                          <sync:digest>
                            <sync:origin>http://www.example.com/sdata/myApp1/myContract/-/accounts</sync:origin>
                            <sync:digestEntry>
                              <sync:endpoint>http://www.example.com/sdata/myApp1/myContract/-/accounts</sync:endpoint>
                              <sync:tick>6</sync:tick>
                              <sync:stamp>2008-10-30T17:23:08Z</sync:stamp>
                              <sync:conflictPriority>2</sync:conflictPriority>
                            </sync:digestEntry>
                            <sync:digestEntry>
                              <sync:endpoint>http://www.example.com/sdata/myApp2/myContract/-/accounts</sync:endpoint>
                              <sync:tick>10</sync:tick>
                              <sync:stamp>2008-10-30T12:16:51Z</sync:stamp>
                              <sync:conflictPriority>1</sync:conflictPriority>
                            </sync:digestEntry>
                          </sync:digest>
                        </feed>";
            var feed = new AtomFeed();
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                feed.Load(stream);
            }

            var syncMode = feed.GetSDataSyncMode();
            Assert.That(syncMode, Is.EqualTo(SyncMode.CatchUp));

            var digest = feed.GetSDataSyncDigest();
            Assert.That(digest, Is.Not.Null);
            Assert.That(digest.Origin, Is.EqualTo("http://www.example.com/sdata/myApp1/myContract/-/accounts"));
            Assert.That(digest.Entries.Length, Is.EqualTo(2));

            var entry = digest.Entries[0];
            Assert.That(entry.EndPoint, Is.EqualTo("http://www.example.com/sdata/myApp1/myContract/-/accounts"));
            Assert.That(entry.Tick, Is.EqualTo(6L));
            Assert.That(entry.Stamp, Is.EqualTo(new DateTime(2008, 10, 30, 17, 23, 08)));
            Assert.That(entry.ConflictPriority, Is.EqualTo(2));

            entry = digest.Entries[1];
            Assert.That(entry.EndPoint, Is.EqualTo("http://www.example.com/sdata/myApp2/myContract/-/accounts"));
            Assert.That(entry.Tick, Is.EqualTo(10L));
            Assert.That(entry.Stamp, Is.EqualTo(new DateTime(2008, 10, 30, 12, 16, 51)));
            Assert.That(entry.ConflictPriority, Is.EqualTo(1));
        }
        public void Extension_Namespace_Declared_On_Root_Element_Test()
        {
            const string xml = @"<feed xmlns=""http://www.w3.org/2005/Atom"" xmlns:opensearch=""http://a9.com/-/spec/opensearch/1.1/"">
                                   <entry>
                                     <opensearch:startIndex>33</opensearch:startIndex>
                                   </entry>
                                 </feed>";
            var feed = new AtomFeed();

            using (var reader = new StringReader(xml))
            using (var xmlReader = XmlReader.Create(reader))
            {
                feed.Load(xmlReader);
            }

            Assume.That(feed.Entries, Is.Not.Empty);
            var entry = feed.Entries.First();
            Assert.That(entry.Extensions.OfType<OpenSearchExtension>().Any());
        }
        public void Nested_And_Unnested_Resource_Diagnoses_Test()
        {
            const string xml = @"
            <feed xmlns=""http://www.w3.org/2005/Atom"" xmlns:sdata=""http://schemas.sage.com/sdata/2008/1"">
              <sdata:diagnoses>
            <sdata:diagnosis>
              <sdata:message>one</sdata:message>
            </sdata:diagnosis>
              </sdata:diagnoses>
              <sdata:diagnosis>
            <sdata:message>two</sdata:message>
              </sdata:diagnosis>
              <entry>
            <sdata:diagnoses>
              <sdata:diagnosis>
            <sdata:message>three</sdata:message>
              </sdata:diagnosis>
            </sdata:diagnoses>
            <sdata:diagnosis>
              <sdata:message>four</sdata:message>
            </sdata:diagnosis>
              </entry>
            </feed>";
            var feed = new AtomFeed();
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                feed.Load(stream);
            }

            var diagnoses = feed.GetSDataDiagnoses();
            Assert.That(diagnoses.Count, Is.EqualTo(2));
            Assert.That(diagnoses[0].Message, Is.EqualTo("one"));
            Assert.That(diagnoses[1].Message, Is.EqualTo("two"));

            Assume.That(feed.Entries.Any());
            diagnoses = feed.Entries.First().GetSDataDiagnoses();
            Assert.That(diagnoses.Count, Is.EqualTo(2));
            Assert.That(diagnoses[0].Message, Is.EqualTo("three"));
            Assert.That(diagnoses[1].Message, Is.EqualTo("four"));
        }
 private static AtomFeed LoadFeedContent(Stream stream)
 {
     var feed = new AtomFeed();
     feed.Load(stream);
     return feed;
 }
        public void AtomFeedReader_MultiPageEnumerator()
        {
            var page1 = new AtomFeed();
            var page2 = new AtomFeed();

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Resources.TestFeed)))
            {
                page1.Load(stream);
                stream.Seek(0, SeekOrigin.Begin);
                page2.Load(stream);
            }

            page1.SetOpenSearchStartIndex(1);
            page1.SetOpenSearchItemsPerPage(1);
            ((IList<AtomEntry>) page1.Entries).RemoveAt(1);

            page2.SetOpenSearchStartIndex(2);
            page2.SetOpenSearchItemsPerPage(1);
            ((IList<AtomEntry>) page2.Entries).RemoveAt(0);

            var pages = new Stack<AtomFeed>(new[] {page2, page1});

            var request = new SDataResourceCollectionRequest(_service);
            _mock.Setup(s => s.ReadFeed(request)).Returns(pages.Pop).AtMost(2);

            var reader = request.ExecuteReader();
            reader.ToList();
        }
Пример #6
0
        /// <summary>
        /// Creates a new <see cref="AtomFeed"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object.
        /// </summary>
        /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param>
        /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomFeed"/> instance. This value can be <b>null</b>.</param>
        /// <returns>An <see cref="AtomFeed"/> object loaded using the <paramref name="source"/> data.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the feed remains empty.</exception>
        public static AtomFeed Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            AtomFeed syndicationResource = new AtomFeed();

            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Create new instance using supplied parameters
            //------------------------------------------------------------
            syndicationResource.Load(source, options, settings);

            return syndicationResource;
        }