Exemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="htmlHelper"></param>
 /// <param name="takeCount"></param>
 /// <returns></returns>
 public static IEnumerable<TB_News> GetNewsItemsOrderByDesc(this HtmlHelper htmlHelper, int takeCount)
 {
     using (var db = new NewsRepository())
     {
         return db.Find<TB_News>(s => s.IsDelete == false)
             .OrderByDescending(desc => desc.PostDateTime)
             .Take(takeCount).ToList();
     }
 }
        public void TestAddValidNewsToDb()
        {
            var news = new News
            {
                Title   = "Test News",
                Content = "This is very important"
            };

            newsRepo.Add(news);
            newsRepo.SaveChanges();

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

            Assert.IsNotNull(newsFromDb);
            Assert.AreEqual(news.Title, newsFromDb.Title);
            Assert.AreEqual(news.Content, newsFromDb.Content);
            Assert.AreEqual(news.PublishDate, newsFromDb.PublishDate);
            Assert.IsTrue(newsFromDb.Id != 0);
        }
        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 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 ModifyExistingNewsWithCorrectData()
        {
            var repo = new NewsRepository(new NewsContext());

            var newsFromDb = repo.Find(1);

            newsFromDb.Title = "Edited Title";
            newsFromDb.Content = "Some new content";

            repo.SaveChanges();

            Assert.IsNotNull(newsFromDb);
            Assert.AreEqual(newsFromDb.Title, "Edited Title");
            Assert.AreEqual(newsFromDb.Content, "Some new content");
            Assert.AreEqual(1, newsFromDb.Id);
        }
        public void GetAllNewsReturnNewsShouldReturnCorrectly()
        {
            var repo = new NewsRepository(new NewsContext());

            var news = new News
            {
                Title = "Test Title",
                Content = "Some test content.",
                PublishedDate = DateTime.Now
            };
            repo.Add(news);
            repo.SaveChanges();

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

            Assert.IsNotNull(newsDb);
            Assert.AreEqual(news.Title, newsDb.Title);
            Assert.AreEqual(news.Content, newsDb.Content);
            Assert.AreEqual(news.PublishedDate, newsDb.PublishedDate);
        }
        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 ModifyExistingNewsWithIncorrectData()
        {
            var repo = new NewsRepository(new NewsContext());

            var newsFromDb = repo.Find(1);

            newsFromDb.Title = null;

            repo.SaveChanges();
        }
        public void TryToDeleteNonExistingNews()
        {
            var repo = new NewsRepository(new NewsContext());

            var newsFromDb = repo.Find(5);

            repo.Delete(newsFromDb);
        }
Exemplo n.º 10
0
        public void DeleteExistingNews()
        {
            var repo = new NewsRepository(new NewsContext());

            var newsFromDb = repo.Find(1);

            repo.Delete(newsFromDb);
            repo.SaveChanges();

            Assert.IsNull(repo.Find(1));
        }
        public void CreateNews_WhenNewsIsAddedToDbWithCorrectData_ShouldReturnNews()
        {
            // Arrange -> prapare the objects

            var repo = new NewsRepository(new NewsContext());
            var news = new Models.News()
            {
                Title = "Sample New News",
                PublishDate = DateTime.Now,
                Content = "Sample New News Content"
            };

            // Act -> perform some logic
            repo.Add(news);
            repo.SaveChanges();

            // Assert -> validate the results
            var newsFromDb = repo.Find(news.Id);

            Assert.IsNotNull(newsFromDb);
            Assert.AreEqual(news.Title, newsFromDb.Title);
            Assert.AreEqual(news.Content, newsFromDb.Content);
            Assert.AreEqual(news.PublishDate, newsFromDb.PublishDate);
            Assert.IsTrue(newsFromDb.Id != 0);
        }
 public void ModifyNews_WhenModifingNonExistingNews_ShouldThrowException()
 {
     var context = new NewsContext();
     context.News.Delete();
     context.SaveChanges();
     var repo = new NewsRepository(context);
     var newsToChange = repo.Find(1);
     newsToChange.Title = "New title";
     repo.SaveChanges();
 }
 public void ModifyNews_WhenExistingNewsIsModifiedWithIncorrectData_ShouldThrowException()
 {
     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);
     var newsToChange = repo.Find(news.Id);
     newsToChange.Title = null;
     repo.SaveChanges();
 }
 public void ModifyNews_WhenExistingNewsIsModifiedWithCorrectData_ShouldReturnNews()
 {
     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);
     var newsToChange = repo.Find(news.Id);
     newsToChange.Title = "Murder committed last night";
     repo.SaveChanges();
     var newsFromDb = repo.Find(news.Id);
     Assert.IsNotNull(newsFromDb);
     Assert.AreEqual(newsToChange.Title, newsFromDb.Title);
     Assert.AreEqual(news.Content, newsFromDb.Content);
     Assert.AreEqual(news.PublishDate, newsFromDb.PublishDate);
     Assert.IsTrue(newsFromDb.Id != 0);
 }
Exemplo n.º 15
0
        public void ModifyNonExistingNewsShouldTrhowException()
        {
            var repo = new NewsRepository(new NewsContext());

            var newsFromDb = repo.Find(5);
            newsFromDb.Title = "NonExisting entity";
        }
Exemplo n.º 16
0
 public NewsDto GetNews(long id)
 {
     return(newsRepository.Find(x => x.Id == id).FirstOrDefault().ToModel <NewsDto>());
 }
 public void DeleteNews_WhenDeletingNonExistingNews_ShouldThrowException()
 {
     var context = new NewsContext();
     context.News.Delete();
     context.SaveChanges();
     var repo = new NewsRepository(context);
     var newsToDelete = repo.Find(1);
     repo.Delete(newsToDelete);
     repo.SaveChanges();
 }