Пример #1
0
        public void AddANewsWithoutTitle_RepoAddSaveChanges_ShouldThrоwDbEntityValidationException()
        {
            var news = new TempNews()
            {
                Content       = "Niama takiva",
                PublishedDate = DateTime.Now.ToString("D")
            };

            var context = new Repository <TempNews>(new NewsContext());

            context.Add(news);
            context.SaveChanges();
        }
Пример #2
0
        public ActionResult HomeNews()
        {
            var tempNews = new TempNews()
            {
                CanadaNews  = NewsProject.ExecuteNews.News.GetByGroupPaging(SessionDecentralize(), (short)Common.MenuKeyWord.Canada, 1, 5).List,
                JapanNews   = NewsProject.ExecuteNews.News.GetByGroupPaging(SessionDecentralize(), (short)Common.MenuKeyWord.Japan, 1, 5).List,
                GermanyNews = NewsProject.ExecuteNews.News.GetByGroupPaging(SessionDecentralize(), (short)Common.MenuKeyWord.Germany, 1, 5).List,
                KoreaNews   = NewsProject.ExecuteNews.News.GetByGroupPaging(SessionDecentralize(), (short)Common.MenuKeyWord.Korea, 1, 5).List,
                TaiwanNews  = NewsProject.ExecuteNews.News.GetByGroupPaging(SessionDecentralize(), (short)Common.MenuKeyWord.Taiwan, 1, 5).List,
                JobNews     = NewsProject.ExecuteNews.News.GetByGroupPaging(SessionDecentralize(), (short)Common.MenuKeyWord.Job, 1, 10).List,
                OrderNews   = NewsProject.ExecuteNews.News.GetAll(SessionDecentralize()).List.OrderByDescending(p => p.Order).Take(10).ToList(),
                NewNews     = NewsProject.ExecuteNews.News.GetAllPaging(SessionDecentralize(), 1, 10).List,
                ViewsNews   = NewsProject.ExecuteNews.News.GetAll(SessionDecentralize()).List.OrderByDescending(p => p.View).Take(10).ToList()
            };

            var groups = NewsProject.ExecuteNews.Group.GetByPaging(0, (short)Common.PageSize.Small);

            ViewData["Groups"] = groups;
            return(View("HomeNews", tempNews));
        }
Пример #3
0
        public void AddANews_RepoAddFindSaveChanges_ShouldCreateAndReturnTheNewsFromDb()
        {
            var news = new TempNews()
            {
                Title         = "Sport",
                Content       = "Dnes...",
                PublishedDate = DateTime.Now.ToString("D")
            };

            var context = new Repository <TempNews>(new NewsContext());

            context.Add(news);
            context.SaveChanges();

            var findNews = context.Find(news.Id);

            Assert.AreEqual(news.Id, findNews.Id);
            Assert.AreEqual(news.Title, findNews.Title);
            Assert.AreEqual(news.Content, findNews.Content);
        }
Пример #4
0
        public void ListAllNews_RepoAllAddSaveChanges_ShouldReturnAllNewsCount()
        {
            var news = new TempNews()
            {
                Title         = "Novinite dnes",
                Content       = "Niama takiva",
                PublishedDate = DateTime.Now.ToString("D")
            };

            var context = new Repository <TempNews>(new NewsContext());

            var count = context.All().Count();

            context.Add(news);

            context.SaveChanges();

            var newCount = context.All().Count();

            Assert.AreEqual(count + 1, newCount);
        }
Пример #5
0
        public void DeleteExistingNews_RepoDelete_ShouldDeleteTheNews()
        {
            var news = new TempNews()
            {
                Title         = "Sport",
                Content       = "Dnes...",
                PublishedDate = DateTime.Now.ToString("D")
            };

            var context = new Repository <TempNews>(new NewsContext());

            context.Add(news);
            context.SaveChanges();

            var findNews = context.Find(news.Id);

            context.Delete(findNews);
            context.SaveChanges();
            var findNewsAfterDelete = context.Find(news.Id);

            Assert.IsNull(findNewsAfterDelete);
        }
Пример #6
0
        public void EditExistingNews_RepoAddSaveChangesFindUpdate_ShouldThrоwDbEntityValidationException()
        {
            var news = new TempNews()
            {
                Title         = "Sport",
                Content       = "Dnes...",
                PublishedDate = DateTime.Now.ToString("D")
            };

            var context = new Repository <TempNews>(new NewsContext());

            context.Add(news);
            context.SaveChanges();

            var findNews = context.Find(news.Id);

            findNews.Content = "D";

            context.Update(findNews);

            context.SaveChanges();
        }
Пример #7
0
        public void EditExistingNews_RepoAddUpdateSaveChanges_ShouldBeModified()
        {
            var news = new TempNews()
            {
                Title         = "Sport",
                Content       = "Dnes...",
                PublishedDate = DateTime.Now.ToString("D")
            };

            var context = new Repository <TempNews>(new NewsContext());

            context.Add(news);
            context.SaveChanges();

            var findNews = context.Find(news.Id);

            findNews.Title = "Vremeto";

            context.Update(findNews);

            context.SaveChanges();

            Assert.AreEqual("Vremeto", findNews.Title);
        }