// GET: /Movies/ public ActionResult Index(SearchViewModel searchModel, SortPagingViewModel sortPagingModel, IPrincipal user) { searchModel.SearchResults = this._moviesService.GetAllReachable(user.Identity.Name, searchModel.BuildFilter(), sortPagingModel.Page, AppConfiguration.PageSize, sortPagingModel.SortingCriteriaWithOrder); sortPagingModel.SearchResults = searchModel.SearchResults; SearchSortPagingViewModel indexModel = new SearchSortPagingViewModel(searchModel, sortPagingModel); return View(indexModel); }
public void ShouldRenderAllExistingMoviesWithoutSearchAndPaging() { // Arrange SearchViewModel searchModel = new SearchViewModel(); SortPagingViewModel sortPagingModel = new SortPagingViewModel {Page = 0, PageSize = 4}; IPrincipal fakeUser = new GenericPrincipal(new GenericIdentity("User1", "Forms"), null); var moviesCount = this._inMemoryMoviesService.GetAll().Count; // Act ActionResult actual = _controller.Index(searchModel, sortPagingModel, fakeUser); // Assert Assert.IsNotNull(actual, "The returned ActionResult is Null"); Assert.IsInstanceOf<ViewResult>(actual, "The returned ActionResult was not an instance of ViewResult"); ViewResult viewResult = (ViewResult) actual; Assert.IsNotNull(viewResult.ViewData.Model, "The value of viewResult.ViewData.Model is Null"); Assert.IsInstanceOf<SearchSortPagingViewModel>(viewResult.ViewData.Model, "The value of viewResult.ViewData.Model is not an instance of SearchSortPagingViewModel"); SearchSortPagingViewModel model = (SearchSortPagingViewModel) viewResult.ViewData.Model; Assert.IsTrue(model.SearchModel.SearchResults.Count == moviesCount, string.Format("The value of Model.SearchModel.SearchResults.Count should be '{0}' but it is '{1}'", moviesCount, model.SearchModel.SearchResults.Count)); }