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")); }