public void Categories_AddNonNullItem_Success() { Collection <SyndicationCategory> collection = new InlineCategoriesDocument().Categories; collection.Add(new SyndicationCategory()); Assert.Equal(1, collection.Count); }
public void Ctor_CategoriesDocument() { var document = new InlineCategoriesDocument(); var formatter = new Formatter(document); Assert.Same(document, formatter.Document); }
/// <summary> /// Return the service document describing the collections hosted by the service. /// </summary> /// <returns></returns> /// TODO: expect for the moment only 1 Workspace is present. protected override ServiceDocument GetServiceDocument() { List <ResourceCollectionInfo> collections = new List <ResourceCollectionInfo>(); var categories = this.unitOfWork.Categories.GetAll().ToList(); foreach (var col in this.unitOfWork.Collections.GetCollectionsInfo()) { var resourceCollection = new ResourceCollectionInfo(new TextSyndicationContent(col.Name), GetAllEntriesUri(col.Name), null, GetAllowedContentTypes(col.Name)); var inlineCategoriesDocument = new InlineCategoriesDocument(); foreach (var cat in categories) { inlineCategoriesDocument.Categories.Add(new SyndicationCategory(cat.Value, "", cat.Name)); } resourceCollection.Categories.Add(inlineCategoriesDocument); collections.Add(resourceCollection); } Workspace workSpace = new Workspace("Ronald Rosier Blog Service", collections); var serviceDocument = new ServiceDocument(); serviceDocument.Workspaces.Add(workSpace); return(serviceDocument); }
public void GetFormatter_Invoke_ReturnsExpected() { var document = new InlineCategoriesDocument(); AtomPub10CategoriesDocumentFormatter formatter = Assert.IsType <AtomPub10CategoriesDocumentFormatter>(document.GetFormatter()); Assert.Same(document, formatter.Document); Assert.Equal("http://www.w3.org/2007/app", formatter.Version); }
public void Ctor_CategoriesDocument_Inline() { var document = new InlineCategoriesDocument(); var formatter = new AtomPub10CategoriesDocumentFormatter(document); Assert.Same(document, formatter.Document); Assert.Equal("http://www.w3.org/2007/app", formatter.Version); }
public void Ctor_Type_Type(Type inlineDocumentType, Type referencedDocumentType) { var document = new InlineCategoriesDocument(); var formatter = new AtomPub10CategoriesDocumentFormatter(inlineDocumentType, referencedDocumentType); Assert.Null(formatter.Document); Assert.Equal("http://www.w3.org/2007/app", formatter.Version); }
public void Categories_SetNullItem_ThrowsArgumentNullException() { Collection <SyndicationCategory> collection = new InlineCategoriesDocument().Categories; collection.Add(new SyndicationCategory()); AssertExtensions.Throws <ArgumentNullException>("item", () => collection[0] = null); }
public void WriteAttributeExtensions_Categories_Success(string version) { var document = new InlineCategoriesDocument(); CompareHelper.AssertEqualWriteOutput("", writer => Formatter.WriteAttributeExtensionsEntryPoint(writer, document, version)); document.AttributeExtensions.Add(new XmlQualifiedName("name1"), "value"); document.AttributeExtensions.Add(new XmlQualifiedName("name2", "namespace"), ""); document.AttributeExtensions.Add(new XmlQualifiedName("name3"), null); CompareHelper.AssertEqualWriteOutput(@"name1=""value"" d0p1:name2="""" name3=""""", writer => Formatter.WriteAttributeExtensionsEntryPoint(writer, document, version)); }
public void CreateCategory_Invoke_ReturnsExpected() { var document = new InlineCategoriesDocument(); SyndicationCategory category = Formatter.CreateCategoryEntryPoint(document); Assert.Empty(category.AttributeExtensions); Assert.Empty(category.ElementExtensions); Assert.Null(category.Label); Assert.Null(category.Name); Assert.Null(category.Scheme); }
public void SetDocument_GetDocument_ReturnsExpected() { var formatter = new Formatter(); var document = new InlineCategoriesDocument(); formatter.SetDocumentEntryPoint(document); Assert.Same(document, formatter.Document); formatter.SetDocumentEntryPoint(null); Assert.Null(formatter.Document); }
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 Categories_SetNonNullItem_GetReturnsExpected() { Collection <CategoriesDocument> collection = new ResourceCollectionInfo().Categories; collection.Add(new InlineCategoriesDocument()); var newValue = new InlineCategoriesDocument(); collection[0] = newValue; Assert.Same(newValue, collection[0]); }
public void Ctor_Categories(IEnumerable <SyndicationCategory> categories) { var document = new InlineCategoriesDocument(categories); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Equal(categories?.Count() ?? 0, document.Categories.Count); Assert.Empty(document.ElementExtensions); Assert.False(document.IsFixed); Assert.Null(document.Language); Assert.Null(document.Scheme); }
public void Ctor_Default() { var document = new InlineCategoriesDocument(); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Empty(document.Categories); Assert.Empty(document.ElementExtensions); Assert.False(document.IsFixed); Assert.Null(document.Language); Assert.Null(document.Scheme); }
public void WriteTo2() { var doc = new InlineCategoriesDocument(); var f = new AtomPub10CategoriesDocumentFormatter(doc); doc.Categories.Add(new SyndicationCategory("TEST CATEGORY")); var sw = new StringWriter(); using (var xw = XmlWriter.Create(sw, settings)) f.WriteTo(xw); Assert.AreEqual(app2, sw.ToString()); }
public void Ctor_Categories_Bool_String(IEnumerable <SyndicationCategory> categories, bool isFixed, string scheme) { var document = new InlineCategoriesDocument(categories, isFixed, scheme); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Equal(categories?.Count() ?? 0, document.Categories.Count); Assert.Empty(document.ElementExtensions); Assert.Equal(isFixed, document.IsFixed); Assert.Null(document.Language); Assert.Equal(scheme, document.Scheme); }
public void WriteTo() { var doc = new InlineCategoriesDocument(); var f = new AtomPub10CategoriesDocumentFormatter(doc); doc.Scheme = "http"; doc.IsFixed = false; var sw = new StringWriter(); using (var xw = XmlWriter.Create(sw, settings)) f.WriteTo(xw); Assert.AreEqual(app1, sw.ToString()); }
public void Create_CategoriesAdvanced_ReturnsExpected(IList <SyndicationCategory> categories, bool isFixed, string scheme) { Collection <SyndicationCategory> categoriesCollection = categories == null ? null : new Collection <SyndicationCategory>(categories); InlineCategoriesDocument document = CategoriesDocument.Create(categoriesCollection, isFixed, scheme); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Equal(categoriesCollection?.Count ?? 0, document.Categories.Count); Assert.Empty(document.ElementExtensions); Assert.Equal(isFixed, document.IsFixed); Assert.Null(document.Language); Assert.Equal(scheme, document.Scheme); }
public void CreateInlineCategoriesDocument_Invoke_ReturnsExpected() { var workspace = new ResourceCollectionInfoSubclass(); InlineCategoriesDocument document = workspace.CreateInlineCategoriesDocumentEntryPoint(); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Empty(document.Categories); Assert.Empty(document.ElementExtensions); Assert.False(document.IsFixed); Assert.Null(document.Language); Assert.Null(document.Scheme); }
public void CreateInlineCategoriesDocument_Invoke_ReturnsExpected() { var formatter = new Formatter(); InlineCategoriesDocument document = formatter.CreateInlineCategoriesDocumentEntryPoint(); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Empty(document.Categories); Assert.Empty(document.ElementExtensions); Assert.False(document.IsFixed); Assert.Null(document.Language); Assert.Null(document.Scheme); }
public void CreateInlineCategories_Invoke_ReturnsExpected() { var collection = new ResourceCollectionInfo(); InlineCategoriesDocument document = Formatter.CreateInlineCategoriesEntryPoint(collection); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Empty(document.Categories); Assert.Empty(document.ElementExtensions); Assert.False(document.IsFixed); Assert.Null(document.Language); Assert.Null(document.Scheme); }
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 document = new InlineCategoriesDocument(); Formatter.LoadElementExtensionsEntryPoint(reader, document, int.MaxValue); Assert.Equal(2, document.ElementExtensions.Count); Assert.Equal(10, document.ElementExtensions[0].GetObject <ExtensionObject>(new XmlSerializer(typeof(ExtensionObject))).Value); Assert.Equal("ExtensionObject", document.ElementExtensions[0].OuterName); Assert.Empty(document.ElementExtensions[0].OuterNamespace); Assert.Equal("ExtensionObject", document.ElementExtensions[1].OuterName); Assert.Equal("http://www.w3.org/TR/html4/", document.ElementExtensions[1].OuterNamespace); } }
public void WriteElementExtensions_Categories_Success(string version) { var document = new InlineCategoriesDocument(); CompareHelper.AssertEqualWriteOutput("", writer => Formatter.WriteElementExtensionsEntryPoint(writer, document, version)); document.ElementExtensions.Add(new ExtensionObject { Value = 10 }); document.ElementExtensions.Add(new ExtensionObject { Value = 11 }); CompareHelper.AssertEqualWriteOutput( @"<ServiceDocumentFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests""> <Value>10</Value> </ServiceDocumentFormatterTests.ExtensionObject> <ServiceDocumentFormatterTests.ExtensionObject xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/System.ServiceModel.Syndication.Tests""> <Value>11</Value> </ServiceDocumentFormatterTests.ExtensionObject>", writer => Formatter.WriteElementExtensionsEntryPoint(writer, document, version)); }
public override void WriteToStream(Type type, object value, Stream writeStream, HttpContent content) { var document = value as IPublicationCategoriesDocument; var atomDoc = new InlineCategoriesDocument( document.Categories.Select(c => new SyndicationCategory(c.Name) { Label = c.Label }), document.IsFixed, document.Scheme ); var formatter = new AtomPub10CategoriesDocumentFormatter(atomDoc); using (writeStream) { using (var writer = XmlWriter.Create(writeStream)) { formatter.WriteTo(writer); } } }
public void CreateInlineCategoriesDocument_NonGeneric_Success() { var formatter = new Formatter(); InlineCategoriesDocument document = Assert.IsType <InlineCategoriesDocument>(formatter.CreateInlineCategoriesDocumentEntryPoint()); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Empty(document.Categories); Assert.Empty(document.ElementExtensions); Assert.False(document.IsFixed); Assert.Null(document.Language); Assert.Null(document.Scheme); var typedFormatter = new Formatter(typeof(InlineCategoriesDocumentSubclass), typeof(ReferencedCategoriesDocumentSubclass)); document = Assert.IsType <InlineCategoriesDocumentSubclass>(typedFormatter.CreateInlineCategoriesDocumentEntryPoint()); Assert.Empty(document.AttributeExtensions); Assert.Null(document.BaseUri); Assert.Empty(document.Categories); Assert.Empty(document.ElementExtensions); Assert.False(document.IsFixed); Assert.Null(document.Language); Assert.Null(document.Scheme); }
public static IEnumerable <object[]> WriteTo_TestData() { // Empty InlineCategoriesDocument. yield return(new object[] { new InlineCategoriesDocument(), @"<app:categories xmlns:a10=""http://www.w3.org/2005/Atom"" xmlns:app=""http://www.w3.org/2007/app"" />" }); // Full InlineCategoriesDocument var fullSyndicationCategory = new SyndicationCategory("category_name", "category_scheme", "category_label"); fullSyndicationCategory.AttributeExtensions.Add(new XmlQualifiedName("category_name1"), null); fullSyndicationCategory.AttributeExtensions.Add(new XmlQualifiedName("category_name2", "category_namespace"), ""); fullSyndicationCategory.AttributeExtensions.Add(new XmlQualifiedName("category_name3", "category_namespace"), "category_value"); fullSyndicationCategory.AttributeExtensions.Add(new XmlQualifiedName("category_name4", "xmlns"), ""); fullSyndicationCategory.ElementExtensions.Add(new ExtensionObject { Value = 10 }); var fullInlineCategoriesDocument = new InlineCategoriesDocument(new SyndicationCategory[] { new SyndicationCategory(), fullSyndicationCategory }) { BaseUri = new Uri("http://inlinecategories_url.com"), Language = "inlinecategories_Language", IsFixed = true, Scheme = "inlinecategories_scheme" }; fullInlineCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("inlinecategories_name1"), null); fullInlineCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("inlinecategories_name2", "inlinecategories_namespace"), ""); fullInlineCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("inlinecategories_name3", "inlinecategories_namespace"), "inlinecategories_value"); fullInlineCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("inlinecategories_name4", "xmlns"), ""); fullInlineCategoriesDocument.ElementExtensions.Add(new ExtensionObject { Value = 10 }); yield return(new object[] { fullInlineCategoriesDocument, @"<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>" }); // Empty ReferencedCategoriesDocument. yield return(new object[] { new ReferencedCategoriesDocument(), @"<app:categories xmlns:a10=""http://www.w3.org/2005/Atom"" xmlns:app=""http://www.w3.org/2007/app"" />" }); // Full ReferencedCategoriesDocument. var fullReferenceCategoriesDocument = new ReferencedCategoriesDocument(new Uri("http://referencecategories_link.com")) { BaseUri = new Uri("http://referencecategories_url.com"), Language = "referencecategories_language" }; fullReferenceCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("referencecategories_name1"), null); fullReferenceCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("referencecategories_name2", "referencecategories_namespace"), ""); fullReferenceCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("referencecategories_name3", "referencecategories_namespace"), "referencecategories_value"); fullReferenceCategoriesDocument.AttributeExtensions.Add(new XmlQualifiedName("referencecategories_name4", "xmlns"), ""); fullReferenceCategoriesDocument.ElementExtensions.Add(new ExtensionObject { Value = 10 }); yield return(new object[] { fullReferenceCategoriesDocument, @"<app:categories xmlns:a10=""http://www.w3.org/2005/Atom"" xml:base=""http://referencecategories_url.com/"" xml:lang=""referencecategories_language"" href=""http://referencecategories_link.com/"" referencecategories_name1="""" d1p1:referencecategories_name2="""" d1p1:referencecategories_name3=""referencecategories_value"" d1p2:referencecategories_name4="""" xmlns:d1p2=""xmlns"" xmlns:d1p1=""referencecategories_namespace"" xmlns:app=""http://www.w3.org/2007/app""> <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>" }); }
public static SyndicationCategory CreateCategoryEntryPoint(InlineCategoriesDocument inlineCategories) => CreateCategory(inlineCategories);