Пример #1
0
        public void ParseDate_WhenCalled_ReturnValidDateTime()
        {
            //Arrange
            var date = "Sat, 26 Jan 2019 18:23:09 GMT";

            //Act
            var result = _sut.ParseDate(date);

            //Assert
            Assert.IsType <DateTime>(result);
        }
Пример #2
0
        public IEnumerable <FeedItem> GetAllNews(string url)
        {
            try
            {
                //Get the content from the url
                var urlContent = _httpDownload.DownloadPage(url);

                //extract feed items
                var doc = XDocument.Parse(urlContent.Result);

                if (doc.Root != null)
                {
                    var feedItems = from item in doc.Root.Descendants().First(i => i.Name.LocalName == "channel").Elements().Where(i => i.Name.LocalName == "item")
                                    select new FeedItem
                    {
                        Content     = item.Elements().First(i => i.Name.LocalName == "description").Value,
                        Link        = item.Elements().First(i => i.Name.LocalName == "link").Value,
                        PublishDate = _dateParser.ParseDate(item.Elements().First(i => i.Name.LocalName == "pubDate").Value),
                        Title       = item.Elements().First(i => i.Name.LocalName == "title").Value
                    };

                    return(feedItems);
                }

                return(new List <FeedItem>());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(new List <FeedItem>());
            }
        }