public async Task <IActionResult> Index(int page = MinPage) { if (page < MinPage) { return(RedirectToAction(nameof(Index))); } PagingElementsViewModel <ReviewAdvancedServiceModel> model = new PagingElementsViewModel <ReviewAdvancedServiceModel> { Elements = await this.reviewService.GetAllListingAsync(page), Pagination = new PaginationViewModel { TotalElements = await this.reviewService.TotalCountAsync(false), PageSize = ReviewPageSize, CurrentPage = page } }; if (page > MinPage && page > model.Pagination.TotalPages) { return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task Index_WithCorrectPage_ShouldReturnViewResultWithValidViewModel() { const int page = 3; const int totalElements = 20; //Arrange Mock <IAdminUserService> adminUserService = new Mock <IAdminUserService>(); adminUserService .Setup(a => a.GetAllListingAsync(searchToken, page)) .ReturnsAsync(new List <AdminUserBasicServiceModel>()); adminUserService .Setup(a => a.TotalCountAsync(searchToken)) .ReturnsAsync(totalElements); UsersController usersController = new UsersController(null, null, adminUserService.Object, null, null); //Assert var result = await usersController.Index(searchToken, page); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().Model.Should().BeOfType <PagingElementsViewModel <AdminUserBasicServiceModel> >(); PagingElementsViewModel <AdminUserBasicServiceModel> model = result.As <ViewResult>().Model.As <PagingElementsViewModel <AdminUserBasicServiceModel> >(); model.SearchToken.Should().Be(searchToken); model.Pagination.CurrentPage.Should().Be(page); model.Pagination.PreviousPage.Should().Be(2); model.Pagination.NextPage.Should().Be(4); model.Pagination.TotalPages.Should().Be(4); model.Pagination.TotalElements.Should().Be(totalElements); model.Pagination.PageSize.Should().Be(UserPageSize); }
public async Task Index_WithTotalPagesEqualToOne_ShouldReturnValidPaginationModelAndValidViewModel() { const int page = 1; const int totalElements = ManufacturerPageSize; //Arrange Mock <IManagerManufacturerService> managerManufacturerService = new Mock <IManagerManufacturerService>(); managerManufacturerService .Setup(m => m.GetAllPagedListingAsync(false, searchToken, page)) .ReturnsAsync(new List <ManufacturerAdvancedServiceModel>()); managerManufacturerService .Setup(m => m.TotalCountAsync(false, searchToken)) .ReturnsAsync(totalElements); ManufacturersController manufacturersController = new ManufacturersController(managerManufacturerService.Object, null); //Act var result = await manufacturersController.Index(searchToken, false, page); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().Model.Should().BeOfType <PagingElementsViewModel <ManufacturerAdvancedServiceModel> >(); PagingElementsViewModel <ManufacturerAdvancedServiceModel> model = result.As <ViewResult>().Model.As <PagingElementsViewModel <ManufacturerAdvancedServiceModel> >(); model.SearchToken.Should().Be(searchToken); model.Pagination.CurrentPage.Should().Be(page); model.Pagination.PreviousPage.Should().Be(page); model.Pagination.NextPage.Should().Be(page); model.Pagination.TotalPages.Should().Be(page); model.Pagination.TotalElements.Should().Be(totalElements); model.Pagination.PageSize.Should().Be(ManufacturerPageSize); }
public async Task Index_WithCorrectPage_ShouldReturnViewResultWithValidViewModel() { const int page = 3; const int totalElements = 10; //Arrange Mock <IManagerSubcategoryService> managerSubcategoryService = new Mock <IManagerSubcategoryService>(); managerSubcategoryService .Setup(a => a.GetAllPagedListingAsync(false, searchToken, page)) .ReturnsAsync(new List <SubcategoryAdvancedServiceModel>()); managerSubcategoryService .Setup(a => a.TotalCountAsync(false, searchToken)) .ReturnsAsync(totalElements); SubcategoriesController subcategoriesController = new SubcategoriesController(managerSubcategoryService.Object, null, null); //Act var result = await subcategoriesController.Index(searchToken, false, page); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().Model.Should().BeOfType <PagingElementsViewModel <SubcategoryAdvancedServiceModel> >(); PagingElementsViewModel <SubcategoryAdvancedServiceModel> model = result.As <ViewResult>().Model.As <PagingElementsViewModel <SubcategoryAdvancedServiceModel> >(); model.SearchToken.Should().Be(searchToken); model.Pagination.CurrentPage.Should().Be(page); model.Pagination.PreviousPage.Should().Be(2); model.Pagination.NextPage.Should().Be(4); model.Pagination.TotalPages.Should().Be(4); model.Pagination.TotalElements.Should().Be(totalElements); model.Pagination.PageSize.Should().Be(SupplementPageSize); }
public async Task <IActionResult> Index(string searchToken, bool isDeleted, int page = MinPage) { if (page < MinPage) { return(RedirectToAction(nameof(Index), new { searchToken, isDeleted })); } PagingElementsViewModel <ManufacturerAdvancedServiceModel> model = new PagingElementsViewModel <ManufacturerAdvancedServiceModel> { Elements = await this.managerManufacturerService.GetAllPagedListingAsync(isDeleted, searchToken, page), SearchToken = searchToken, IsDeleted = isDeleted, Pagination = new PaginationViewModel { TotalElements = await this.managerManufacturerService.TotalCountAsync(isDeleted, searchToken), PageSize = SupplementPageSize, CurrentPage = page } }; if (page > MinPage && page > model.Pagination.TotalPages) { return(RedirectToAction(nameof(Index), new { searchToken, isDeleted })); } return(View(model)); }
public async Task <IActionResult> Index(string searchToken, int page = MinPage) { if (page < MinPage) { return(RedirectToAction(nameof(Index), new { searchToken })); } PagingElementsViewModel <AdminUserBasicServiceModel> model = new PagingElementsViewModel <AdminUserBasicServiceModel> { Elements = await this.adminUserService.GetAllListingAsync(searchToken, page), SearchToken = searchToken, Pagination = new PaginationViewModel { TotalElements = await this.adminUserService.TotalCountAsync(searchToken), PageSize = UserPageSize, CurrentPage = page } }; if (page > MinPage && page > model.Pagination.TotalPages) { return(RedirectToAction(nameof(Index), new { searchToken })); } return(View(model)); }
public async Task Index_WithCorrectPage_ShouldReturnViewResultWithValidViewModel() { const int page = 3; const int totalElements = 20; //Arrange Mock <IModeratorReviewService> moderatorReviewService = new Mock <IModeratorReviewService>(); moderatorReviewService .Setup(m => m.GetAllListingAsync(page)) .ReturnsAsync(new List <ReviewAdvancedServiceModel>() { new ReviewAdvancedServiceModel() }); Mock <IReviewService> reviewService = new Mock <IReviewService>(); reviewService .Setup(r => r.TotalCountAsync(true)) .ReturnsAsync(totalElements); ReviewsController reviewsController = new ReviewsController(moderatorReviewService.Object, reviewService.Object); //Act var result = await reviewsController.Index(page); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().Model.Should().BeOfType <PagingElementsViewModel <ReviewAdvancedServiceModel> >(); PagingElementsViewModel <ReviewAdvancedServiceModel> model = result.As <ViewResult>().Model.As <PagingElementsViewModel <ReviewAdvancedServiceModel> >(); model.Elements.Should().HaveCount(1); model.Pagination.CurrentPage.Should().Be(page); model.Pagination.PreviousPage.Should().Be(2); model.Pagination.NextPage.Should().Be(4); model.Pagination.TotalPages.Should().Be(4); model.Pagination.TotalElements.Should().Be(totalElements); model.Pagination.PageSize.Should().Be(ReviewPageSize); }
public async Task Index_WithCorrectPage_ShouldReturnViewResultWithValidViewModel() { const int page = 3; const int totalElements = 10; //Arrange Mock <IManufacturerService> manufacturerService = new Mock <IManufacturerService>(); manufacturerService .Setup(m => m.GetAllPagedListingAsync(page)) .ReturnsAsync(new List <ManufacturerAdvancedServiceModel>() { new ManufacturerAdvancedServiceModel { } }); manufacturerService .Setup(m => m.TotalCountAsync()) .ReturnsAsync(totalElements); ManufacturersController manufacturersController = new ManufacturersController(manufacturerService.Object); //Act var result = await manufacturersController.Index(page); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().Model.Should().BeOfType <PagingElementsViewModel <ManufacturerAdvancedServiceModel> >(); PagingElementsViewModel <ManufacturerAdvancedServiceModel> model = result.As <ViewResult>().Model.As <PagingElementsViewModel <ManufacturerAdvancedServiceModel> >(); model.Elements.Should().HaveCount(1); model.Pagination.CurrentPage.Should().Be(page); model.Pagination.PreviousPage.Should().Be(2); model.Pagination.NextPage.Should().Be(4); model.Pagination.TotalPages.Should().Be(4); model.Pagination.TotalElements.Should().Be(totalElements); model.Pagination.PageSize.Should().Be(ManufacturerPageSize); }
public async Task Index_WithCorrectPage_ShouldReturnViewResultWithValidViewModel() { const int page = 3; const int totalElements = 20; //Arrange Mock <IModeratorUserService> moderatorUserService = new Mock <IModeratorUserService>(); moderatorUserService .Setup(m => m.GetAllListingAsync(null, page)) .ReturnsAsync(new List <ModeratorUserBasicServiceModel>() { new ModeratorUserBasicServiceModel() }); moderatorUserService .Setup(m => m.TotalCountAsync(null)) .ReturnsAsync(totalElements); UsersController usersController = new UsersController(null, moderatorUserService.Object); //Assert var result = await usersController.Index(null, page); //Assert result.Should().BeOfType <ViewResult>(); result.As <ViewResult>().Model.Should().BeOfType <PagingElementsViewModel <ModeratorUserBasicServiceModel> >(); PagingElementsViewModel <ModeratorUserBasicServiceModel> model = result.As <ViewResult>().Model.As <PagingElementsViewModel <ModeratorUserBasicServiceModel> >(); model.Elements.Should().HaveCount(1); model.Pagination.CurrentPage.Should().Be(page); model.Pagination.PreviousPage.Should().Be(2); model.Pagination.NextPage.Should().Be(4); model.Pagination.TotalPages.Should().Be(4); model.Pagination.TotalElements.Should().Be(totalElements); model.Pagination.PageSize.Should().Be(UserPageSize); }