public async void GetSearchingData() { int pageIndex = 1; int pageSize = 6; string searchText = null; string selectCategory = null; SearchImageData localSearchData = new SearchImageData { FilterByTag = searchText, LikeForUserId = FirstTestUserId, }; var mockImagesService = new Mock <IImagesService>(); mockImagesService.Setup(x => x.GetByFilter <ListImageViewModel>( It.Is <SearchImageData>(x => x.LikeForUserId == FirstTestUserId && x.FilterByTag == searchText), pageSize, pageIndex)) .Returns(new List <ListImageViewModel>() { new ListImageViewModel() { Id = "1", Title = "ImageTitle", }, new ListImageViewModel() { Id = "2", Title = "ImageTitle", }, }); var mockCategoryService = new Mock <ICategoriesService>(); UserManager <ApplicationUser> userManager = MockUserManager(); var logger = new Mock <ILogger <ImagesController> >(); ImagesController controller = new ImagesController( mockImagesService.Object, mockCategoryService.Object, userManager, logger.Object).WithIdentity(FirstTestUserId, "TestIdentity"); ActionResult result = await controller.GetSearchingData(pageIndex, pageSize, searchText, selectCategory); Assert.IsType <PartialViewResult>(result); PartialViewResult viewResult = (PartialViewResult)result; Assert.IsType <List <ListImageViewModel> >(viewResult.Model); List <ListImageViewModel> model = (List <ListImageViewModel>)viewResult.Model; Assert.Equal(2, model.Count); for (int index = 0; index < model.Count; index++) { Assert.Equal(model[index].ImageIndex, index + 1); } }
public async void GetSearchDataMissingImages() { var mockImagesService = new Mock <IImagesService>(); var mockCategoryService = new Mock <ICategoriesService>(); UserManager <ApplicationUser> userManager = MockUserManager(); var logger = new Mock <ILogger <ImagesController> >(); ImagesController controller = new ImagesController( mockImagesService.Object, mockCategoryService.Object, userManager, logger.Object).WithIdentity(FirstTestUserId, "TestIdentity"); ActionResult result = await controller.GetSearchingData(1, 1, null, null); Assert.IsType <JsonResult>(result); }
public async void GetSearchingDataValidateParameters(int pageIndex, int pageSize) { var mockImagesService = new Mock <IImagesService>(); var mockCategoryService = new Mock <ICategoriesService>(); UserManager <ApplicationUser> userManager = MockUserManager(); var logger = new Mock <ILogger <ImagesController> >(); ImagesController controller = new ImagesController( mockImagesService.Object, mockCategoryService.Object, userManager, logger.Object).WithIdentity(FirstTestUserId, "TestIdentity"); ActionResult result = await controller.GetSearchingData(pageIndex, pageSize, null, null); Assert.IsType <BadRequestResult>(result); }