private EventsController SetUpController(int numItems)
        {
            List <Event> listOfEvents = BuildEventList(numItems);

            var categories = new List <string> {
                "Category 1", "Category 2"
            };
            var eventsCalendar    = new EventResponse(listOfEvents, categories);
            var eventListResponse = new HttpResponse(200, eventsCalendar, "");

            _repository.Setup(o =>
                              o.Get <EventResponse>(
                                  It.IsAny <string>(),
                                  It.IsAny <List <Query> >()))
            .ReturnsAsync(eventListResponse);

            var controller = new EventsController(
                _repository.Object,
                _processedContentRepository.Object,
                _eventEmailBuilder,
                _mockRssFeedFactory.Object,
                _logger.Object,
                _config.Object,
                new BusinessId(BusinessId),
                _filteredUrl.Object,
                null,
                null,
                _datetimeCalculator,
                null
                );

            return(controller);
        }
        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 ContactUsControllerTest()
        {
            _mockEmailClient = new Mock <IHttpEmailClient>();
            _mockLogger      = new Mock <ILogger <ContactUsController> >();
            _configuration   = new Mock <IApplicationConfiguration>();

            _configuration.Setup(a => a.GetEmailEmailFrom(It.IsAny <string>()))
            .Returns(AppSetting.GetAppSetting("businessid:Email:EmailFrom"));

            _businessId = new BusinessId("businessid");

            _contactUsId = new ContactUsId("name", "slug", "email", "test button text", "test return url");

            _repository.Setup(o => o.Get <ContactUsId>(It.IsAny <string>(), It.IsAny <List <Query> >()))
            .ReturnsAsync(HttpResponse.Successful(200, _contactUsId));

            _controller          = new ContactUsController(_repository.Object, _mockEmailClient.Object, _mockLogger.Object, _configuration.Object, _businessId);
            _validContactDetails = new ContactUsDetails(_userName, _userEmail, _emailSubject,
                                                        _emailBody, _serviceEmails, _title);

            var request          = new Mock <HttpRequest>();
            var context          = new Mock <HttpContext>();
            var headerDictionary = new HeaderDictionary {
                { "referer", _url }
            };

            request.Setup(r => r.Headers).Returns(headerDictionary);
            context.Setup(c => c.Request).Returns(request.Object);
            _controller.ControllerContext = new ControllerContext(new ActionContext(context.Object, new RouteData(), new ControllerActionDescriptor()));
        }
        public async Task ShouldReturnEmptyPaginationForNoNewsItems()
        {
            var emptyRepository = new Mock <IRepository>();

            emptyRepository.Setup(o => o.Get <Newsroom>(It.IsAny <string>(), It.IsAny <List <Query> >()))
            .ReturnsAsync(HttpResponse.Successful((int)HttpStatusCode.OK, _emptyNewsRoom));

            var controller = new NewsController(
                emptyRepository.Object,
                _processedContentRepository.Object,
                _mockRssFeedFactory.Object,
                _logger.Object,
                _config.Object,
                new BusinessId(BusinessId),
                _filteredUrl.Object
                );

            var actionResponse =
                await
                controller.Index(
                    new NewsroomViewModel
            {
                DateFrom = null,
                DateTo   = null
            }, 1, MaxNumberOfItemsPerPage) as ViewResult;

            var viewModel = actionResponse.ViewData.Model as NewsroomViewModel;

            viewModel.Newsroom.News.Count.Should().Be(0);
//            viewModel.Pagination.TotalItems.Should().Be(0);
        }
        public async Task CreatesRssFeedFromFactory()
        {
            var repository = new Mock <IRepository>();

            repository.Setup(o => o.Get <Newsroom>(It.IsAny <string>(), null))
            .ReturnsAsync(HttpResponse.Successful((int)HttpStatusCode.OK, _newsRoom));

            _controller = new NewsController(
                repository.Object,
                _processedContentRepository.Object,
                _mockRssFeedFactory.Object,
                _logger.Object,
                _config.Object,
                new BusinessId(BusinessId),
                _filteredUrl.Object
                );

            var response = await _controller.Rss() as ContentResult;

            response.ContentType.Should().Be("application/rss+xml");
            response.Content.Should().Be("rss fun");

            _mockRssFeedFactory.Verify(
                o => o.BuildRssFeed(It.IsAny <List <News> >(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
        public async Task ItReturnsAListOfNewsArticlesForATagAndACategory()
        {
            _repository.Setup(
                o =>
                o.Get <Newsroom>("",
                                 It.Is <List <Query> >(
                                     l =>
                                     l.Contains(new Query("tag", "Events")) &&
                                     l.Contains(new Query("Category", "A Category")))))
            .ReturnsAsync(HttpResponse.Successful((int)HttpStatusCode.OK, _newsRoom));
            var actionResponse =
                await
                _controller.Index(new NewsroomViewModel { Tag = "Events", Category = "A Category" }, 1, MaxNumberOfItemsPerPage) as ViewResult;

            var viewModel = actionResponse.ViewData.Model as NewsroomViewModel;
            var news      = viewModel.Newsroom;

            news.News.Count.Should().Be(2);

            var firstNewsItem = news.News[0];

            firstNewsItem.Should().Be(NewsItemWithoutImages);

            var secondNewsItem = news.News[1];

            secondNewsItem.Should().Be(NewsItemWithImages);

            news.EmailAlerts.Should().Be(EmailAlertsOn);
            news.EmailAlertsTopicId.Should().Be(EmailAlertsTopicId);
        }
        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 async Task ShouldReturnNewsItemsForADateFilter()
        {
            _repository.Setup(o =>
                              o.Get <Newsroom>("", It.Is <List <Query> >(l => l.Contains(new Query("DateFrom", "2016-10-01")) && l.Contains(new Query("DateTo", "2016-11-01"))
                                                                         )
                                               )
                              ).ReturnsAsync(HttpResponse.Successful((int)HttpStatusCode.OK, _newsRoom));

            var actionResponse =
                await
                _controller.Index(
                    new NewsroomViewModel
            {
                DateFrom = new DateTime(2016, 10, 01),
                DateTo   = new DateTime(2016, 11, 01)
            }, 1, MaxNumberOfItemsPerPage) as ViewResult;

            var viewModel = actionResponse.ViewData.Model as NewsroomViewModel;
            var news      = viewModel.Newsroom;

            news.Should().Be(_newsRoom);
        }
        public EventsControllerTest()
        {
            _eventsItem = new Event {
                Title    = "title", Slug = "slug", Teaser = "teaser", ImageUrl = "image.png", ThumbnailImageUrl = "image.png", Description = "description", Fee = "fee",
                Location = "location", SubmittedBy = "submittedBy", EventDate = new DateTime(2016, 12, 30, 00, 00, 00), StartTime = "startTime", EndTime = "endTime", Breadcrumbs = new List <Crumb>(), Group = _group, Alerts = _alerts
            };
            _categories = new List <string> {
                "Category 1", "Category 2"
            };

            var mockTime = new Mock <ITimeProvider>();

            _datetimeCalculator = new DateCalculator(mockTime.Object);

            var eventsCalendar = new EventResponse(new List <Event> {
                _eventsItem
            }, _categories);
            var eventItem = new ProcessedEvents("title", "slug", "teaser", "image.png", "image.png", "description",
                                                "fee", "location", "submittedBy", new DateTime(2016, 12, 30, 00, 00, 00), "startTime", "endTime",
                                                new List <Crumb>(), _categories, new MapDetails(), "booking information", _group, _alerts, string.Empty, string.Empty);

            var eventHomepage = new EventHomepage {
                Categories = new List <EventCategory>(), Rows = new List <EventHomepageRow>()
            };

            // setup responses (with mock data)
            responseListing = new HttpResponse(200, eventsCalendar, "");
            _responseDetail = new HttpResponse(200, eventItem, "");
            var responseHomepage = new HttpResponse(200, eventHomepage, "");
            var response404      = new HttpResponse(404, null, "not found");

            // setup mocks
            _repository.Setup(o => o.Get <EventHomepage>(It.IsAny <string>(), It.IsAny <List <Query> >()))
            .ReturnsAsync(responseHomepage);

            _repository.Setup(o => o.Get <EventResponse>(It.IsAny <string>(), It.IsAny <List <Query> >()))
            .ReturnsAsync(responseListing);

            _processedContentRepository.Setup(o => o.Get <Event>("event-of-the-century", It.Is <List <Query> >(l => l.Count == 0)))
            .ReturnsAsync(_responseDetail);

            _processedContentRepository.Setup(o => o.Get <Event>("404-event", It.Is <List <Query> >(l => l.Count == 0)))
            .ReturnsAsync(response404);

            _emailClient = new Mock <IHttpEmailClient>();
            _applicationConfiguration = new Mock <IApplicationConfiguration>();
            _logger      = new Mock <ILogger <EventsController> >();
            _emaillogger = new Mock <ILogger <EventEmailBuilder> >();

            _applicationConfiguration.Setup(a => a.GetEmailEmailFrom(It.IsAny <string>()))
            .Returns(AppSetting.GetAppSetting("GroupSubmissionEmail"));

            _eventEmailBuilder = new EventEmailBuilder(_emaillogger.Object, _emailClient.Object, _applicationConfiguration.Object, new BusinessId("businessId"));

            _mockRssFeedFactory = new Mock <IRssFeedFactory>();
            _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 EventsController(
                _repository.Object,
                _processedContentRepository.Object,
                _eventEmailBuilder,
                _mockRssFeedFactory.Object,
                _logger.Object,
                _config.Object,
                new BusinessId(BusinessId),
                _filteredUrl.Object,
                null,
                null,
                _datetimeCalculator,
                null
                );
        }