using System; using System.IO; using System.Xml.Serialization; using Podsync.Services.Feed; using Xunit; namespace Podsync.Tests.Services.Feed { public class FeedSerializationTests { private const string ImageUrl = "https://yt3.ggpht.com/-OOqFwHRjeMQ/AAAAAAAAAAI/AAAAAAAAAAA/0XQZ2NeGp_0/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"; [Fact] public void SerializeFeedTest() { var feed = new Rss(); var item = new Item { Title = "Steve Gillespie - Getting Arrested (Stand up Comedy)", Link = "https://youtube.com/watch?v=Jj22gfTnpAI", PubDate = DateTime.Parse("Mon, 07 Nov 2016 20:02:26 GMT"), Content = new MediaContent { Url = "http://podsync.net/download/youtube/Jj22gfTnpAI.mp4", Length = 52850000, MediaType = "video/mp4" }, Duration = new TimeSpan(0, 0, 2, 31) }; var channel = new Channel { Title = "Laugh Factory", Description = "The best stand up comedy clips online. That's it.", Link = "https://youtube.com/channel/UCxyCzPY2pjAjrxoSYclpuLg", LastBuildDate = DateTime.Parse("Tue, 08 Nov 2016 05:55:25 GMT"), PubDate = DateTime.Parse("Mon, 31 Jul 2006 22:18:05 GMT"), Subtitle = "Laugh Factory", Summary = "The best stand up comedy clips online. That's it.", Category = "TV & Film", Image = ImageUrl, Thumbnail = ImageUrl, Items = new[] { item } }; feed.Channels = new[] { channel }; var serializer = new XmlSerializer(typeof(Rss)); string body; using (var writer = new StringWriter()) { serializer.Serialize(writer, feed); body = writer.ToString(); } Assert.NotEmpty(body); // Channel tests Assert.Contains("Laugh Factory", body); Assert.Contains("The best stand up comedy clips online. That's it.", body); Assert.Contains("https://youtube.com/channel/UCxyCzPY2pjAjrxoSYclpuLg", body); Assert.Contains("Podsync Generator", body); Assert.Contains("Laugh Factory", body); Assert.Contains("The best stand up comedy clips online. That's it.", body); Assert.Contains("", body); Assert.Contains($"", body); Assert.Contains($"", body); // Items tests Assert.Contains("Steve Gillespie - Getting Arrested (Stand up Comedy)", body); Assert.Contains("Steve Gillespie - Getting Arrested (Stand up Comedy)", body); Assert.Contains("https://youtube.com/watch?v=Jj22gfTnpAI", body); Assert.Contains("https://youtube.com/watch?v=Jj22gfTnpAI", body); Assert.Contains("00:02:31", body); Assert.Contains("", body); Assert.Contains("", body); } } }