public void Add_NullDataContractExtension_ThrowsArgumentNullException()
        {
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            AssertExtensions.Throws <ArgumentNullException>("dataContractExtension", () => elementExtensions.Add((object)null));
            AssertExtensions.Throws <ArgumentNullException>("dataContractExtension", () => elementExtensions.Add(null, new DataContractSerializer(typeof(ExtensionObject))));
            AssertExtensions.Throws <ArgumentNullException>("dataContractExtension", () => elementExtensions.Add("outerName", "outerNamespace", null));
            AssertExtensions.Throws <ArgumentNullException>("dataContractExtension", () => elementExtensions.Add("outerName", "outerNamespace", null, new DataContractSerializer(typeof(ExtensionObject))));
        }
Esempio n. 2
0
        /// <summary>
        /// Converts to Model category to a syndication category.
        /// </summary>
        /// <param name="category">The model category.</param>
        /// <returns></returns>
        public static SyndicationCategory ConvertToSyndicationCategory(this Category category)
        {
            SyndicationCategory sCategory = new SyndicationCategory();

            sCategory.Label = category.Name;
            sCategory.Name  = category.Value;

            return(sCategory);
        }
Esempio n. 3
0
 public JsonSyndicationCategory(SyndicationCategory category)
 {
     if (category != null)
     {
         this.Label  = category.Label;
         this.Name   = category.Name;
         this.Scheme = category.Scheme;
     }
 }
        public void Clone_NoExtensions_ReturnsExpected()
        {
            var category = new SyndicationCategory();
            SyndicationElementExtensionCollection elementExtensions = category.ElementExtensions;

            SyndicationElementExtensionCollection clone = category.Clone().ElementExtensions;

            Assert.Empty(clone);
        }
        public void Ctor_Default()
        {
            var category = new SyndicationCategory();

            Assert.Empty(category.AttributeExtensions);
            Assert.Empty(category.ElementExtensions);
            Assert.Null(category.Name);
            Assert.Null(category.Scheme);
            Assert.Null(category.Label);
        }
        public void Insert_Invoke_Success()
        {
            var extension = new SyndicationElementExtension(new ExtensionObject {
                Value = 10
            });
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            elementExtensions.Insert(0, extension);
            Assert.Same(extension, elementExtensions[0]);
        }
 public DataResultSyndicationItems GetByCategory(DataFilterSyndication filter)
 {
     SyndicationFeedFormatter feed = this.GetAll();
     SyndicationCategoryComparer categoryComparer = new SyndicationCategoryComparer();
     SyndicationCategory categoryToFind = new SyndicationCategory(filter.CategoryName);
     List<SyndicationItem> items = feed.Feed.Items
                                     .Where(p => p.Categories.Contains(categoryToFind, categoryComparer))
                                     .ToList();
     return this.GetDataResult(items, filter);
 }
        public void ItemSet_Null_ThrowsArgumentNullException()
        {
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            elementExtensions.Add(new ExtensionObject {
                Value = 9
            });

            AssertExtensions.Throws <ArgumentNullException>("item", () => elementExtensions[0] = null);
        }
        public void Ctor_String_String_String(string name, string scheme, string label)
        {
            var category = new SyndicationCategory(name, scheme, label);

            Assert.Empty(category.AttributeExtensions);
            Assert.Empty(category.ElementExtensions);
            Assert.Equal(name, category.Name);
            Assert.Equal(scheme, category.Scheme);
            Assert.Equal(label, category.Label);
        }
Esempio n. 10
0
        public void CreateCategory_Invoke_ReturnsExpected()
        {
            var document = new InlineCategoriesDocumentSubclass();
            SyndicationCategory category = document.CreateCategoryEntryPoint();

            Assert.Empty(category.AttributeExtensions);
            Assert.Empty(category.ElementExtensions);
            Assert.Null(category.Name);
            Assert.Null(category.Scheme);
            Assert.Null(category.Label);
        }
Esempio n. 11
0
        public void WriteAttributeExtensions_Category_Success(string version)
        {
            var category = new SyndicationCategory();

            CompareHelper.AssertEqualWriteOutput("", writer => Formatter.WriteAttributeExtensionsEntryPoint(writer, category, version));

            category.AttributeExtensions.Add(new XmlQualifiedName("name1"), "value");
            category.AttributeExtensions.Add(new XmlQualifiedName("name2", "namespace"), "");
            category.AttributeExtensions.Add(new XmlQualifiedName("name3"), null);
            CompareHelper.AssertEqualWriteOutput(@"name1=""value"" d0p1:name2="""" name3=""""", writer => Formatter.WriteAttributeExtensionsEntryPoint(writer, category, version));
        }
Esempio n. 12
0
        public void CreateCategory_Invoke_ReturnsExpected()
        {
            var item = new SyndicationItem();
            SyndicationCategory category = Formatter.CreateCategoryEntryPoint(item);

            Assert.Empty(category.AttributeExtensions);
            Assert.Empty(category.ElementExtensions);
            Assert.Null(category.Label);
            Assert.Null(category.Name);
            Assert.Null(category.Scheme);
        }
        public void Ctor_SyndicationCategory_Empty()
        {
            var original = new SyndicationCategory();
            var clone    = new SyndicationCategorySubclass(original);

            Assert.Empty(clone.AttributeExtensions);
            Assert.Empty(clone.ElementExtensions);
            Assert.Null(clone.Label);
            Assert.Null(clone.Name);
            Assert.Null(clone.Scheme);
        }
Esempio n. 14
0
        public void Categories_SetNonNullItem_GetReturnsExpected()
        {
            Collection <SyndicationCategory> collection = new InlineCategoriesDocument().Categories;

            collection.Add(new SyndicationCategory());

            var newValue = new SyndicationCategory();

            collection[0] = newValue;
            Assert.Same(newValue, collection[0]);
        }
        public void Clone_Empty_ReturnsExpected()
        {
            var original = new SyndicationCategory();
            SyndicationCategory clone = original.Clone();

            Assert.Empty(clone.AttributeExtensions);
            Assert.Empty(clone.ElementExtensions);
            Assert.Null(clone.Label);
            Assert.Null(clone.Name);
            Assert.Null(clone.Scheme);
        }
        public void Remove_Invoke_Success()
        {
            var extension = new SyndicationElementExtension(new ExtensionObject {
                Value = 10
            });
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            elementExtensions.Add(extension);

            elementExtensions.RemoveAt(0);
            Assert.Equal(0, elementExtensions.Count);
        }
        public void Clear_Invoke_Success()
        {
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            elementExtensions.Add(new ExtensionObject {
                Value = 10
            });

            elementExtensions.Clear();
            Assert.Equal(0, elementExtensions.Count);

            elementExtensions.Clear();
            Assert.Equal(0, elementExtensions.Count);
        }
        public void ReadFrom_InlineCategoriesDocument_ReturnsExpected()
        {
            string xmlString =
                @"<app:categories xmlns:a10=""http://www.w3.org/2005/Atom"" xml:base=""http://inlinecategories_url.com/"" xml:lang=""inlinecategories_Language"" scheme=""inlinecategories_scheme"" fixed=""yes"" inlinecategories_name1="""" d1p1:inlinecategories_name2="""" d1p1:inlinecategories_name3=""inlinecategories_value"" d1p2:inlinecategories_name4="""" xmlns:d1p2=""xmlns"" xmlns:d1p1=""inlinecategories_namespace"" xmlns:app=""http://www.w3.org/2007/app"">
    <a10:category term="""" />
    <a10:category category_name1="""" d2p1:category_name2="""" d2p1:category_name3=""category_value"" d1p2:category_name4="""" term=""category_name"" label=""category_label"" scheme=""category_scheme"" xmlns:d2p1=""category_namespace"">
        <AtomPub10CategoriesDocumentFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests"">
            <Value>10</Value>
        </AtomPub10CategoriesDocumentFormatterTests.ExtensionObject>
    </a10:category>
    <AtomPub10CategoriesDocumentFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests"">
        <Value>10</Value>
    </AtomPub10CategoriesDocumentFormatterTests.ExtensionObject>
</app:categories>";

            VerifyRead <InlineCategoriesDocument>(xmlString, document =>
            {
                Assert.Equal(4, document.AttributeExtensions.Count);
                Assert.Equal("", document.AttributeExtensions[new XmlQualifiedName("inlinecategories_name1")]);
                Assert.Equal("", document.AttributeExtensions[new XmlQualifiedName("inlinecategories_name2", "inlinecategories_namespace")]);
                Assert.Equal("inlinecategories_value", document.AttributeExtensions[new XmlQualifiedName("inlinecategories_name3", "inlinecategories_namespace")]);
                Assert.Equal("", document.AttributeExtensions[new XmlQualifiedName("inlinecategories_name4", "xmlns")]);
                Assert.Equal(new Uri("http://inlinecategories_url.com/"), document.BaseUri);
                Assert.Equal(2, document.Categories.Count);
                Assert.Equal(1, document.ElementExtensions.Count);
                Assert.Equal(10, document.ElementExtensions[0].GetObject <ExtensionObject>().Value);
                Assert.True(document.IsFixed);
                Assert.Equal("inlinecategories_Language", document.Language);
                Assert.Equal("inlinecategories_scheme", document.Scheme);

                SyndicationCategory firstCategory = document.Categories[0];
                Assert.Empty(firstCategory.AttributeExtensions);
                Assert.Empty(firstCategory.ElementExtensions);
                Assert.Empty(firstCategory.Name);
                Assert.Equal("inlinecategories_scheme", firstCategory.Scheme);
                Assert.Null(firstCategory.Label);

                SyndicationCategory secondCategory = document.Categories[1];
                Assert.Equal(4, secondCategory.AttributeExtensions.Count);
                Assert.Equal("", secondCategory.AttributeExtensions[new XmlQualifiedName("category_name1")]);
                Assert.Equal("", secondCategory.AttributeExtensions[new XmlQualifiedName("category_name2", "category_namespace")]);
                Assert.Equal("category_value", secondCategory.AttributeExtensions[new XmlQualifiedName("category_name3", "category_namespace")]);
                Assert.Equal("", secondCategory.AttributeExtensions[new XmlQualifiedName("category_name4", "xmlns")]);
                Assert.Equal(1, secondCategory.ElementExtensions.Count);
                Assert.Equal(10, secondCategory.ElementExtensions[0].GetObject <ExtensionObject>().Value);
                Assert.Equal("category_name", secondCategory.Name);
                Assert.Equal("category_scheme", secondCategory.Scheme);
                Assert.Equal("category_label", secondCategory.Label);
            });
        }
        public void ItemSet_Get_ReturnsExpected()
        {
            var extension = new SyndicationElementExtension(new ExtensionObject {
                Value = 10
            });
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            elementExtensions.Add(new ExtensionObject {
                Value = 9
            });

            elementExtensions[0] = extension;
            Assert.Same(extension, elementExtensions[0]);
        }
        public void ReadElementExtensions_NoSuchObject_ReturnsEmpty(string name, string ns)
        {
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            elementExtensions.Add(new ExtensionObject {
                Value = 10
            });
            elementExtensions.Add(new ExtensionObject {
                Value = 11
            });

            Assert.Empty(elementExtensions.ReadElementExtensions <ExtensionObject>(name, ns));
            Assert.Empty(elementExtensions.ReadElementExtensions <ExtensionObject>(name, ns, new DataContractSerializer(typeof(ExtensionObject))));
            Assert.Empty(elementExtensions.ReadElementExtensions <ExtensionObject>(name, ns, new XmlSerializer(typeof(ExtensionObject))));
        }
Esempio n. 21
0
        public void Snippet4()
        {
            // <Snippet4>
            SyndicationFeed feed = new SyndicationFeed("My Feed Title", "My Feed Description", new Uri("http://MyFeedURI"));

            SyndicationCategory category = new SyndicationCategory("MyCategory");

            category.Label  = "categoryLabel";
            category.Name   = "categoryName";
            category.Scheme = "categoryScheme";
            feed.Categories.Add(category);

            SerializeFeed(feed);
            // </Snippet4>
        }
Esempio n. 22
0
    /// <summary>
    /// Builds a dictionary that contains Syndication Category.
    /// </summary>
    /// <param name="c">A <see cref="System.ServiceModel.Syndication.SyndicationCategory"/> representing a category from a syndicated feed.</param>
    /// <returns>A <see cref="System.Collections.Generic.Dictionary{string,object}"/> containing the content of the category.</returns>
    private static Dictionary <string, object> BuildSyndicationCategory(SyndicationCategory c)
    {
        Dictionary <string, object> category = new Dictionary <string, object>();

        if (c != null)
        {
            category.Add("AttributeExtensions", c.AttributeExtensions.ToDictionary(a => a.Key.ToString(), a => a.Value));
            category.Add("ElementExtensions", c.ElementExtensions);
            category.Add("Label", c.Label);
            category.Add("Name", c.Name);
            category.Add("Scheme", c.Scheme);
        }

        return(category);
    }
        public void Clone_WithExtensions_ReturnsExpected()
        {
            var category = new SyndicationCategory();

            SyndicationElementExtensionCollection elementExtensions = category.ElementExtensions;

            elementExtensions.Add(new ExtensionObject {
                Value = 10
            });

            SyndicationElementExtensionCollection clone = category.Clone().ElementExtensions;

            Assert.Equal(1, clone.Count);

            elementExtensions.Clear();
            Assert.Equal(1, clone.Count);
        }
        public void Add_Invoke_ReturnsExpected()
        {
            SyndicationElementExtensionCollection elementExtensions = new SyndicationCategory().ElementExtensions;

            elementExtensions.Add(new ExtensionObject {
                Value = 10
            });
            elementExtensions.Add(new SyndicationElementExtension(new ExtensionObject {
                Value = 11
            }));
            using (var stringReader = new StringReader(@"<SyndicationElementExtensionCollectionTests.ExtensionObject xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><Value>12</Value></SyndicationElementExtensionCollectionTests.ExtensionObject>"))
                using (XmlReader reader = XmlReader.Create(stringReader))
                {
                    elementExtensions.Add(reader);
                }
            elementExtensions.Add(new ExtensionObject {
                Value = 13
            }, new DataContractSerializer(typeof(ExtensionObject)));
            elementExtensions.Add(new ExtensionObject {
                Value = 14
            }, (DataContractSerializer)null);
            elementExtensions.Add(new ExtensionObject {
                Value = 15
            }, new XmlSerializer(typeof(ExtensionObject)));
            elementExtensions.Add(new ExtensionObject {
                Value = 16
            }, (XmlSerializer)null);
            elementExtensions.Add("outerName", "outerNamespace", new ExtensionObject {
                Value = 17
            });
            elementExtensions.Add("outerName", "outerNamespace", new ExtensionObject {
                Value = 18
            }, new DataContractSerializer(typeof(ExtensionObject)));
            elementExtensions.Add("outerName", "outerNamespace", new ExtensionObject {
                Value = 19
            }, null);

            Assert.Equal(10, elementExtensions.Count);

            using (XmlReader reader = elementExtensions.GetReaderAtElementExtensions())
            {
                Assert.Equal(@"<SyndicationElementExtensionCollectionTests.ExtensionObject xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><Value>10</Value></SyndicationElementExtensionCollectionTests.ExtensionObject>", reader.ReadOuterXml());
            }
        }
Esempio n. 25
0
        public async Task <ActionResult> GetFeed()
        {
            SyndicationFeed   feed   = new SyndicationFeed(BlogSettings.Name, BlogSettings.Description, new Uri(BaseAddress));
            SyndicationPerson author = new SyndicationPerson("", BlogSettings.Onwer, BaseAddress);

            feed.Authors.Add(author);
            Dictionary <string, SyndicationCategory> categoryMap = new Dictionary <string, SyndicationCategory>();
            {
                var cates = await BlogService.CategoryService.GetCategories(await BlogService.CategoryService.All());

                foreach (var p in cates)
                {
                    var cate = new SyndicationCategory(p.Name);
                    categoryMap.Add(p.Id, cate);
                    feed.Categories.Add(cate);
                }
            }
            {
                var posts = await BlogService.PostService.GetPosts(await BlogService.PostService.All());

                List <SyndicationItem> items = new List <SyndicationItem>();
                foreach (var p in posts)
                {
                    var s = new SyndicationItem(p.Title,
                                                SyndicationContent.CreateHtmlContent(Markdown.ToHtml(p.Content.Raw, Pipeline)),
                                                new Uri($"{BaseAddress}/posts/{p.Id}"), p.Id, p.ModificationTime);
                    s.Authors.Add(author);
                    string summary = Markdown.ToPlainText(p.Content.Raw, Pipeline);
                    s.Summary = SyndicationContent.CreatePlaintextContent(summary.Length <= 100 ? summary : summary.Substring(0, 100));
                    if (categoryMap.TryGetValue(p.CategoryId, out var cate))
                    {
                        s.Categories.Add(cate);
                    }
                    s.PublishDate = p.CreationTime;
                    items.Add(s);
                }
                feed.Items = items.AsEnumerable();
            }
            StringBuilder sb = new StringBuilder();

            using (var writer = XmlWriter.Create(sb))
                feed.GetAtom10Formatter().WriteTo(writer);
            return(Content(sb.ToString(), "text/xml"));
        }
        public async Task WriteCategory()
        {
            var category = new SyndicationCategory("Test Category");

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new AtomFeedWriter(xmlWriter);

                await writer.Write(category);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<category term=\"{category.Name}\" />"));
        }
        public void Read_InlineCategoriesDocumentTryParseTrue_ReturnsExpected()
        {
            using (var stringReader = new StringReader(
                       @"<app:categories xmlns:a10=""http://www.w3.org/2005/Atom"" xml:base=""http://inlinecategories_url.com/"" xml:lang=""inlinecategories_Language"" scheme=""inlinecategories_scheme"" fixed=""yes"" inlinecategories_name1="""" d1p1:inlinecategories_name2="""" d1p1:inlinecategories_name3=""inlinecategories_value"" d1p2:inlinecategories_name4="""" xmlns:d1p2=""xmlns"" xmlns:d1p1=""inlinecategories_namespace"" xmlns:app=""http://www.w3.org/2007/app"">
    <a10:category term="""" />
    <a10:category category_name1="""" d2p1:category_name2="""" d2p1:category_name3=""category_value"" d1p2:category_name4="""" term=""category_name"" label=""category_label"" scheme=""category_scheme"" xmlns:d2p1=""category_namespace"">
        <AtomPub10CategoriesDocumentFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests"">
            <Value>10</Value>
        </AtomPub10CategoriesDocumentFormatterTests.ExtensionObject>
    </a10:category>
    <AtomPub10CategoriesDocumentFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests"">
        <Value>10</Value>
    </AtomPub10CategoriesDocumentFormatterTests.ExtensionObject>
</app:categories>"))
                using (XmlReader reader = XmlReader.Create(stringReader))
                {
                    var formatter = new AtomPub10CategoriesDocumentFormatter(typeof(InlineCategoriesDocumentTryParseTrueSubclass), typeof(ReferencedCategoriesDocumentTryParseTrueSubclass));
                    formatter.ReadFrom(reader);

                    InlineCategoriesDocumentTryParseTrueSubclass document = Assert.IsType <InlineCategoriesDocumentTryParseTrueSubclass>(formatter.Document);
                    Assert.Empty(document.AttributeExtensions);
                    Assert.Equal(new Uri("http://inlinecategories_url.com/"), document.BaseUri);
                    Assert.Equal(2, document.Categories.Count);
                    Assert.Empty(document.ElementExtensions);
                    Assert.True(document.IsFixed);
                    Assert.Equal("inlinecategories_Language", document.Language);
                    Assert.Equal("inlinecategories_scheme", document.Scheme);

                    SyndicationCategory firstCategory = document.Categories[0];
                    Assert.Empty(firstCategory.AttributeExtensions);
                    Assert.Empty(firstCategory.ElementExtensions);
                    Assert.Empty(firstCategory.Name);
                    Assert.Equal("inlinecategories_scheme", firstCategory.Scheme);
                    Assert.Null(firstCategory.Label);

                    SyndicationCategory secondCategory = document.Categories[1];
                    Assert.Empty(secondCategory.AttributeExtensions);
                    Assert.Empty(secondCategory.ElementExtensions);
                    Assert.Equal("category_name", secondCategory.Name);
                    Assert.Equal("category_scheme", secondCategory.Scheme);
                    Assert.Equal("category_label", secondCategory.Label);
                }
        }
Esempio n. 28
0
        public void LoadElementExtensions_Categories_Success()
        {
            var settings = new XmlReaderSettings {
                ConformanceLevel = ConformanceLevel.Fragment
            };

            using (var stringReader = new StringReader(@"<ExtensionObject><Value>10</Value></ExtensionObject><ExtensionObject xmlns=""http://www.w3.org/TR/html4/""><Value>11</Value></ExtensionObject>"))
                using (XmlReader reader = XmlReader.Create(stringReader, settings))
                {
                    var category = new SyndicationCategory();
                    Formatter.LoadElementExtensionsEntryPoint(reader, category, int.MaxValue);

                    Assert.Equal(2, category.ElementExtensions.Count);
                    Assert.Equal(10, category.ElementExtensions[0].GetObject <ExtensionObject>(new XmlSerializer(typeof(ExtensionObject))).Value);
                    Assert.Equal("ExtensionObject", category.ElementExtensions[0].OuterName);
                    Assert.Empty(category.ElementExtensions[0].OuterNamespace);
                    Assert.Equal("ExtensionObject", category.ElementExtensions[1].OuterName);
                    Assert.Equal("http://www.w3.org/TR/html4/", category.ElementExtensions[1].OuterNamespace);
                }
        }
Esempio n. 29
0
        public void Snippet1()
        {
            SyndicationFeed feed = new SyndicationFeed("My Feed Title", "My Feed Description", new Uri("http://MyFeedURI"));

            // <Snippet1>
            SyndicationItem item = new SyndicationItem("Item Title", "Item Content", new Uri("http://MyItemURI"));

            item.Authors.Add(new SyndicationPerson("*****@*****.**", "Jesper Aaberg", "http://Contoso/Aaberg"));
            item.Authors.Add(new SyndicationPerson("*****@*****.**", "Syed Abbas", "http://Contoso/Abbas"));

            SyndicationCategory category = new SyndicationCategory("MyCategory");

            category.Label  = "categoryLabel";
            category.Name   = "categoryName";
            category.Scheme = "categoryScheme";

            SyndicationCategory category2 = new SyndicationCategory("MyCategoryTwo");

            category2.Label  = "categoryLabel";
            category2.Name   = "categoryName";
            category2.Scheme = "categoryScheme";

            item.Categories.Add(category);
            item.Categories.Add(category2);
            item.Contributors.Add(new SyndicationPerson("*****@*****.**", "Lene Aaling", "http://Contoso/Aaling"));
            item.Contributors.Add(new SyndicationPerson("*****@*****.**", "Kim Abercrombie", "http://Contoso/Abercrombie"));
            item.Copyright       = new TextSyndicationContent("Copyright 2007");
            item.Id              = "ItemID";
            item.LastUpdatedTime = DateTime.Now;
            item.PublishDate     = DateTime.Today;
            item.SourceFeed      = feed;
            item.Summary         = new TextSyndicationContent("Item Summary");

            Collection <SyndicationItem> items = new Collection <SyndicationItem>();

            items.Add(item);
            feed.Items = items;

            SerializeItem(item);
            // </Snippet1>
        }
Esempio n. 30
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);
        }
Esempio n. 31
0
        public void WriteElementExtensions_Category_Success(string version)
        {
            var category  = new SyndicationCategory();
            var formatter = new Formatter();

            CompareHelper.AssertEqualWriteOutput("", writer => formatter.WriteElementExtensionsEntryPoint(writer, category, version));

            category.ElementExtensions.Add(new ExtensionObject {
                Value = 10
            });
            category.ElementExtensions.Add(new ExtensionObject {
                Value = 11
            });
            CompareHelper.AssertEqualWriteOutput(
                @"<SyndicationItemFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests"">
    <Value>10</Value>
</SyndicationItemFormatterTests.ExtensionObject>
<SyndicationItemFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests"">
    <Value>11</Value>
</SyndicationItemFormatterTests.ExtensionObject>", writer => formatter.WriteElementExtensionsEntryPoint(writer, category, version));
        }