public void GetAllNews_ShouldReturnAllNews()
        {
            var context = new NewsContext();
            context.News.Delete();
            var firstNews = new Models.News()
            {
                Title = "Murder",
                Content = "A man was slaughterd in Sofia last night.",
                PublishDate = DateTime.Now
            };
            context.News.Add(firstNews);
            var secNews = new Models.News()
            {
                Title = "Eros Ramazzotti",
                Content = "Ramazzotti will sing in Sofia in September",
                PublishDate = DateTime.Now
            };
            context.News.Add(secNews);
            context.SaveChanges();
            var repo = new NewsRepository(context);
            var newsFromDB = repo.All().ToArray();
            Assert.IsNotNull(newsFromDB[0]);
            Assert.AreEqual(firstNews.Title, newsFromDB[0].Title);
            Assert.AreEqual(firstNews.Content, newsFromDB[0].Content);
            Assert.AreEqual(firstNews.PublishDate, newsFromDB[0].PublishDate);
            Assert.IsTrue(newsFromDB[0].Id != 0);

            Assert.IsNotNull(newsFromDB[1]);
            Assert.AreEqual(secNews.Title, newsFromDB[1].Title);
            Assert.AreEqual(secNews.Content, newsFromDB[1].Content);
            Assert.AreEqual(secNews.PublishDate, newsFromDB[1].PublishDate);
            Assert.IsTrue(newsFromDB[1].Id != 0);
        }
        public void ListAllItems_WhenListedCorrectly_ShouldReturnAllItems()
        {
            var repo = new NewsRepository(new NewsEntities());
            var news = repo.All();

            Assert.AreEqual(3, news.Count());

            var testedNews = news.Where(n => n.Title == "News1").FirstOrDefault();

            Assert.AreEqual("News1", testedNews.Title);
            Assert.AreEqual("Content1", testedNews.Content);
            Assert.AreEqual(new DateTime(2015, 1, 20).ToShortDateString(),
                            testedNews.PublishDate.ToShortDateString());

            testedNews = news.Where(n => n.Title == "News2").FirstOrDefault();
            Assert.AreEqual("News2", testedNews.Title);
            Assert.AreEqual("Content2", testedNews.Content);
            Assert.AreEqual(new DateTime(2015, 1, 21).ToShortDateString(),
                            testedNews.PublishDate.ToShortDateString());

            testedNews = news.Where(n => n.Title == "News3").FirstOrDefault();
            Assert.AreEqual("News3", testedNews.Title);
            Assert.AreEqual("Content3", testedNews.Content);
            Assert.AreEqual(new DateTime(2015, 1, 20).ToShortDateString(),
                            testedNews.PublishDate.ToShortDateString());
        }
        public void UpdateNews_WhenNewsIsInvalid_ShouldThrowException()
        {
            var repo = new NewsRepository(new NewsEntities());
            var news = repo.All().Where(n => n.Title == "News1").FirstOrDefault();

            news.Content = null;
            repo.Update(news);
            repo.SaveChanges();
        }
        public void DeleteNews_WhenNewsIsValid_ShouldDeleteNews()
        {
            var repo = new NewsRepository(new NewsEntities());
            var news = repo.All().Where(n => n.Title == "News1").FirstOrDefault();

            repo.Delete(news);
            repo.SaveChanges();

            var newsFromRepo = repo.Find(news.Id);

            Assert.AreEqual(null, newsFromRepo);
        }
        public void TestListAll()
        {
            newsRepo.All().Delete();
            newsRepo.SaveChanges();
            CollectionAssert.AreEquivalent(new List <News>(), newsRepo.All().ToList());
            Assert.AreEqual(0, newsRepo.All().Count());

            var news1 = new News {
                Title = "Zaglavie", Content = "dadadada"
            };
            var news2 = new News {
                Title = "Teadsad", Content = "koko6ki"
            };
            var news3 = new News {
                Title = "Asdjoqwe", Content = "asodojk"
            };

            newsRepo.Add(news1);
            newsRepo.Add(news2);
            newsRepo.Add(news3);
            newsRepo.SaveChanges();

            CollectionAssert.AreEquivalent(new[] { news1, news2, news3 }, newsRepo.All().ToList());
            Assert.AreEqual(3, newsRepo.All().Count());
        }
        public void UpdateNews_WhenNewsIsValid_ShouldUpdateNews()
        {
            var repo = new NewsRepository(new NewsEntities());
            var news = repo.All().Where(n => n.Title == "News1").FirstOrDefault();

            news.Title = "Azis e...folkpevets";
            repo.Update(news);
            repo.SaveChanges();

            var newsFromRepo = repo.Find(news.Id);

            Assert.AreEqual(newsFromRepo.Title, "Azis e...folkpevets");
        }
        public void InsertNews_WhenInsertedCorrectly_ShouldReturnNews()
        {
            var repo = new NewsRepository(new NewsEntities());
            var news = new News.Models.News()
            {
                Title       = "TestNews",
                Content     = "TestNewsContent",
                PublishDate = new DateTime(2015, 05, 10)
            };

            repo.Add(news);
            repo.SaveChanges();

            var newsFromDb = repo.Find(news.Id);

            Assert.AreEqual(4, repo.All().Count());
            Assert.AreEqual(news.Title, newsFromDb.Title);
            Assert.AreEqual(news.Content, newsFromDb.Content);
            Assert.AreEqual(news.PublishDate.ToShortDateString(),
                            newsFromDb.PublishDate.ToShortDateString());
            Assert.AreNotEqual(0, newsFromDb.Id);
        }
 public void DeleteNews_WhenDeletingExistingNews_ShouldDeleteNews()
 {
     var context = new NewsContext();
     context.News.Delete();
     var news = new Models.News()
     {
         Title = "Murder",
         Content = "A man was slaughterd in Sofia last night.",
         PublishDate = DateTime.Now
     };
     context.News.Add(news);
     context.SaveChanges();
     var repo = new NewsRepository(context);
     repo.Delete(news);
     repo.SaveChanges();
     var newsFromDb = repo.All().ToArray();
     Assert.AreEqual(0, newsFromDb.Count());
 }