public void ReadFrom_CantRead_ThrowsXmlException(string xmlString) { using (var stringReader = new StringReader(xmlString)) using (XmlReader reader = XmlReader.Create(stringReader)) { var formatter = new AtomPub10CategoriesDocumentFormatter(); Assert.Throws <XmlException>(() => formatter.ReadFrom(reader)); } }
public void ReadFrom() { var f = new AtomPub10CategoriesDocumentFormatter(); f.ReadFrom(XmlReader.Create(new StringReader(app1))); var inline = f.Document as InlineCategoriesDocument; Assert.IsNotNull(inline, "#1"); Assert.AreEqual("http", inline.Scheme, "#2"); }
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); } }
public void ReadFrom_ReferencedCategoriesDocumentTryParseTrue_ReturnsExpected() { using (var stringReader = new StringReader( @"<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>")) using (XmlReader reader = XmlReader.Create(stringReader)) { var formatter = new AtomPub10CategoriesDocumentFormatter(typeof(InlineCategoriesDocumentTryParseTrueSubclass), typeof(ReferencedCategoriesDocumentTryParseTrueSubclass)); formatter.ReadFrom(reader); ReferencedCategoriesDocumentTryParseTrueSubclass document = Assert.IsType <ReferencedCategoriesDocumentTryParseTrueSubclass>(formatter.Document); Assert.Empty(document.AttributeExtensions); Assert.Equal(new Uri("http://referencecategories_url.com/"), document.BaseUri); Assert.Empty(document.ElementExtensions); Assert.Equal("referencecategories_language", document.Language); Assert.Equal(new Uri("http://referencecategories_link.com"), document.Link); } }
public void ReadFrom_NullReader_ThrowsArgumentNullException() { var formatter = new AtomPub10CategoriesDocumentFormatter(); AssertExtensions.Throws <ArgumentNullException>("reader", () => formatter.ReadFrom(null)); }
private static void VerifyRead <T>(string xmlString, Action <T> verifyAction) where T : CategoriesDocument { // ReadFrom. using (var stringReader = new StringReader(xmlString)) using (XmlReader reader = XmlReader.Create(stringReader)) { var formatter = new AtomPub10CategoriesDocumentFormatter(); formatter.ReadFrom(reader); T document = Assert.IsType <T>(formatter.Document); verifyAction(document); } // ReadFrom with custom subclass. using (var stringReader = new StringReader(xmlString)) using (XmlReader reader = XmlReader.Create(stringReader)) { var formatter = new AtomPub10CategoriesDocumentFormatter(typeof(InlineCategoriesDocumentSubclass), typeof(ReferencedCategoriesDocumentSubclass)); formatter.ReadFrom(reader); if (typeof(T) == typeof(InlineCategoriesDocument)) { InlineCategoriesDocumentSubclass document = Assert.IsType <InlineCategoriesDocumentSubclass>(formatter.Document); verifyAction(document as T); } else { ReferencedCategoriesDocumentSubclass document = Assert.IsType <ReferencedCategoriesDocumentSubclass>(formatter.Document); verifyAction(document as T); } } // ReadXml. using (var stringReader = new StringReader(xmlString)) using (XmlReader reader = XmlReader.Create(stringReader)) { reader.MoveToContent(); var formatter = new AtomPub10CategoriesDocumentFormatter(); ((IXmlSerializable)formatter).ReadXml(reader); T document = Assert.IsType <T>(formatter.Document); verifyAction(document); } // ReadXml with custom subclass. using (var stringReader = new StringReader(xmlString)) using (XmlReader reader = XmlReader.Create(stringReader)) { reader.MoveToContent(); var formatter = new AtomPub10CategoriesDocumentFormatter(typeof(InlineCategoriesDocumentSubclass), typeof(ReferencedCategoriesDocumentSubclass)); ((IXmlSerializable)formatter).ReadXml(reader); if (typeof(T) == typeof(InlineCategoriesDocument)) { InlineCategoriesDocumentSubclass document = Assert.IsType <InlineCategoriesDocumentSubclass>(formatter.Document); verifyAction(document as T); } else { ReferencedCategoriesDocumentSubclass document = Assert.IsType <ReferencedCategoriesDocumentSubclass>(formatter.Document); verifyAction(document as T); } } // Load. using (var stringReader = new StringReader(xmlString)) using (XmlReader reader = XmlReader.Create(stringReader)) { T document = Assert.IsType <T>(CategoriesDocument.Load(reader)); verifyAction(document); } }