public void Dogs_Search_Correctly_Adds_SearchViewModel_To_the_Session() { const string sortBy = "price"; _searchViewModel.SortBy = sortBy; var pageableResults = new PageableResults<Dog>() {Data = _dogs}; var searchRepository = MockRepository.GenerateMock<ISearchAPIFacade>(); searchRepository.Stub(x => x.GetDogsByBreed( _pageNumber, 25, _selectedBreed, sortBy)).Return(pageableResults); var session = SessionStateHelper.FakeHttpContext("http://localhost/test?sortBy=price"); var httpRequestWrapper = MockRepository.GenerateMock<ICustomHttpRequestWrapper>(); httpRequestWrapper.Stub(x => x.GetQueryStringValueByKey(QuerystringKeys.SortBy)).Return(sortBy); var searchController = new SearchController(searchRepository, session, httpRequestWrapper, _configMgr); // act var result = (ViewResult) searchController.Dogs(_searchViewModel); var searchViewModelFromSession = (SearchViewModel) session["searchViewModel"]; // assert Assert.That(result.Model, Is.EqualTo(pageableResults)); Assert.That(searchViewModelFromSession.SelectedBreed, Is.EqualTo(_selectedBreed)); Assert.That(searchViewModelFromSession.PageNumber, Is.EqualTo(_pageNumber)); Assert.That(searchViewModelFromSession.IsNationalSearch, Is.EqualTo(_isNationalSearch)); Assert.That(searchViewModelFromSession.SortBy, Is.EqualTo(sortBy)); }
public void DogSearch_NationalSearch_Return_View_With_Full_List_Of_Dogs_Found_When_NationalSearch_For_Specific_Breed() { var 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}, }; var pageableResults = new PageableResults<Dog>() { Data = dogs }; var searchRepository = MockRepository.GenerateMock<ISearchAPIFacade>(); searchRepository.Stub(x => x.GetDogsByBreed(1, 25, 3, SearchSortOptions.PRICE_LOWEST)).Return(pageableResults); _searchViewModel.IsNationalSearch = true; _searchViewModel.SelectedBreed = 3; var httpRequestWrapper = MockRepository.GenerateMock<ICustomHttpRequestWrapper>(); var session = SessionStateHelper.FakeHttpContext("http://localhost/example"); var searchController = new SearchController(searchRepository, session, httpRequestWrapper, _configMgr); // act var result = (ViewResult) searchController.Dogs(_searchViewModel); var searchViewModelFromSession = (SearchViewModel) session["searchViewModel"]; // assert Assert.That(result.Model, Is.EqualTo(pageableResults)); Assert.That(searchViewModelFromSession.SelectedBreed, Is.EqualTo(3)); Assert.That(searchViewModelFromSession.PageNumber, Is.EqualTo(1)); }
public void Dogs_WhenPlaceId_IsZero_and_Location_Is_EmptyString_DoNationalSearch() { var 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}, }; var pageableResults = new PageableResults<Dog>() { Data = dogs }; var searchRepository = MockRepository.GenerateMock<ISearchAPIFacade>(); searchRepository.Stub(x => x.GetDogs(1, 25)).Return(pageableResults); _searchViewModel.IsNationalSearch = false; _searchViewModel.SelectedBreed = 0; _searchViewModel.PlaceId = 0; _searchViewModel.Location = string.Empty; var httpRequestWrapper = MockRepository.GenerateMock<ICustomHttpRequestWrapper>(); var searchController = new SearchController(searchRepository, SessionStateHelper.FakeHttpContext("http://localhost/example"), httpRequestWrapper, _configMgr); // act var result = (ViewResult)searchController.Dogs(_searchViewModel); // assert Assert.That(result.Model, Is.EqualTo(pageableResults)); }
public void DogSearch_NationalSearch_Calls_SearchRepository_GetDogs_When_NationalSearch_For_all_breeds() { // arrange var searchRepository = MockRepository.GenerateMock<ISearchAPIFacade>(); searchRepository.Stub(x => x.GetDogs(1, 25)).Return( new PageableResults<Dog>() { Data = 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}, } }); _searchViewModel.IsNationalSearch = true; _searchViewModel.SelectedBreed = 0; var customHttpRequestWrapper = MockRepository.GenerateMock<ICustomHttpRequestWrapper>(); var searchController = new SearchController(searchRepository, SessionStateHelper.FakeHttpContext("http://localhost/example"), customHttpRequestWrapper, _configMgr); // act searchController.Dogs(_searchViewModel); // assert searchRepository.AssertWasCalled(x => x.GetDogs(1, 25)); }