public ActionResult NewsDetail(int id) { var news = nr.Get(id) ?? new News(); ViewBag.NewsCategories = nr.GetAllCategories().Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Title, Selected = c.Id == news.CategoryId }); return(View(news)); }
public void Get_ItemNotDerivedFromNewsFolderTemplate_ThrowArgumentNullException([Frozen] ISearchServiceRepository searchServiceRepository, [Frozen] ISearchSettings searchSettings, Item contextItem) { var repo = new NewsRepository(searchServiceRepository); Action act = () => repo.Get(contextItem); act.ShouldThrow <ArgumentException>(); }
public void Get_NullAs1Parameter_ThrowArgumentNullException([Frozen] ISearchServiceRepository searchServiceRepository, [Frozen] ISearchSettings searchSettings) { var repo = new NewsRepository(searchServiceRepository); Action act = () => repo.Get(null); act.ShouldThrow <ArgumentException>(); }
/// <summary> /// 用户点击收藏操作 /// </summary> /// <returns></returns> public static Result <int> AddFavorite(MemberFavoriteModel ent) { var result = new Result <int>(); if (ent.UserId <= 0 || ent.NewsId <= 0) { result.Message = "无效的参数"; return(result); } var newsInfo = NewsRepository.Get(ent.NewsId); if (newsInfo == null || newsInfo.Id <= 0) { result.Message = "无效的数据"; return(result); } var favoriteCount = FavoriteRepository.Count(ent.UserId); if (favoriteCount >= 20) { result.Message = "最多只能收藏20条新闻"; return(result); } var newsCount = FavoriteRepository.Count(ent.UserId, ent.NewsId); if (newsCount >= 1) { result.Message = "请勿重复收藏"; return(result); } result.Code = ResultCode.Success; result.Data = FavoriteRepository.Add(ent); return(result); }
/// <summary> /// 获取新闻明细 /// </summary> /// <returns></returns> public static NewsModel Get(int id) { if (id <= 0) { return(null); } return(NewsRepository.Get(id)); }
private void RemoveCategories(News entity) { var oldEntityCount = _entityRepository.Get(entity.Id, false, new List <string>() { "CategoryList" }).CategoryList.Count(); for (int i = 0; i < oldEntityCount; i++) { var tempEntity = _entityRepository.Get(entity.Id, false, new List <string>() { "CategoryList" }); tempEntity.CategoryList.RemoveAt(0); _entityRepository.SaveChange(); } }
public ActionResult Detail(int id) { var news = nr.Get(id); ViewBag.Cid = news.CategoryId; news.ReadCount++; nr.Update(news); return(View(news)); }
public async void Repository_IdIsNotFound() { var repository = new NewsRepository(); httpTest.RespondWith("error", 500); //httpTest.RespondWithJson(new Body() { Response = new Response() { Content = new Content() { ApiUrl = "ApiUrl" } } }, 200); var sut = await repository.Get("1"); sut.Content.ApiUrl.Should().Be("xApiUrl"); }
public IActionResult Get(int id) { var data = _repo.Get(id); if (data != null) { return(Ok(data)); } else { return(BadRequest()); } }
public IEnumerable <NewsEntity> GetAllNews() { var newsList = newsRepository.Get(); List <NewsEntity> newsEntities = null; if (newsList != null) { newsEntities = new List <NewsEntity>(); foreach (var item in newsList) { NewsEntity entity = new NewsEntity(); entity.NewsId = item.NewsId; entity.Title = item.Title; entity.Abstract = item.Abstract; entity.News = item.News1; entity.AirDate = item.AirDate; entity.ImagePath = item.ImagePath; newsEntities.Add(entity); } } return(newsEntities); }
public void Get_ReturnsListOfNews([Frozen] ISearchServiceRepository searchServiceRepository, [Frozen] ISearchSettingsRepository searchSettingsRepository, string itemName, [Substitute] SearchService searchService) { var id = ID.NewID; searchServiceRepository.Get().Returns(searchService); var db = new Db { new DbItem(itemName, id, Templates.NewsFolder.ID) }; var contextItem = db.GetItem(id); var repository = new NewsRepository(contextItem, searchServiceRepository); var news = repository.Get(); news.Should().As <IEnumerable <Item> >(); }
public News Get(int id) { return(_newsRepository.Get(id)); }
public ActionResult UpdateNews(int id) { var obj = _news.Get(id); return(View(obj)); }
public void GetsAllNewsItems() { _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 5)); var contentfulNewsRoom = new ContentfulNewsRoom { Title = "test" }; var newsRoom = new Newsroom(_alerts, true, "test-id"); _newsRoomContentfulFactory.Setup(o => o.ToModel(It.IsAny <ContentfulNewsRoom>())).Returns(newsRoom); var news = new News(Title, Slug, Teaser, Purpose, Image, ThumbnailImage, Body, _sunriseDate, _sunsetDate, _crumbs, _alerts, new List <string>() { "tag1", "tag2" }, new List <Document>(), _newsCategories); _newsContentfulFactory.Setup(o => o.ToModel(It.IsAny <ContentfulNews>())).Returns(news); var newsListCollection = new ContentfulCollection <ContentfulNews>(); newsListCollection.Items = new List <ContentfulNews> { new ContentfulNewsBuilder().Title("Another news article").Slug("another-news-article").Teaser("This is another news article").SunriseDate(new DateTime(2016, 06, 30, 23, 0, 0, DateTimeKind.Utc)).SunsetDate(new DateTime(2017, 11, 22, 23, 0, 0, DateTimeKind.Utc)).Build(), new ContentfulNewsBuilder().Title("This is the news").Slug("news-of-the-century").Teaser("Read more for the news").SunriseDate(new DateTime(2016, 08, 24, 23, 30, 0, DateTimeKind.Utc)).SunsetDate(new DateTime(2016, 08, 23, 23, 0, 0, DateTimeKind.Utc)).Build(), }; _client.Setup(o => o.GetEntries <ContentfulNews>( It.Is <string>(q => q.Contains(new QueryBuilder <ContentfulNews>().ContentTypeIs("news").Include(1).Build())), It.IsAny <CancellationToken>())).ReturnsAsync(newsListCollection); _cacheWrapper.Setup(_ => _.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "news-all"), It.IsAny <Func <Task <IList <ContentfulNews> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(newsListCollection.Items.ToList()); _cacheWrapper.Setup(_ => _.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "newsroom"), It.IsAny <Func <Task <ContentfulNewsRoom> > >(), It.Is <int>(s => s == 60))).ReturnsAsync(contentfulNewsRoom); _cacheWrapper.Setup(_ => _.GetFromCacheOrDirectlyAsync(It.Is <string>(s => s == "news-categories"), It.IsAny <Func <Task <List <string> > > >(), It.Is <int>(s => s == 60))).ReturnsAsync(new List <string> { "Benefits", "foo", "Council leader" }); _videoRepository.Setup(o => o.Process(It.IsAny <string>())).Returns("The news"); var response = AsyncTestHelper.Resolve(_repository.Get(null, null, null, null)); response.StatusCode.Should().Be(HttpStatusCode.OK); var newsroom = response.Get <Newsroom>(); newsroom.Alerts.Count.Should().Be(1); newsroom.Alerts[0].Title.Should().BeEquivalentTo(_alerts[0].Title); newsroom.EmailAlerts.Should().Be(true); newsroom.EmailAlertsTopicId.Should().Be("test-id"); newsroom.Categories.Count.Should().Be(3); newsroom.Categories.First().Should().Be("Benefits"); newsroom.Categories.Last().Should().Be("Council leader"); newsroom.Dates.Should().HaveCount(1); newsroom.Dates[0].Should().HaveMonth(8); newsroom.Dates[0].Should().HaveYear(2016); newsroom.News.Count.Should().Be(2); var firstNews = newsroom.News.First(); firstNews.Title.Should().Be(Title); firstNews.Body.Should().Be(Body); firstNews.Slug.Should().Be(Slug); firstNews.Teaser.Should().Be(Teaser); firstNews.SunriseDate.Should().Be(_sunriseDate); firstNews.SunsetDate.Should().Be(_sunsetDate); firstNews.Image.Should().Be(Image); firstNews.ThumbnailImage.Should().Be(ThumbnailImage); firstNews.Breadcrumbs.Should().BeEquivalentTo(_crumbs); firstNews.Alerts.Should().BeEquivalentTo(_alerts); firstNews.Categories.Count.Should().Be(2); firstNews.Categories[0].Should().Be("news-category-1"); firstNews.Categories[1].Should().Be("news-category-2"); }