public void List_NewsRecords_Should_Return_Correct_List()
        {
            //Arrange
            NewsRepository repo = new NewsRepository(new NewsContext());
            var countBeforeAdding = repo.GetAll().Count();

            var news = new NewsRecord()
            {
                Title = "HardShit",
                Content = "Hard Shit in the mix",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };
            var news2 = new NewsRecord()
            {
                Title = "SmokeShit",
                Content = "Smoke Shit in the mix",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

            var listNews = new List<NewsRecord>();
            listNews.Add(news);
            listNews.Add(news2);

            var newsBeforeAdd = repo.GetAll()
               .Select(n => n.Title)
               .ToList();

            var fakeNewsTitles = listNews
                .Select(n => n.Title)
                .ToList();

            fakeNewsTitles.AddRange(newsBeforeAdd);
            fakeNewsTitles.Sort();

            var fakeNewsTitlesOrd = fakeNewsTitles;
                 

            //Act
            repo.Add(news);
            repo.Add(news2);
            repo.SaveChanges();

            var allNews = repo.GetAll()
                .OrderBy(n => n.Title)
                .Select(n => n.Title)
                .ToList();

            //Assert
            Assert.AreEqual(2 + countBeforeAdding, repo.GetAll().Count());
            CollectionAssert.AreEqual(fakeNewsTitlesOrd, allNews);
        }
        public IActionResult GetNews()
        {
            // block access until data is loaded

            lock (_lockMe) {
                if (newsDTO.Count() > 0)
                {
                    return(Ok(newsDTO.OrderBy(x => x.Author)));
                }

                var data = _repo.GetAll();
                if (data != null)
                {
                    foreach (var n in data)
                    {
                        newsDTO.Add(new NewsDTO
                        {
                            Author = n.Author,
                            Title  = n.Title
                        });
                    }
                    return(Ok(newsDTO.OrderBy(x => x.Author)));
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Ejemplo n.º 3
0
        public PartialViewResult News(int?newsCategoryId, int?page)
        {
            var items = newsCategoryId != null
                ? NewsRepository.GetAllByNewsCategoryId(newsCategoryId.Value).Select(x => x.ToViewModel())
                : NewsRepository.GetAll().Where(x => !x.IsDeleted).Select(x => x.ToViewModel());

            return(PartialView("~/Views/Home/_News.cshtml", items.ToPagedList(page ?? 1, TechOfficeConfig.PAGESIZE)));
        }
Ejemplo n.º 4
0
        public static List <News> GetLastNews()
        {
            INewsRepository newsRepo = new NewsRepository();
            var             lastNews = new List <News>();
            var             allNews  = newsRepo.GetAll().Where(n => n.IsDeleted).OrderByDescending(n => n.DateCreated).ToList();

            foreach (var item in allNews)
            {
                if (lastNews.Count >= 5)
                {
                    continue;
                }
                lastNews.Add(item);
            }
            return(lastNews);
        }
Ejemplo n.º 5
0
 public async Task <IActionResult> Search()
 {
     try
     {
         var links = _repo.GetAll();
         return(Ok(await links.ToListAsync()));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed to get all links: {ex.Message}");
         return(new ExceptionResult(ex, true)
         {
             StatusCode = 204
         });
     }
 }
Ejemplo n.º 6
0
        public ActionResult TestSearch()
        {
            var seg = new JiebaSegmenter();

            seg.AddWord("机器学习");

            NewsSearcher.ClearLuceneIndex();

            var data = NewsRepository.GetAll();

            NewsSearcher.UpdateLuceneIndex(data);

            var results = NewsSearcher.Search("方法研究");


            return(View(results));
        }
Ejemplo n.º 7
0
        public static List <News> GetAll()
        {
            var             pathNewsPhoto    = ConfigurationManager.AppSettings["pathNewsPhoto"];
            var             pathDefaultPhoto = ConfigurationManager.AppSettings["pathDefaultPhoto"];
            INewsRepository newsRepo         = new NewsRepository();
            var             allNews          = newsRepo.GetAll().ToList();

            foreach (var item in allNews)
            {
                if (item.HeadImage != "")
                {
                    item.HeadImage = pathNewsPhoto + item.HeadImage;
                }
                else
                {
                    item.HeadImage = pathDefaultPhoto;
                }
            }
            return(allNews);
        }
Ejemplo n.º 8
0
        public static List <News> GetAll(PaginationParameters pagination, bool allOrActivated)
        {
            var             pathNewsPhoto    = ConfigurationManager.AppSettings["pathNewsPhoto"];
            var             pathDefaultPhoto = ConfigurationManager.AppSettings["pathDefaultPhoto"];
            INewsRepository newsRepo         = new NewsRepository();
            var             allNews          = (allOrActivated)? newsRepo.GetAll(pagination).ToList(): newsRepo.GetAllActivated(pagination).ToList();

            foreach (var item in allNews)
            {
                if (item.HeadImage != "" && item.HeadImage != null)
                {
                    item.HeadImage = pathNewsPhoto + item.HeadImage;
                }
                else
                {
                    item.HeadImage = pathDefaultPhoto;
                }
            }
            return(allNews);
        }
        public void Modify_Non_Existing_Data_Should_Throw_Exception()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Id == 1500);
            newsFromDB.Title = "Ihaaaaa";

            repo.Update(newsFromDB);
            repo.SaveChanges();
        }
        public void Modify_Existing_Data_With_Incorrect_Data_Should_Throw_Exception()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());
            var news = new NewsRecord()
            {
                Title = "UnModifiedShit",
                Content = "See me updated",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

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

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Title == "UnModifiedShit");
            newsFromDB.Title = "";

            repo.Update(news);
            repo.SaveChanges();
        }
        public void Modify_Existing_Data_Should_Update_The_Data()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());
            var news = new NewsRecord()
            {
                Title = "UnModifiedShit",
                Content = "See me updated",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

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

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Title == "UnModifiedShit");
            newsFromDB.Title = "ModifiedShit";

            repo.Update(news);
            repo.SaveChanges();

            var changedNews = repo.GetAll().FirstOrDefault(n => n.Title == "ModifiedShit");

            Assert.AreEqual("ModifiedShit", changedNews.Title);
        }
Ejemplo n.º 12
0
        //
        // GET: /Default1/

        public ViewResult Index()
        {
            return(View(NewsRepository.GetAll()));
        }
Ejemplo n.º 13
0
        [HttpGet("getall")] // api/news GET
        public IActionResult GetAll()
        {
            var a = _newsRepository.GetAll();

            return(Ok(a));
        }
Ejemplo n.º 14
0
        public ActionResult Index()
        {
            var all = NewsRepository.GetAll();

            return(View(all));
        }
Ejemplo n.º 15
0
        public IActionResult GetAll()
        {
            IEnumerable <News> news = _newsRepository.GetAll();

            return(Ok(news));
        }
Ejemplo n.º 16
0
 public ActionResult Index()
 {
     ViewBag.News = NewsRepository.GetAll();
     return(View());
 }
Ejemplo n.º 17
0
        public async Task ShouldReturnListOfNews()
        {
            var result = await sut.GetAll();

            Assert.That(result.Count > 0);
        }
Ejemplo n.º 18
0
 // GET: News
 public ActionResult Index()
 {
     return(View(news.GetAll()));
 }
        public void Delete_Existing_Data_Should_Delete_The_Data()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());
            var news = new NewsRecord()
            {
                Title = "UnModifiedShit",
                Content = "See me updated",
                PublishDate = new DateTime(2015, 08, 30, 14, 04, 30)
            };

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

            var countBeforeDeletion = repo.GetAll().Count();

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Title == "UnModifiedShit");
            repo.Delete(newsFromDB);
            repo.SaveChanges();

            Assert.AreEqual(countBeforeDeletion - 1, repo.GetAll().Count());
        }
Ejemplo n.º 20
0
 public IEnumerable <News> GetAllNews()
 {
     return(NewsRepository.GetAll());
 }
Ejemplo n.º 21
0
 public ActionResult News()
 {
     return(View(NewsRepository.GetAll()));
 }
Ejemplo n.º 22
0
 public IQueryable <EntityModel.News> GetAll()
 {
     return(_newsRepository.GetAll());
 }
Ejemplo n.º 23
0
 // GET api/newsApi/
 public IEnumerable <News> GetAll()
 {
     return((List <News>)newsRepository.GetAll());
 }
        public void Delete_Non_Existing_Data_Should_Throw_Exception()
        {
            NewsRepository repo = new NewsRepository(new NewsContext());

            var newsFromDB = repo.GetAll().FirstOrDefault(n => n.Id == 1500);

            repo.Delete(newsFromDB);
            repo.SaveChanges();

        }
Ejemplo n.º 25
0
 public ActionResult <IEnumerable <News> > Get()
 {
     return(_newsRepository.GetAll().ToList());
 }
Ejemplo n.º 26
0
 public List <News> GetAll()
 {
     return(NewsRepository.GetAll());
 }
Ejemplo n.º 27
0
        public IActionResult Index()
        {
            var model = _newsRepository.GetAll();

            return(View(model));
        }