public void NewResults() { var candidateId = Guid.NewGuid(); var candidateSavedSearch = new CandidateSavedSearches { CandidateId = candidateId }; var existingSearchResults = new ApprenticeshipSearchResultsBuilder().WithResultCount(2).Build(); var dateProcessed = new DateTime(2015, 01, 01); var savedSearches = new Fixture().Build <SavedSearch>() .With(s => s.AlertsEnabled, true) .With(s => s.LastResultsHash, existingSearchResults.Results.GetResultsHash()) .With(s => s.DateProcessed, dateProcessed) .CreateMany(1).ToList(); var savedSearchReadRepository = new Mock <ISavedSearchReadRepository>(); savedSearchReadRepository.Setup(r => r.GetForCandidate(candidateId)).Returns(savedSearches); var userReadRepository = new Mock <IUserReadRepository>(); userReadRepository.Setup(r => r.Get(candidateId)).Returns(new UserBuilder(candidateId).Activated(true).Build); var candidateReadRepository = new Mock <ICandidateReadRepository>(); candidateReadRepository.Setup(r => r.Get(candidateId)).Returns(new CandidateBuilder(candidateId).EnableSavedSearchAlertsViaEmailAndText(true).Build); var vacancySearchProvider = new Mock <IVacancySearchProvider <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters> >(); vacancySearchProvider.Setup(p => p.FindVacancies(It.IsAny <ApprenticeshipSearchParameters>())).Returns(new ApprenticeshipSearchResultsBuilder().WithResultCount(3).Build); var savedSearchAlertRepository = new Mock <ISavedSearchAlertRepository>(); SavedSearchAlert savedSearchAlert = null; savedSearchAlertRepository.Setup(r => r.Save(It.IsAny <SavedSearchAlert>())).Callback <SavedSearchAlert>(a => { savedSearchAlert = a; }); var savedSearchWriteRepository = new Mock <ISavedSearchWriteRepository>(); SavedSearch savedSearch = null; savedSearchWriteRepository.Setup(r => r.Save(It.IsAny <SavedSearch>())).Callback <SavedSearch>(s => { savedSearch = s; }); var processor = new SavedSearchProcessorBuilder().With(savedSearchReadRepository).With(userReadRepository).With(candidateReadRepository).With(vacancySearchProvider).With(savedSearchAlertRepository).With(savedSearchWriteRepository).Build(); processor.ProcessCandidateSavedSearches(candidateSavedSearch); savedSearchWriteRepository.Verify(r => r.Save(It.IsAny <SavedSearch>()), Times.Once); savedSearch.Should().NotBeNull(); savedSearch.LastResultsHash.Should().NotBeNullOrEmpty(); savedSearch.DateProcessed.HasValue.Should().BeTrue(); savedSearch.DateProcessed.Should().BeAfter(dateProcessed); savedSearchAlertRepository.Verify(r => r.GetUnsentSavedSearchAlert(It.IsAny <SavedSearch>()), Times.Once); savedSearchAlertRepository.Verify(r => r.Save(It.IsAny <SavedSearchAlert>()), Times.Once); savedSearchAlert.Should().NotBeNull(); savedSearchAlert.Parameters.Should().Be(savedSearches.First()); savedSearchAlert.Results.Should().NotBeNull(); var results = savedSearchAlert.Results.ToList(); results.Count.Should().Be(3); savedSearchAlert.BatchId.HasValue.Should().BeFalse(); savedSearchAlert.SentDateTime.HasValue.Should().BeFalse(); }
public void Success() { var candidateId = Guid.NewGuid(); SavedSearch savedSearch = null; var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>())).Callback <SavedSearch>(ss => { savedSearch = ss; }); var provider = new CandidateServiceProviderBuilder().With(candidateService).Build(); var viewModel = new ApprenticeshipSearchViewModelBuilder().Build(); var response = provider.CreateSavedSearch(candidateId, viewModel); response.Should().NotBeNull(); candidateService.Verify(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>()), Times.Once); savedSearch.Should().NotBeNull(); }
public void SubCategoriesMustBelongToCategory() { var candidateId = Guid.NewGuid(); const string category = "MFP"; var subCategories = new[] { "513", "540", "600" }; const string subCategoriesFullNames = "Surveying|Construction Civil Engineering"; var categories = new List <Category> { new Category(17, category, category, CategoryType.SectorSubjectAreaTier1, CategoryStatus.Active, new List <Category> { new Category(255, "513", "Surveying", CategoryType.Framework, CategoryStatus.Active), new Category(273, "540", "Construction Civil Engineering", CategoryType.Framework, CategoryStatus.Active) } ), new Category(0, "OTHER", "OTHER", CategoryType.SectorSubjectAreaTier1, CategoryStatus.Active, new List <Category> { new Category(329, "600", "Should not be included", CategoryType.Framework, CategoryStatus.Active) } ) }; SavedSearch savedSearch = null; var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>())).Callback <SavedSearch>(ss => { savedSearch = ss; }); var provider = new CandidateServiceProviderBuilder().With(candidateService).Build(); var viewModel = new ApprenticeshipSearchViewModelBuilder() .WithCategory(category) .WithSubCategories(subCategories) .WithCategories(categories) .Build(); var response = provider.CreateSavedSearch(candidateId, viewModel); response.Should().NotBeNull(); candidateService.Verify(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>()), Times.Once); savedSearch.Should().NotBeNull(); savedSearch.CandidateId.Should().Be(candidateId); savedSearch.Category.Should().Be(category); savedSearch.SubCategories.Length.Should().Be(2); savedSearch.SubCategories.Should().NotContain("600"); savedSearch.SubCategoriesFullName.Should().Be(subCategoriesFullNames); }
public void Mapping() { var candidateId = Guid.NewGuid(); const ApprenticeshipSearchMode searchMode = ApprenticeshipSearchMode.Category; const string keywords = "chef"; const string location = "Warwick"; const double latitude = 1.1; const double longitude = 2.1; const int withinDistance = 15; const string apprenticeshipLevel = "Advanced"; const string category = "MFP"; const string categoryFullName = "Engineering and Manufacturing Technologies"; var subCategories = new[] { "513", "540" }; const string subCategoriesFullNames = "Surveying|Construction Civil Engineering"; const string searchField = "JobTitle"; const bool displaySubCategory = false; const bool displayDescription = false; const bool displayDistance = false; const bool displayClosingDate = false; const bool displayStartDate = false; const bool displayApprenticeshipLevel = true; const bool displayWage = true; var categories = new List <Category> { new Category(17, category, categoryFullName, CategoryType.SectorSubjectAreaTier1, CategoryStatus.Active, new List <Category> { new Category(255, "513", "Surveying", CategoryType.Framework, CategoryStatus.Active), new Category(273, "540", "Construction Civil Engineering", CategoryType.Framework, CategoryStatus.Active) } ) }; SavedSearch savedSearch = null; var candidateService = new Mock <ICandidateService>(); candidateService.Setup(cs => cs.GetSavedSearches(candidateId)).Returns(new List <SavedSearch> { new SavedSearchBuilder().WithLocation("Different Location").Build() }); candidateService.Setup(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>())).Callback <SavedSearch>(ss => { savedSearch = ss; }); var provider = new CandidateServiceProviderBuilder().With(candidateService).Build(); var viewModel = new ApprenticeshipSearchViewModelBuilder() .WithSearchMode(searchMode) .WithKeywords(keywords) .WithLocation(location) .WithLatLong(latitude, longitude) .WithinDistance(withinDistance) .WithApprenticeshipLevel(apprenticeshipLevel) .WithCategory(category) .WithSubCategories(subCategories) .WithSearchField(searchField) .WithCategories(categories) .WithDisplay(displaySubCategory, displayDescription, displayDistance, displayClosingDate, displayStartDate, displayApprenticeshipLevel, displayWage) .Build(); var response = provider.CreateSavedSearch(candidateId, viewModel); response.Should().NotBeNull(); candidateService.Verify(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>()), Times.Once); savedSearch.Should().NotBeNull(); savedSearch.CandidateId.Should().Be(candidateId); savedSearch.SearchMode.Should().Be(searchMode); savedSearch.Keywords.Should().Be(keywords); savedSearch.Location.Should().Be(location); savedSearch.Latitude.Should().Be(latitude); savedSearch.Longitude.Should().Be(longitude); savedSearch.Hash.Should().Be(string.Format("{0}{1}{2}", longitude, latitude, location).GetHashCode()); savedSearch.WithinDistance.Should().Be(withinDistance); savedSearch.ApprenticeshipLevel.Should().Be(apprenticeshipLevel); savedSearch.Category.Should().Be(category); savedSearch.CategoryFullName.Should().Be(categoryFullName); savedSearch.SubCategories.Should().BeEquivalentTo(subCategories); savedSearch.SubCategoriesFullName.Should().Be(subCategoriesFullNames); savedSearch.SearchField.Should().Be(searchField); savedSearch.LastResultsHash.Should().BeNull(); savedSearch.DateProcessed.Should().Be(null); savedSearch.DisplaySubCategory.Should().Be(displaySubCategory); savedSearch.DisplayDescription.Should().Be(displayDescription); savedSearch.DisplayDistance.Should().Be(displayDistance); savedSearch.DisplayClosingDate.Should().Be(displayClosingDate); savedSearch.DisplayStartDate.Should().Be(displayStartDate); savedSearch.DisplayApprenticeshipLevel.Should().Be(displayApprenticeshipLevel); savedSearch.DisplayWage.Should().Be(displayWage); }