public void LocationTypeShouldBeCopiedOver() { SearchProvider.Setup(sp => sp.FindVacancies(It.IsAny <ApprenticeshipSearchViewModel>())) .Callback <ApprenticeshipSearchViewModel>(svm => { svm.LocationType = ApprenticeshipLocationType.National; _searchSentToSearchProvider = svm; }) .Returns <ApprenticeshipSearchViewModel>(svm => new ApprenticeshipSearchResponseViewModel { Vacancies = new ApprenticeshipVacancySummaryViewModel[0], VacancySearch = svm }); var searchViewModel = new ApprenticeshipSearchViewModel { Keywords = AKeyword, Location = ACityWithOneSuggestedLocation, LocationType = ApprenticeshipLocationType.NonNational, Category = "1", SearchMode = ApprenticeshipSearchMode.Category }; var response = Mediator.Results(searchViewModel); response.AssertCode(ApprenticeshipSearchMediatorCodes.Results.Ok, true); response.ViewModel.VacancySearch.LocationType.Should().Be(ApprenticeshipLocationType.National); }
public override void Setup() { base.Setup(); SearchProvider.Setup(sp => sp.FindLocation(It.IsAny <string>())) .Returns <string>(l => new LocationsViewModel(new[] { new LocationViewModel { Name = l } })); var londonVacancies = new[] { new ApprenticeshipVacancySummaryViewModel { Description = "A London Vacancy" } }; var emptyVacancies = new ApprenticeshipVacancySummaryViewModel[0]; //This order is important. Moq will run though all matches and pick the last one ApprenticeshipVacancyProvider.Setup(sp => sp.FindVacancies(It.IsAny <ApprenticeshipSearchViewModel>())) .Returns <ApprenticeshipSearchViewModel>( svm => new ApprenticeshipSearchResponseViewModel { Vacancies = emptyVacancies, VacancySearch = svm }) .Callback <ApprenticeshipSearchViewModel>(svm => { _searchSentToSearchProvider = svm; }); ApprenticeshipVacancyProvider.Setup( sp => sp.FindVacancies( It.Is <ApprenticeshipSearchViewModel>(svm => svm.Location == ACityWithOneSuggestedLocation))) .Returns <ApprenticeshipSearchViewModel>( svm => new ApprenticeshipSearchResponseViewModel { Vacancies = londonVacancies, VacancySearch = svm }) .Callback <ApprenticeshipSearchViewModel>(svm => { _searchSentToSearchProvider = svm; }); }
public void ExactMatchFoundUsingVacancyReference() { var searchViewModel = new ApprenticeshipSearchViewModel { Keywords = "VAC000123456" }; SearchProvider.Setup(sp => sp.FindVacancies(It.IsAny <ApprenticeshipSearchViewModel>())) .Returns(new ApprenticeshipSearchResponseViewModel { ExactMatchFound = true, VacancySearch = searchViewModel, Vacancies = new List <ApprenticeshipVacancySummaryViewModel> { new ApprenticeshipVacancySummaryViewModel { Id = 123456 } } }); var response = Mediator.Results(searchViewModel); response.AssertCode(ApprenticeshipSearchMediatorCodes.Results.ExactMatchFound, false, true); }
public void LocationResultIsNotValid() { var searchViewModel = new ApprenticeshipSearchViewModel { Location = ACityWithoutSuggestedLocations }; SearchProvider.Setup(sp => sp.FindLocation(ACityWithoutSuggestedLocations)) .Returns(() => new LocationsViewModel()); var response = Mediator.Results(searchViewModel); response.AssertCode(ApprenticeshipSearchMediatorCodes.Results.Ok, true); response.ViewModel.VacancySearch.Should().Be(searchViewModel); }
public void ShouldShowAMessageIfAnErrorOccursWhileFindingSuggestedLocations() { var searchViewModel = new ApprenticeshipSearchViewModel { Location = ACityWithMoreThanOneSuggestedLocation }; SearchProvider.Setup(sp => sp.FindLocation(ACityWithMoreThanOneSuggestedLocation)) .Returns(() => new LocationsViewModel { ViewModelMessage = SomeErrorMessage }); var response = Mediator.Results(searchViewModel); response.AssertMessage(ApprenticeshipSearchMediatorCodes.Results.HasError, SomeErrorMessage, UserMessageLevel.Warning, true); }
public void ErrorFindingVacancies() { var searchViewModel = new ApprenticeshipSearchViewModel { Location = ACityWithOneSuggestedLocation }; SearchProvider.Setup(sp => sp.FindVacancies(It.IsAny <ApprenticeshipSearchViewModel>())) .Returns(new ApprenticeshipSearchResponseViewModel { ViewModelMessage = SomeErrorMessage }); var response = Mediator.Results(searchViewModel); response.AssertMessage(ApprenticeshipSearchMediatorCodes.Results.HasError, SomeErrorMessage, UserMessageLevel.Warning, true); }
public void ShouldReturnAListOfSuggestedLocations() { const int numberOfSuggestedLocations = 4; var searchViewModel = new ApprenticeshipSearchViewModel { Location = ACityWithMoreThanOneSuggestedLocation }; SearchProvider.Setup(sp => sp.FindLocation(ACityWithMoreThanOneSuggestedLocation)) .Returns(() => new LocationsViewModel(Enumerable.Range(1, numberOfSuggestedLocations + 1).Select(e => new LocationViewModel { Name = Convert.ToString(e) }))); var response = Mediator.Results(searchViewModel); response.AssertCode(ApprenticeshipSearchMediatorCodes.Results.Ok, true); response.ViewModel.LocationSearches.Should().HaveCount(numberOfSuggestedLocations); }
public void IfTotalLocalHitsIsGreaterThanZero_LocationTypeIsNonNational() { var searchViewModel = new ApprenticeshipSearchViewModel { Location = ACityWithOneSuggestedLocation }; SearchProvider.Setup(sp => sp.FindVacancies(searchViewModel)) .Returns(new ApprenticeshipSearchResponseViewModel { TotalLocalHits = 1, VacancySearch = searchViewModel }); var response = Mediator.Results(searchViewModel); response.AssertCode(ApprenticeshipSearchMediatorCodes.Results.Ok, true); response.ViewModel.VacancySearch.LocationType = ApprenticeshipLocationType.NonNational; }