public FeedDTO Add(String uri) { if (string.IsNullOrEmpty(uri)) // validate not null or empty { throw new ArgumentNullException("uri", "The uri parameter cannot be null or empty"); } Uri feedUri; if (!Uri.TryCreate(uri, UriKind.Absolute, out feedUri)) // validate is URI { throw new ArgumentException("uri", "The uri parameter must be a valid absolute URI path"); } var feedObj = Load(feedUri); var feedDTO = new FeedDTO() { Name = feedObj.Title.Text, Description = feedObj.Description.Text, Feed = feedUri, Link = feedObj.Links.Any(o => o.RelationshipType.Equals("alternate", StringComparison.InvariantCultureIgnoreCase)) ? feedObj.Links.First(o => o.RelationshipType.Equals("alternate", StringComparison.InvariantCultureIgnoreCase)).Uri : null }; var id = _feedRepository.Add(feedDTO); return(feedDTO); }
public void Given_a_new_rss_uri_should_add_feed_to_list_and_persist() { var persistence = new Mock <IPersistence>(); var feedRepo = new FeedRepository(persistence.Object); var rssUri = new Uri("protocol://host/uri.rss"); Feed.Downloader = (u, cb) => { if (u == rssUri) { cb(false, null, @"<?xml version=""1.0"" encoding=""UTF-8""?> <rss xmlns:itunes=""http://www.itunes.com/dtds/podcast-1.0.dtd"" xmlns:atom=""http://www.w3.org/2005/Atom"" version=""2.0""> <channel> <title>My New Feed</title> <item> <title>Whistle</title> <guid isPermaLink=""true"">item1</guid> <enclosure url=""http://blockedcontent/whistle.mp3"" type=""audio/mp3"" /> </item> </channel> </rss>"); } }; feedRepo.Add(rssUri); Assert.AreEqual(1, feedRepo.Feeds.Count); Assert.AreEqual("My New Feed", feedRepo.Feeds[0].Name); persistence.Verify(p => p.WriteTextFile(It.IsAny <string>(), It.Is <string>(contents => ContainsFeedDetails(contents, "My New Feed", "item1")))); }
public bool AddFeed(string feedUrl, string feedName) { FeedRepository rep = new FeedRepository(); Feed feed = new Feed { URL = feedUrl, Name = feedName, Active = true, LastReadTime = null }; try { rep.Add(feed); return(true); } catch { return(false); } }
public async Task <ActionResult <Feed> > Post(Feed feed) { await _feedRepository.Add(feed); return(CreatedAtAction("Get", new { id = feed.Code }, feed)); }