Exemple #1
0
        public MediatorResponse <ApprenticeshipSearchViewModel> Index(ApprenticeshipSearchMode searchMode)
        {
            var distances            = GetDistances();
            var sortTypes            = GetSortTypes();
            var resultsPerPage       = GetResultsPerPage();
            var apprenticeshipLevels = GetApprenticeshipLevels();
            var apprenticeshipLevel  = GetApprenticeshipLevel();
            var categories           = GetCategories();

            var viewModel = new ApprenticeshipSearchViewModel
            {
                WithinDistance       = 5,
                LocationType         = ApprenticeshipLocationType.NonNational,
                Distances            = distances,
                SortTypes            = sortTypes,
                ResultsPerPage       = resultsPerPage,
                ApprenticeshipLevels = apprenticeshipLevels,
                ApprenticeshipLevel  = apprenticeshipLevel,
                Categories           = categories,
                SearchMode           = searchMode
            };

            return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Index.Ok, viewModel));
        }
Exemple #2
0
 private string GetSearchModeName(ApprenticeshipSearchMode searchMode)
 {
     return(searchMode == ApprenticeshipSearchMode.Keyword ? "keyword" : "category");
 }
Exemple #3
0
 public ApprenticeshipSearchViewModelBuilder WithSearchMode(ApprenticeshipSearchMode searchMode)
 {
     _searchMode = searchMode;
     return(this);
 }
        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);
        }
        public void DuplicatesAreReplaced()
        {
            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";

            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)
                }
                             )
            };

            var existingSavedSearch = new SavedSearchBuilder()
                                      .WithSearchMode(searchMode)
                                      .WithKeywords(keywords)
                                      .WithLocation(location)
                                      .WithLatLong(latitude, longitude)
                                      .WithinDistance(withinDistance)
                                      .WithApprenticeshipLevel(apprenticeshipLevel)
                                      .WithCategory(category)
                                      .WithCategoryFullName(categoryFullName)
                                      .WithSubCategories(subCategories)
                                      .WithSubCategoriesFullNames(subCategoriesFullNames)
                                      .WithSearchField(searchField)
                                      .Build();

            var candidateService = new Mock <ICandidateService>();

            candidateService.Setup(cs => cs.GetSavedSearches(candidateId)).Returns(new List <SavedSearch> {
                existingSavedSearch
            });
            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)
                            .Build();

            var response = provider.CreateSavedSearch(candidateId, viewModel);

            response.Should().NotBeNull();
            candidateService.Verify(cs => cs.GetSavedSearches(candidateId), Times.Once);

            //Should only replace search if it is new
            candidateService.Verify(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>()), Times.Never);
        }
 public SavedSearchBuilder WithSearchMode(ApprenticeshipSearchMode searchMode)
 {
     _searchMode = searchMode;
     return(this);
 }
Exemple #7
0
        public MediatorResponse <ApprenticeshipSearchViewModel> Index(Guid?candidateId, ApprenticeshipSearchMode searchMode, bool reset)
        {
            var lastSearchedLocation = UserDataProvider.Get(UserDataItemNames.LastSearchedLocation);

            if (string.IsNullOrWhiteSpace(lastSearchedLocation) && candidateId.HasValue)
            {
                var candidate = _candidateServiceProvider.GetCandidate(candidateId.Value);
                UserDataProvider.Push(UserDataItemNames.LastSearchedLocation, lastSearchedLocation = candidate.RegistrationDetails.Address.Postcode);
            }

            if (!candidateId.HasValue && searchMode == ApprenticeshipSearchMode.SavedSearches)
            {
                searchMode = ApprenticeshipSearchMode.Keyword;
            }

            var distances            = GetDistances(true);
            var sortTypes            = GetSortTypes();
            var resultsPerPage       = GetResultsPerPage();
            var apprenticeshipLevels = GetApprenticeshipLevels();
            var apprenticeshipLevel  = GetApprenticeshipLevel(reset);
            var searchFields         = GetSearchFields();
            var categories           = GetCategories();
            var savedSearches        = GetSavedSearches(candidateId);

            var viewModel = new ApprenticeshipSearchViewModel
            {
                WithinDistance       = 5,
                LocationType         = ApprenticeshipLocationType.NonNational,
                Location             = SplitSearchLocation(lastSearchedLocation, 0),
                Latitude             = SplitSearchLocation(lastSearchedLocation, 1).GetValueOrNull <double>(),
                Longitude            = SplitSearchLocation(lastSearchedLocation, 2).GetValueOrNull <double>(),
                Distances            = distances,
                SortTypes            = sortTypes,
                ResultsPerPage       = resultsPerPage,
                ApprenticeshipLevels = apprenticeshipLevels,
                ApprenticeshipLevel  = apprenticeshipLevel,
                SearchFields         = searchFields,
                Categories           = categories,
                SavedSearches        = savedSearches,
                SearchMode           = searchMode
            };

            return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Index.Ok, viewModel));
        }