Beispiel #1
0
        public void TestUri()
        {
            SyndicationLink link = new SyndicationLink(new Uri("empty.xml", UriKind.Relative));

            link.Uri = null;
            Assert.IsNull(link.Uri, "#1");
            Assert.IsNull(link.GetAbsoluteUri(), "#2");
        }
Beispiel #2
0
        public static JsonObject ReadFeed(TextReader payload)
        {
            SyndicationFeed feed         = SyndicationFeed.Load(XmlReader.Create(payload));
            JsonObject      feedData     = new JsonObject();
            JsonObject      feedMetadata = new JsonObject();

            feedData["results"]    = feed.Items.Select(item => ReadEntry(item)).ToArray();
            feedData["__metadata"] = feedMetadata;

            feedMetadata["feed_extensions"] = feed.AttributeExtensions.Select(pair => ReadExtension(pair)).ToArray();

            if (feed.Id != null)
            {
                feedMetadata["uri"]            = feed.Id;
                feedMetadata["uri_extensions"] = new JsonObject[] { };
            }

            if (feed.Title != null)
            {
                feedMetadata["title"]            = feed.Title.Text;
                feedMetadata["title_extensions"] = GetTitleExtensions(feed.Title);
            }

            SyndicationLink feedSelfLink = GetLink("self", feed.Links);

            if (feedSelfLink != null)
            {
                feedMetadata["self"]            = feedSelfLink.GetAbsoluteUri().AbsoluteUri;
                feedMetadata["self_extensions"] = GetLinkExtensions(feedSelfLink);
            }

            long?count = GetInlineCount(feed);

            if (count.HasValue)
            {
                feedData["__count"] = count.Value;
            }

            SyndicationLink feedNextLink = GetLink("next", feed.Links);

            if (feedNextLink != null)
            {
                feedData["__next"] = feedNextLink.GetAbsoluteUri().AbsoluteUri;
                feedMetadata["next_extensions"] = GetLinkExtensions(feedNextLink);
            }

            return(feedData);
        }
Beispiel #3
0
        public void GetAbsoluteUri()
        {
            // no Uri
            SyndicationLink link = new SyndicationLink();

            Assert.IsNull(link.GetAbsoluteUri(), "#1");

            // Uri is relative
            link = new SyndicationLink(new Uri("empty.xml", UriKind.Relative));
            Assert.IsNull(link.GetAbsoluteUri(), "#2");

            // Uri is absolute
            link = new SyndicationLink(new Uri("http://mono-project.com/index.rss"));
            Assert.AreEqual("http://mono-project.com/index.rss", link.GetAbsoluteUri().ToString(), "#3");

            // only BaseUri - null result
            link         = new SyndicationLink();
            link.BaseUri = new Uri("http://mono-project.com/index.rss");
            Assert.IsNull(link.GetAbsoluteUri(), "#4");
        }
Beispiel #4
0
        private static JsonObject ReadEntry(SyndicationItem item)
        {
            SyndicationLink     entryEditLink = GetLink("edit", item.Links);
            SyndicationCategory entryCategory = item.Categories.FirstOrDefault();

            XElement   propertiesElement = GetPropertiesElement(item);
            JsonObject entryData         = ReadObject(propertiesElement);

            entryData = JsonObject.Merge(entryData, ReadNavigationProperties(item));
            entryData = JsonObject.Merge(entryData, ReadNamedStreams(item));

            JsonObject propertiesMetadata = ReadPropertiesMetadata(propertiesElement);

            propertiesMetadata = JsonObject.Merge(propertiesMetadata, ReadNavigationPropertiesMetadata(item));
            propertiesMetadata = JsonObject.Merge(propertiesMetadata, ReadNamedStreamMetadata(item));

            JsonObject entryMetadata = new JsonObject();

            entryData["__metadata"]     = entryMetadata;
            entryMetadata["properties"] = propertiesMetadata;

            if (item.Id != null)
            {
                entryMetadata["uri"]            = item.Id;
                entryMetadata["uri_extensions"] = new JsonObject[] { };
            }

            if (entryCategory != null)
            {
                entryMetadata["type"]            = entryCategory.Name;
                entryMetadata["type_extensions"] = new JsonObject[] { };
            }

            if (entryEditLink != null)
            {
                entryMetadata["edit"] = entryEditLink.GetAbsoluteUri().AbsoluteUri;
                entryMetadata["edit_link_extensions"] = GetLinkExtensions(entryEditLink);
            }

            return(entryData);
        }
 public void GetAbsoluteUri_Invoke_ReturnsExpected(SyndicationLink link, Uri expected)
 {
     Assert.Equal(expected, link.GetAbsoluteUri());
 }