public void ShouldReturnNotFoundForTagAndCategory() { _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 5)); 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(), }; _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(new ContentfulNewsRoom { Title = "test" }); var response = AsyncTestHelper.Resolve(_repository.Get("NotFound", "NotFound", null, null)); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public MainPage VerifyWebsiteLoadedCorectly() { _globaMethods.ScrollToWebElement(Produkty); Assert.Equal("PRODUKTY", Produkty.GetAttribute("innerText")); _globaMethods.ScrollToWebElement(Inwestorzy); Assert.Equal("INWESTORZY", Inwestorzy.GetAttribute("innerText")); _globaMethods.ScrollToWebElement(Kontakt); Assert.Equal("KONTAKT", Kontakt.GetAttribute("innerText")); _globaMethods.ScrollToWebElement(MedicalgorithmicsWLiczbach); Assert.Equal("Medicalgorithmics w liczbach", MedicalgorithmicsWLiczbach.GetAttribute("innerText")); _globaMethods.ScrollToWebElement(OstatnieAktualnosci); Assert.Equal("Ostatnie aktualności", OstatnieAktualnosci.GetAttribute("innerText")); _globaMethods.ScrollToWebElement(NajnowszeOfertyPracy); Assert.Equal("Najnowsze oferty pracy", NajnowszeOfertyPracy.GetAttribute("innerText")); _globaMethods.ScrollToWebElement(Newsroom); Assert.Equal("Newsroom", Newsroom.GetAttribute("innerText")); return(this); }
private NewsController SetUpController(int numNewsItems) { List <News> listofNewsItems = BuildNewsList(numNewsItems); var bigNewsRoom = new Newsroom( listofNewsItems, new OrderedList <Alert>(), EmailAlertsOn, EmailAlertsTopicId, new List <string>(), new List <DateTime>()); _repository.Setup(o => o.Get <Newsroom>( It.IsAny <string>(), It.IsAny <List <Query> >())) .ReturnsAsync(HttpResponse.Successful((int)HttpStatusCode.OK, bigNewsRoom)); var controller = new NewsController( _repository.Object, _processedContentRepository.Object, _mockRssFeedFactory.Object, _logger.Object, _config.Object, new BusinessId(BusinessId), _filteredUrl.Object ); return(controller); }
public void ShouldReturnNoListOfNewsForDateRange() { _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 09, 5)); var newsRoom = new Newsroom(_alerts, true, "test-id"); _newsRoomContentfulFactory.Setup(o => o.ToModel(It.IsAny <ContentfulNewsRoom>())).Returns(newsRoom); var news = new News("This is within the date Range", Slug, Teaser, Purpose, Image, ThumbnailImage, Body, _sunriseDate, _sunsetDate, _crumbs, _alerts, null, 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("This is within the date Range").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 within the date Range").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(new ContentfulNewsRoom { Title = "test" }); var response = AsyncTestHelper.Resolve(_repository.Get(tag: null, category: null, startDate: new DateTime(2017, 08, 01), endDate: new DateTime(2017, 08, 31))); var newsroom = response.Get <Newsroom>(); newsroom.News.Count.Should().Be(0); }
public void GetsAllNewsItemsWhenNoNewsroomIsPresent() { _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 5)); var newsRoom = new Newsroom(new List <Alert> { }, true, ""); _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, null, 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); _videoRepository.Setup(o => o.Process(It.IsAny <string>())).Returns("The news"); _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(new ContentfulNewsRoom { Title = "test" }); 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(0); newsroom.News.Count.Should().Be(2); newsroom.News.First().Title.Should().Be(Title); newsroom.News.First().Body.Should().Be(Body); newsroom.News.First().Slug.Should().Be(Slug); newsroom.News.First().Teaser.Should().Be(Teaser); newsroom.News.First().SunriseDate.Should().Be(_sunriseDate); newsroom.News.First().SunsetDate.Should().Be(_sunsetDate); newsroom.News.First().Image.Should().Be(Image); newsroom.News.First().ThumbnailImage.Should().Be(ThumbnailImage); newsroom.News.First().Breadcrumbs.Should().BeEquivalentTo(_crumbs); newsroom.News.First().Alerts.Should().BeEquivalentTo(_alerts); newsroom.Dates.Should().HaveCount(1); newsroom.Dates[0].Should().HaveMonth(8); newsroom.Dates[0].Should().HaveYear(2016); }
public void ShouldReturnNewsItemsWithTagsContainingMatchingTagsWithHash() { const string tag = "#testTag"; const string expectedTagQueryValue = "testTag"; _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 5)); 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>() { expectedTagQueryValue }, 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().Tags(new List <string> { "#testTag", "foo" }).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().Tags(new List <string> { "#testTag", "foo" }).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).FieldEquals("fields.tags[match]", "testTag").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(new ContentfulNewsRoom { Title = "test" }); // Act var response = AsyncTestHelper.Resolve(_repository.Get(tag, null, null, null)); var newsroom = response.Get <Newsroom>(); // Assert newsroom.News.Count.Should().Be(2); newsroom.News[1].Tags.Any(t => t == expectedTagQueryValue).Should().BeTrue(); }
public NewsControllerTest() { _newsRoom = new Newsroom(_listOfNewsItems, new OrderedList <Alert>(), EmailAlertsOn, EmailAlertsTopicId, new List <string>(), new List <DateTime>()); _emptyNewsRoom = new Newsroom(new List <News>(), new OrderedList <Alert>(), EmailAlertsOn, EmailAlertsTopicId, new List <string>(), new List <DateTime>()); // setup responses (with mock data) var responseListing = new HttpResponse(200, _newsRoom, ""); var responseDetail = new HttpResponse(200, _processedNewsArticle, ""); var emptyResponsListing = new HttpResponse(200, _emptyNewsRoom, ""); // setup mocks _repository.Setup(o => o.Get <Newsroom>(It.IsAny <string>(), It.Is <List <Query> >(l => l.Count == 0))) .ReturnsAsync(responseListing); _repository.Setup(o => o.GetLatest <List <News> >(7)) .ReturnsAsync(HttpResponse.Successful(200, _listOfNewsItems)); _processedContentRepository.Setup(o => o.Get <News>("another-news-article", null)) .ReturnsAsync(responseDetail); _logger = new Mock <ILogger <NewsController> >(); _mockRssFeedFactory = new Mock <IRssFeedFactory>(); _mockRssFeedFactory.Setup( o => o.BuildRssFeed(It.IsAny <List <News> >(), It.IsAny <string>(), It.IsAny <string>())).Returns("rss fun"); _config = new Mock <IApplicationConfiguration>(); _filteredUrl = new Mock <IFilteredUrl>(); _config.Setup(o => o.GetRssEmail(BusinessId)).Returns(AppSetting.GetAppSetting("rss-email")); _config.Setup(o => o.GetEmailAlertsNewSubscriberUrl(BusinessId)) .Returns(AppSetting.GetAppSetting("email-alerts-url")); _controller = new NewsController( _repository.Object, _processedContentRepository.Object, _mockRssFeedFactory.Object, _logger.Object, _config.Object, new BusinessId(BusinessId), _filteredUrl.Object ); }
public void ShouldReturnListOfNewsForCategoryAndTag() { _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 5)); 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>() { "Events" }, 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).FieldEquals("fields.tags[in]", "Events").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(new ContentfulNewsRoom { Title = "test" }); var response = AsyncTestHelper.Resolve(_repository.Get(tag: "Events", category: "news-category-1", startDate: null, endDate: null)); var newsroom = response.Get <Newsroom>(); response.StatusCode.Should().Be(HttpStatusCode.OK); newsroom.Alerts.Count.Should().Be(1); newsroom.EmailAlerts.Should().Be(true); newsroom.EmailAlertsTopicId.Should().Be("test-id"); newsroom.News.Count.Should().Be(2); newsroom.News.First().Title.Should().Be(Title); newsroom.News.First().Slug.Should().Be(Slug); }
public void ShouldReturnNewsItemsWithExactMatchingesForTagsWithoutHash() { const string tag = "testTag"; _mockTimeProvider.Setup(o => o.Now()).Returns(new DateTime(2016, 08, 5)); 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>() { "testTag" }, 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().Tags(new List <string> { "testTag", "foo" }).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().Tags(new List <string> { "testTag", "bar" }).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(), }; _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(new ContentfulNewsRoom { Title = "test" }); // Act var response = AsyncTestHelper.Resolve(_repository.Get(tag: tag, category: null, startDate: new DateTime(2016, 08, 01), endDate: new DateTime(2016, 08, 31))); var newsroom = response.Get <Newsroom>(); // Assert newsroom.News.Count.Should().Be(2); newsroom.News.First().Tags.Any(t => t == tag).Should().BeTrue();; }
private void DoPagination(Newsroom newsRoom, NewsroomViewModel model, int currentPageNumber, int pageSize) { if (newsRoom != null && newsRoom.News.Any()) { var paginatedNews = PaginationHelper.GetPaginatedItemsForSpecifiedPage( newsRoom.News, currentPageNumber, "news articles", pageSize, _config.GetNewsDefaultPageSize("stockportgov")); newsRoom.News = paginatedNews.Items; model.Pagination = paginatedNews.Pagination; model.Pagination.CurrentUrl = model.CurrentUrl; } else { model.Pagination = new Pagination(); } }
public async Task <HttpResponse> Get(string tag, string category, DateTime?startDate, DateTime?endDate) { var newsroom = new Newsroom(new List <Alert>(), false, string.Empty); var newsRoomEntry = await _cache.GetFromCacheOrDirectlyAsync("newsroom", GetNewsRoom, _newsTimeout); List <string> categories; if (newsRoomEntry != null) { newsroom = _newsRoomContentfulFactory.ToModel(newsRoomEntry); } var newsEntries = await _cache.GetFromCacheOrDirectlyAsync("news-all", GetAllNews, _newsTimeout); var filteredEntries = newsEntries.Where(n => tag == null || n.Tags.Any(t => t == tag)); if (!filteredEntries.Any()) { return(HttpResponse.Failure(HttpStatusCode.NotFound, "No news found")); } List <DateTime> dates; var newsArticles = filteredEntries .Select(item => _newsContentfulFactory.ToModel(item)) .GetNewsDates(out dates, _timeProvider) .Where(news => CheckDates(startDate, endDate, news)) .Where(news => string.IsNullOrWhiteSpace(category) || news.Categories.Contains(category)) .OrderByDescending(o => o.SunriseDate) .ToList(); categories = await GetCategories(); newsroom.SetNews(newsArticles); newsroom.SetCategories(categories); newsroom.SetDates(dates.Distinct().ToList()); return(HttpResponse.Successful(newsroom)); }
public NewsroomViewModelTest() { _newsroom = new Newsroom(new List <News>(), new List <Alert>(), true, "tag-id", new List <string>(), new List <DateTime>()); }