public void WriteTo_NoDocument_ThrowsInvalidOperationException()
 {
     using (var stringWriter = new StringWriter())
         using (var writer = XmlWriter.Create(stringWriter))
         {
             var formatter = new AtomPub10CategoriesDocumentFormatter();
             Assert.Throws <InvalidOperationException>(() => formatter.WriteTo(writer));
         }
 }
        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 WriteTo_HasDocument_SerializesExpected(CategoriesDocument document, string expected)
        {
            var formatter = new AtomPub10CategoriesDocumentFormatter(document);

            CompareHelper.AssertEqualWriteOutput(expected, writer => formatter.WriteTo(writer));
            CompareHelper.AssertEqualWriteOutput(expected, writer => document.Save(writer));
            CompareHelper.AssertEqualWriteOutput(expected, writer =>
            {
                writer.WriteStartElement("app", "categories", "http://www.w3.org/2007/app");
                ((IXmlSerializable)formatter).WriteXml(writer);
                writer.WriteEndElement();
            });
        }
        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());
        }
Esempio n. 5
0
        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 WriteTo_NullWriter_ThrowsArgumentNullException()
        {
            var formatter = new AtomPub10CategoriesDocumentFormatter();

            AssertExtensions.Throws <ArgumentNullException>("writer", () => formatter.WriteTo(null));
        }