Пример #1
0
        private static KeyValuePair<string, Article> GetUriArticlePair(string uri, SyndicationItem item)
        {
            string subject = item.Title.Text;
            string summary = item.Summary.Text;
            var authors = new List<Author>(item.Authors.Count);
            authors.AddRange(item.Authors.Select(author => new Author(author.Name, author.Email)));

            string articleContent = "";
            foreach (SyndicationElementExtension ext in item.ElementExtensions)
            {
                if (ext.GetObject<XElement>().Name.LocalName == "encoded")
                {
                    articleContent = ext.GetObject<XElement>().Value;
                }
            }

            var content = new Content(articleContent, "Html");
            DateTime lastUpdateTime = item.LastUpdatedTime.DateTime;
            DateTime publishDate = item.PublishDate.DateTime;

            var article = new Article(item.Id, uri, subject, item.Title.Text, summary, authors, lastUpdateTime, publishDate,
                                      content);
            var key = string.Format("{0}.{1}", uri, item.Id);

            return new KeyValuePair<string, Article>(key, article);
        }
Пример #2
0
        public void TestCanInsertArticle()
        {
            string id1 = "Id1" + Guid.NewGuid();
            string id2 = "Id2" + Guid.NewGuid();
            string source = "CassandraUri" + Guid.NewGuid();
            List<Author> authors = new List<Author>() { { new Author("Adi", "*****@*****.**") }, { new Author("Francky", "*****@*****.**") } };

            Article article1 = new Article(id1, source, "Learn Cassandra For Dummies", "Cassandra in Depth",
                "Learn to use and setup a NoSQL database", authors, (new DateTime(2013, 3, 4)), (new DateTime(2012, 12, 10)), new Content("blablablablabla", "html"));

            Article article2 = new Article(id2, source, "Cassandra Cookbook", "Cassandra Cookbook",
               "Configure a NoSQL database for advanced users", authors, (new DateTime(2013, 5, 15)), (new DateTime(2013, 2, 3)), new Content("blablablablabla2", "html"));

            _database.InsertArticle(article1);
            _database.InsertArticle(article2);

            Article[] results = null;
            Assert.DoesNotThrow(() => results =_database.GetArticles(source).ToArray());

            Assert.AreEqual(2, results.Length);
            Assert.AreEqual(article1, results[0]);
            Assert.AreEqual(article2, results[1]);
        }
Пример #3
0
        private bool Equals(Article other)
        {
            bool authorsEquals = Authors.Count == other.Authors.Count;
            if (!authorsEquals) return false;

            for(int i=0; i<Authors.Count; i++)
            {
                authorsEquals = Authors[i].Equals(other.Authors[i]);
                if (!authorsEquals) return false;
            }

            return string.Equals(Id, other.Id) && string.Equals(Source, other.Source) && string.Equals(Subject, other.Subject)
                && string.Equals(Title, other.Title) && PublishDate.Equals(other.PublishDate) && LastUpdateTime.Equals(other.LastUpdateTime)
                && Content.Equals(other.Content) && authorsEquals && string.Equals(Summary, other.Summary);
        }