public ActionResult Dogs(SearchViewModel searchViewModel) { PageableResults<Dog> searchResults; if (searchViewModel.IsNationalSearch || searchViewModel.Location.IsEmpty()) searchResults = HandleNationalDogSearch(searchViewModel); else { if (searchViewModel.PlaceId == 0) { var places = _searchRepository.GetPlaces(searchViewModel.Location); if (places.Count != 1) return AmbiguousLocations(searchViewModel, places); searchViewModel.PlaceId = places.First().PlacesID; } searchResults = HandleLocalDogSearch( searchViewModel); } _session[SessionStoreKeys.SearchViewModel] = searchViewModel; if (searchResults == null) return RedirectToAction("Index", "Home", searchViewModel); // pass some TempData here to say place not found return View("Dogs", searchResults); }
public ViewResult Index(SearchViewModel searchViewModel) { ViewBag.Message = ConfigurationManager.AppSettings[AppSettingKeys.ApplicationMainSlogan]; PopulateBreedSelectList(searchViewModel); return View(_searchViewModel); }
public void Init() { _searchViewModel = MockRepository.GenerateMock<SearchViewModel>(); _searchRepository = MockRepository.GenerateMock<ISearchAPIFacade>(); _contactInformation = MockRepository.GenerateMock<ContactInformation>(); _searchRepository.Stub(x => x.GetBreeds()).Return(breedsList); _homeController = new HomeController(_searchViewModel, _searchRepository, _contactInformation); }
private void PopulateBreedSelectList(SearchViewModel searchViewModel) { if (searchViewModel == null) { _searchViewModel.BreedsSelectList = new SelectList(_searchRepository.GetBreeds(), "id", "name"); return; } _searchViewModel.BreedsSelectList = searchViewModel.BreedsSelectList ?? new SelectList(_searchRepository.GetBreeds(), "id", "name"); }
private static RouteValueDictionary BuildRouteValuesForDogsSearchViewModel(SearchViewModel searchViewModel) { return new RouteValueDictionary { {"SelectedBreed", searchViewModel.SelectedBreed}, {"BreedsSelectList", searchViewModel.BreedsSelectList}, {"Location", searchViewModel.Location}, {"SortBy", searchViewModel.SortBy}, {"PageNumber", searchViewModel.PageNumber}, {"IsNationalSearch", searchViewModel.IsNationalSearch}, }; }
private PageableResults<Dog> HandleNationalDogSearch( SearchViewModel searchViewModel) { SetPageNumber(searchViewModel); var defaultPageSize = _configuration.GetDefaultSearchResultPageSize(); return !IsSearchingForAnyBreed(searchViewModel.SelectedBreed) ? _searchRepository.GetDogsByBreed( searchViewModel.PageNumber, defaultPageSize, searchViewModel.SelectedBreed, searchViewModel.SortBy) : _searchRepository.GetDogs( searchViewModel.PageNumber, defaultPageSize); }
private ActionResult AmbiguousLocations(SearchViewModel search, List<Place> places) { return View("AmbiguousLocation", new AmbiguousLocationViewModel { SearchViewModel = search, Places = places }); }
private static void SetPageNumber(SearchViewModel searchViewModel) { if (searchViewModel.PageNumber == 0) searchViewModel.PageNumber = _firstPage; }
public void SearchControllerTestsSetup() { _searchViewModel = MockRepository.GenerateMock<SearchViewModel>(); _configMgr = MockRepository.GenerateMock<IConfiguration>(); _configMgr.Stub(x => x.GetDefaultSearchResultPageSize()).Return(25); }
public void Setup() { _configMgr = MockRepository.GenerateMock<IConfiguration>(); _configMgr.Stub(x => x.GetDefaultSearchResultPageSize()).Return(25); _searchViewModel = MockRepository.GenerateMock<SearchViewModel>(); _searchViewModel.IsNationalSearch = _isNationalSearch; _searchViewModel.SelectedBreed = _selectedBreed; _searchViewModel.PageNumber = _pageNumber; _dogs = new List<Dog>() { new Dog() {AgeInMonths = 3, AgeInYears = 0, Id = 1, IsFemale = false, IsSold = false}, new Dog() {AgeInMonths = 15, AgeInYears = 1, Id = 3, IsFemale = true, IsSold = false}, }; }
public HomeController(SearchViewModel searchViewModel, ISearchAPIFacade searchRepository, ContactInformation contactInformation) { _searchViewModel = searchViewModel; _searchRepository = searchRepository; _contactInformation = contactInformation; }
public void Index_Doesnt_Call_Repository_GetBreeds() { // arrange var searchViewModel = new SearchViewModel() { BreedsSelectList = new SelectList(breedsList) }; // act _homeController.Index(searchViewModel); // assert _searchRepository.AssertWasNotCalled(x => x.GetBreeds()); }