예제 #1
0
        public void CallGetAimsCount_FromAimService_WhenValidParametersArePassed()
        {
            // Arrange
            string searchWord       = "some searching word";
            var    categoriesChosen = new int[] { 1, 16 };

            var mockedAimService         = new Mock <IAimService>();
            var mockedAimCategoryService = new Mock <IAimCategoryService>();
            var mockedMapper             = new Mock <IMapperAdapter>();

            ExploreSubmitViewModel submitModel = new ExploreSubmitViewModel()
            {
                SearchWord          = searchWord,
                ChosenCategoriesIds = categoriesChosen
            };

            mockedAimService
            .Setup(x => x.GetAimsCount(searchWord, categoriesChosen))
            .Verifiable();

            ExploreController controller = new ExploreController(mockedAimService.Object,
                                                                 mockedAimCategoryService.Object, mockedMapper.Object);

            // Act
            controller.ExploreAims(submitModel, null);

            // Assert
            mockedAimService
            .Verify(x => x.GetAimsCount(searchWord, categoriesChosen), Times.Once);
        }
예제 #2
0
        public void CallExploreAimsWithDefaultPage_WhenPageParameterIsNull()
        {
            // Arrange
            string searchWord       = "word";
            string sortBy           = "name";
            var    categoriesChosen = new int[] { 4, 2 };
            // it is a constant
            int aimsPerPage = 5;

            var mockedAimService         = new Mock <IAimService>();
            var mockedAimCategoryService = new Mock <IAimCategoryService>();
            var mockedMapper             = new Mock <IMapperAdapter>();

            ExploreSubmitViewModel submitModel = new ExploreSubmitViewModel()
            {
                SearchWord          = searchWord,
                SortBy              = sortBy,
                ChosenCategoriesIds = categoriesChosen
            };

            mockedAimService
            .Setup(x => x.ExploreAims(searchWord, categoriesChosen, sortBy, 1, aimsPerPage))
            .Verifiable();

            ExploreController controller = new ExploreController(mockedAimService.Object,
                                                                 mockedAimCategoryService.Object, mockedMapper.Object);

            // Act
            controller.ExploreAims(submitModel, null);

            // Assert
            mockedAimService
            .Verify(x => x.ExploreAims(searchWord, categoriesChosen, sortBy, 1, aimsPerPage), Times.Once);
        }
예제 #3
0
        public void CallExploreAims_FromAimService_WithCorrectParameter()
        {
            // Arrange
            string searchWord       = "search";
            string sortBy           = "sort";
            var    categoriesChosen = new int[] { 1, 2 };
            int    page             = 3;
            // it is a constant
            int aimsPerPage = 5;

            var mockedAimService         = new Mock <IAimService>();
            var mockedAimCategoryService = new Mock <IAimCategoryService>();
            var mockedMapper             = new Mock <IMapperAdapter>();

            ExploreSubmitViewModel submitModel = new ExploreSubmitViewModel()
            {
                SearchWord          = searchWord,
                SortBy              = sortBy,
                ChosenCategoriesIds = categoriesChosen
            };

            mockedAimService
            .Setup(x => x.ExploreAims(searchWord, categoriesChosen, sortBy, page, aimsPerPage))
            .Verifiable();

            ExploreController controller = new ExploreController(mockedAimService.Object,
                                                                 mockedAimCategoryService.Object, mockedMapper.Object);

            // Act
            controller.ExploreAims(submitModel, page);

            // Assert
            mockedAimService
            .Verify(x => x.ExploreAims(searchWord, categoriesChosen, sortBy, page, aimsPerPage), Times.Once);
        }
예제 #4
0
        public PartialViewResult ExploreAims(ExploreSubmitViewModel submitModel, int?page)
        {
            int actualPage = page ?? 1;

            var result          = this.aimService.ExploreAims(submitModel.SearchWord, submitModel.ChosenCategoriesIds, submitModel.SortBy, actualPage, CountOfAims);
            var count           = this.aimService.GetAimsCount(submitModel.SearchWord, submitModel.ChosenCategoriesIds);
            var resultViewModel = new ExploreResultsViewModel();

            resultViewModel.SubmitModel = submitModel;
            resultViewModel.Pages       = (int)Math.Ceiling((double)count / CountOfAims);

            resultViewModel.Aims = mapper.Map <IEnumerable <AimViewModel> >(result);

            return(this.PartialView("_ExploreResultsPartial", resultViewModel));
        }
예제 #5
0
        public void ReturnCorrectPartialView_WithExploreSubmitViewModel()
        {
            // Arrange
            var mockedAimService         = new Mock <IAimService>();
            var mockedAimCategoryService = new Mock <IAimCategoryService>();
            var mockedMapper             = new Mock <IMapperAdapter>();

            ExploreSubmitViewModel model = new ExploreSubmitViewModel();

            ExploreController controller = new ExploreController(mockedAimService.Object,
                                                                 mockedAimCategoryService.Object, mockedMapper.Object);

            // Act & Assert
            controller.WithCallTo(x => x.ExploreAims(model, null))
            .ShouldRenderPartialView("_ExploreResultsPartial")
            .WithModel <ExploreResultsViewModel>(x => x.SubmitModel == model);
        }