public void PostedDate()
        {
            // Arrange.
            const int hits = 5;

            var vacancySearchViewModel = new ApprenticeshipSearchViewModelBuilder()
                                         .Build();

            var viewModel = new ApprenticeshipSearchResponseViewModelBuilder()
                            .WithVacancySearch(vacancySearchViewModel)
                            .WithTotalLocalHits(hits)
                            .Build();

            // Act.
            var result = new SearchResultsViewBuilder().With(viewModel).Render();

            // Assert.
            viewModel.Vacancies.Count().Should().Be(hits);

            foreach (var vacancy in viewModel.Vacancies)
            {
                var id = string.Format("posted-date-{0}", vacancy.Id);

                var element = result.GetElementbyId(id);

                var friendlyPostedDate = vacancy.PostedDate.ToFriendlyDaysAgo();

                element.Should().NotBeNull();
                element.InnerText.Should().Contain(friendlyPostedDate);
            }
        }
        public void NumberOfPositions(int numberOfPositions)
        {
            // Arrange.
            const int hits = 5;

            var vacancySearchViewModel = new ApprenticeshipSearchViewModelBuilder()
                                         .Build();

            var viewModel = new ApprenticeshipSearchResponseViewModelBuilder()
                            .WithVacancySearch(vacancySearchViewModel)
                            .WithTotalLocalHits(hits)
                            .WithNumberOfPositions(numberOfPositions)
                            .Build();

            // Act.
            var result = new SearchResultsViewBuilder().With(viewModel).Render();

            // Assert.
            viewModel.Vacancies.Count().Should().Be(hits);

            foreach (var vacancy in viewModel.Vacancies)
            {
                var id = string.Format("number-of-positions-{0}", vacancy.Id);

                var element = result.GetElementbyId(id);

                element.Should().NotBeNull();
                element.InnerText.Should().Contain(numberOfPositions.ToString(CultureInfo.InvariantCulture));
            }
        }
        public void AlertsEnabled()
        {
            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();

            provider.CreateSavedSearch(candidateId, viewModel);

            savedSearch.AlertsEnabled.Should().BeTrue();
        }
Пример #4
0
        public void SaveSearchAvailableNotLoggedIn()
        {
            var vacancySearchViewModel  = new ApprenticeshipSearchViewModelBuilder().WithLocation("CV1").Build();
            var searchResponseViewModel = new ApprenticeshipSearchResponseViewModelBuilder()
                                          .WithVacancySearch(vacancySearchViewModel)
                                          .Build();

            var result = new ResultsViewBuilder()
                         .With(searchResponseViewModel)
                         .Render();

            var receiveSaveSearchAlert = result.GetElementbyId("receiveSaveSearchAlert");

            receiveSaveSearchAlert.Should().NotBeNull();
        }
        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 Error()
        {
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();

            candidateService.Setup(cs => cs.CreateSavedSearch(It.IsAny <SavedSearch>())).Throws <Exception>();
            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);
            response.HasError().Should().BeTrue();
            response.ViewModelMessage.Should().Be(VacancySearchResultsPageMessages.SaveSearchFailed);
        }
        public void Ok()
        {
            var candidateId = Guid.NewGuid();
            var candidateServiceProvider = new Mock <ICandidateServiceProvider>();

            candidateServiceProvider.Setup(
                p => p.CreateSavedSearch(candidateId, It.IsAny <ApprenticeshipSearchViewModel>()))
            .Returns <Guid, ApprenticeshipSearchViewModel>((cid, vm) => vm);
            var mediator  = new ApprenticeshipSearchMediatorBuilder().With(candidateServiceProvider).Build();
            var viewModel = new ApprenticeshipSearchViewModelBuilder().Build();

            var response = mediator.SaveSearch(candidateId, viewModel);

            response.AssertMessage(ApprenticeshipSearchMediatorCodes.SaveSearch.Ok,
                                   VacancySearchResultsPageMessages.SaveSearchSuccess, UserMessageLevel.Success, true);
            candidateServiceProvider.Verify(p => p.CreateSavedSearch(candidateId, viewModel), Times.Once);
        }
        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 ShowHideSaveVacancyLinks(bool?isCandidateActivated)
        {
            // Arrange.
            const int hits = 5;

            var vacancySearchViewModel = new ApprenticeshipSearchViewModelBuilder()
                                         .Build();

            var viewModel = new ApprenticeshipSearchResponseViewModelBuilder()
                            .WithVacancySearch(vacancySearchViewModel)
                            .WithTotalLocalHits(hits)
                            .Build();

            // Act.
            var view = new SearchResultsViewBuilder().With(viewModel).Build();

            view.ViewBag.IsCandidateActivated = isCandidateActivated;

            var result = view.RenderAsHtml(viewModel);

            // Assert.
            viewModel.Vacancies.Count().Should().Be(hits);

            foreach (var vacancy in viewModel.Vacancies)
            {
                var idFormats = new[] { "save-vacancy-link-{0}", "resume-link-{0}", "applied-label-{0}" };

                foreach (var idFormat in idFormats)
                {
                    var id = string.Format(idFormat, vacancy.Id);

                    var element = result.GetElementbyId(id);

                    if (isCandidateActivated.HasValue && isCandidateActivated.Value)
                    {
                        element.Should().NotBeNull(id);
                    }
                    else
                    {
                        element.Should().BeNull(id);
                    }
                }
            }
        }
        public void CommunicationPreferences()
        {
            var       candidateId      = Guid.NewGuid();
            Candidate candidate        = null;
            var       candidateService = new Mock <ICandidateService>();

            candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).EnableSavedSearchAlertsViaEmailAndText(false).Build());
            candidateService.Setup(cs => cs.SaveCandidate(It.IsAny <Candidate>())).Callback <Candidate>(c => { candidate = c; });
            var provider  = new CandidateServiceProviderBuilder().With(candidateService).Build();
            var viewModel = new ApprenticeshipSearchViewModelBuilder().Build();

            provider.CreateSavedSearch(candidateId, viewModel);

            candidateService.Verify(cs => cs.GetCandidate(candidateId), Times.Once);
            candidateService.Verify(cs => cs.SaveCandidate(candidate), Times.Once);

            candidate.Should().NotBeNull();
            candidate.CommunicationPreferences.SavedSearchPreferences.EnableEmail.Should().BeTrue();
            candidate.CommunicationPreferences.SavedSearchPreferences.EnableText.Should().BeFalse();
        }
        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);
        }