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}\" />"));
        }
Example #2
0
        public async Task WriteXmlContent()
        {
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            string content = "<h1 xmlns=\"boooo\"><b href=\"foo\">Heading</b><br foo=\"bar\" /></h1><br xmlns=\"\" />";

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

                await writer.WriteText("content", content, "application/xml");

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<content type=\"application/xml\">{content}</content>"));
        }
Example #3
0
        public async Task WriteXhtmlTextConstruct()
        {
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            string content = "<h1><b href=\"foo\">Heading</b><br foo=\"bar\" /></h1><br />";

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

                await writer.WriteText("title", content, "xhtml");

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<title type=\"xhtml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">{content}</div></title>"));
        }
        public async Task WriteContent()
        {
            const string uri       = "https://contoso.com/generator";
            const string version   = "1.0";
            const string generator = "Example Toolkit";

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

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

                await writer.WriteGenerator(generator, uri, version);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<generator uri=\"{uri}\" version=\"{version}\">{generator}</generator>"));
        }
Example #5
0
        public async Task WriteCDATAValue()
        {
            var    sw    = new StringWriterWithEncoding(Encoding.UTF8);
            string title = "Title & Markup";

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new AtomFeedWriter(xmlWriter, null, new AtomFormatter()
                {
                    UseCDATA = true
                });

                await writer.WriteTitle(title);

                await writer.Flush();
            }

            var res = sw.ToString();

            Assert.True(CheckResult(res, $"<title><![CDATA[{title}]]></title>"));
        }
        public async Task WriteImage()
        {
            var icon = new SyndicationImage(new Uri("http://contoso.com/icon.ico"), AtomImageTypes.Icon);
            var logo = new SyndicationImage(new Uri("http://contoso.com/logo.png"), AtomImageTypes.Logo);

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

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

                await writer.Write(icon);

                await writer.Write(logo);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<icon>{icon.Url}</icon><logo>{logo.Url}</logo>"));
        }
        public async Task WriteLink()
        {
            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            var link = new SyndicationLink(new Uri("http://contoso.com"))
            {
                Title     = "Test title",
                Length    = 123,
                MediaType = "mp3/video"
            };

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

                await writer.Write(link);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<link title=\"{link.Title}\" href=\"{link.Uri}\" type=\"{link.MediaType}\" length=\"{link.Length}\" />"));
        }
        public async Task WritePrefixedAtomNs()
        {
            const string title     = "Example Feed";
            const string uri       = "https://contoso.com/generator";
            const string generator = "Example Toolkit";

            var sw = new StringWriterWithEncoding(Encoding.UTF8);

            using (var xmlWriter = XmlWriter.Create(sw))
            {
                var writer = new AtomFeedWriter(xmlWriter,
                                                new ISyndicationAttribute[] { new SyndicationAttribute("xmlns:atom", "http://www.w3.org/2005/Atom") });

                await writer.WriteTitle(title);

                await writer.WriteGenerator(generator, uri, null);

                await writer.Flush();
            }

            string res = sw.ToString();

            Assert.True(CheckResult(res, $"<atom:title>{title}</atom:title><atom:generator uri=\"{uri}\">{generator}</atom:generator>", "atom"));
        }