public void ShowsSavedAndDraftApprenticeshipsAndSuggestedSearchUrl()
        {
            //Arrange
            var fixture = new Fixture();
            var savedDraftViewModels     = fixture.CreateMany <MyApprenticeshipApplicationViewModel>().ToList();
            var suggestedViewModels      = fixture.CreateMany <SuggestedVacancyViewModel>().ToList();
            var whatHappensNextViewModel = new WhatHappensNextApprenticeshipViewModel
            {
                SuggestedVacancies = suggestedViewModels,
                SuggestedVacanciesSearchViewModel = new ApprenticeshipSearchViewModel(),
                SavedAndDraftApplications         = savedDraftViewModels
            };

            //Act
            var whatHappendNextView = new WhatHappensNextViewBuilder().With(whatHappensNextViewModel).RenderAsHtml();

            whatHappendNextView.Should().NotBeNull();

            //Assert
            for (int i = 0; i < 3; i++)
            {
                var savedDraft   = whatHappendNextView.GetElementbyId("saved-vacancy-" + savedDraftViewModels[i].VacancyId);
                var suggestedVac = whatHappendNextView.GetElementbyId("suggested-vacancy-" + suggestedViewModels[i].VacancyId);
                suggestedVac.Should().BeNull();
                savedDraft.Should().NotBeNull();
                savedDraft.InnerText.Should().Contain(savedDraftViewModels[i].Title);
                savedDraft.InnerText.Should().Contain(savedDraftViewModels[i].ClosingDate.ToFriendlyClosingToday());
            }
        }
Exemple #2
0
        private WhatHappensNextApprenticeshipViewModel WhatHappensNextSavedAndDrafts(WhatHappensNextApprenticeshipViewModel whatHappensNextViewModel, Guid candidateId)
        {
            var apprenticeshipApplicationSummaries = _candidateService.GetApprenticeshipApplications(candidateId);
            var savedAndDraftApplications          = apprenticeshipApplicationSummaries.Where(a => a.Status == ApplicationStatuses.Draft || a.Status == ApplicationStatuses.Saved).OrderBy(a => a.ClosingDate);

            whatHappensNextViewModel.SavedAndDraftApplications = savedAndDraftApplications.Select(s => new MyApprenticeshipApplicationViewModel(s)).ToList();
            return(whatHappensNextViewModel);
        }
Exemple #3
0
        public WhatHappensNextApprenticeshipViewModel GetWhatHappensNextViewModel(Guid candidateId, int vacancyId, string searchReturnUrl)
        {
            _logger.Debug(
                "Calling ApprenticeshipApplicationProvider to get the What Happens Next data for candidate ID: {0}, vacancy ID: {1}.",
                candidateId, vacancyId);

            try
            {
                var applicationDetails = _candidateService.GetApplication(candidateId, vacancyId);
                var candidate          = _candidateService.GetCandidate(candidateId);
                _candidateApplicationsProvider.RecalculateSavedAndDraftCount(candidateId, null);

                if (applicationDetails == null || candidate == null)
                {
                    var message =
                        string.Format(
                            "Get What Happens Next View Model failed as no application was found for candidate ID: {0}, vacancy ID: {1}.",
                            candidateId, vacancyId);

                    _logger.Info(message);
                    return(new WhatHappensNextApprenticeshipViewModel(MyApplicationsPageMessages.ApplicationNotFound));
                }

                var model        = _apprenticeshipCandidateWebMappers.Map <ApprenticeshipApplicationDetail, ApprenticeshipApplicationViewModel>(applicationDetails);
                var patchedModel = PatchWithVacancyDetail(candidateId, vacancyId, model);

                if (patchedModel.HasError())
                {
                    return(new WhatHappensNextApprenticeshipViewModel(patchedModel.ViewModelMessage));
                }

                var whatHappensNextViewModel = new WhatHappensNextApprenticeshipViewModel
                {
                    VacancyReference    = patchedModel.VacancyDetail.VacancyReference,
                    VacancyTitle        = patchedModel.VacancyDetail.Title,
                    Status              = patchedModel.Status,
                    VacancyStatus       = patchedModel.VacancyDetail.VacancyStatus,
                    ProviderContactInfo = patchedModel.VacancyDetail.Contact
                };


                whatHappensNextViewModel = WhatHappensNextSavedAndDrafts(whatHappensNextViewModel, candidateId);
                whatHappensNextViewModel = WhatHappensNextSuggestions(whatHappensNextViewModel, candidateId, applicationDetails.Vacancy.Id, searchReturnUrl);
                return(whatHappensNextViewModel);
            }
            catch (Exception e)
            {
                var message =
                    string.Format("Get What Happens Next View Model failed for candidate ID: {0}, vacancy ID: {1}.",
                                  candidateId, vacancyId);

                _logger.Error(message, e);

                return(new WhatHappensNextApprenticeshipViewModel(MyApplicationsPageMessages.CreateOrRetrieveApplicationFailed));
            }
        }
        public void ShowPlainFindApprenticeshipButtonWhenNoSavedDraftsOrSuggestedVacancies()
        {
            //Arrange
            var whatHappensNextViewModel = new WhatHappensNextApprenticeshipViewModel();
            var whatHappendNextView      = new WhatHappensNextViewBuilder().Build();

            //Act
            var result = whatHappendNextView.RenderAsHtml(whatHappensNextViewModel);

            //Assert
            var searchLink = result.GetElementbyId("find-apprenticeship-btn");

            searchLink.Should().NotBeNull();
            searchLink.InnerText.Should().Be("Find an apprenticeship");
        }
Exemple #5
0
        private WhatHappensNextApprenticeshipViewModel WhatHappensNextSuggestions(WhatHappensNextApprenticeshipViewModel whatHappensNextViewModel, Guid candidateId, int vacancyId, string searchReturnUrl)
        {
            var searchReturnViewModel = ApprenticeshipSearchViewModel.FromSearchUrl(searchReturnUrl) ?? new ApprenticeshipSearchViewModel {
                WithinDistance = 40, ResultsPerPage = 5, PageNumber = 1
            };
            var searchLocation = _apprenticeshipCandidateWebMappers.Map <ApprenticeshipSearchViewModel, Location>(searchReturnViewModel);

            var searchParameters = new ApprenticeshipSearchParameters
            {
                VacancyLocationType = ApprenticeshipLocationType.NonNational,
                ApprenticeshipLevel = searchReturnViewModel.ApprenticeshipLevel,
                SortType            = VacancySearchSortType.Distance,
                Location            = searchLocation,
                PageNumber          = 1,
                PageSize            = searchReturnViewModel.ResultsPerPage,
                SearchRadius        = searchReturnViewModel.WithinDistance
            };

            var suggestedVacancies = _candidateService.GetSuggestedApprenticeshipVacancies(searchParameters, candidateId, vacancyId);

            if (suggestedVacancies == null)
            {
                return(whatHappensNextViewModel);
            }

            var searchedCategory = (suggestedVacancies.SearchParameters.SubCategoryCodes != null && suggestedVacancies.SearchParameters.SubCategoryCodes.Length == 1
                ? _referenceDataService.GetSubCategoryByCode(suggestedVacancies.SearchParameters.SubCategoryCodes[0])
                : _referenceDataService.GetCategoryByCode(suggestedVacancies.SearchParameters.CategoryCode)) ?? Category.InvalidSectorSubjectAreaTier1;

            whatHappensNextViewModel.SuggestedVacanciesSearchViewModel = new ApprenticeshipSearchViewModel(suggestedVacancies.SearchParameters);
            whatHappensNextViewModel.SuggestedVacanciesCategory        = searchedCategory.FullName;
            whatHappensNextViewModel.SuggestedVacanciesSearchDistance  = suggestedVacancies.SearchParameters.SearchRadius;
            whatHappensNextViewModel.SuggestedVacanciesSearchLocation  = suggestedVacancies.SearchParameters.Location.Name;
            whatHappensNextViewModel.SuggestedVacancies =
                suggestedVacancies.Results.Select(x => new SuggestedVacancyViewModel
            {
                VacancyId    = x.Id,
                VacancyTitle = x.Title,
                IsPositiveAboutDisability = x.IsPositiveAboutDisability,
                Distance = Math.Round(x.Distance, 1, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture)
            }).ToList();

            return(whatHappensNextViewModel);
        }
        public void ShowsSearchReturnUrlWhenPResent()
        {
            //Arrange
            const string returnUrl = "http://searchreturn";
            var          whatHappensNextViewModel = new WhatHappensNextApprenticeshipViewModel
            {
                SuggestedVacanciesSearchViewModel = new ApprenticeshipSearchViewModel()
            };
            var whatHappendNextView = new WhatHappensNextViewBuilder().Build();

            whatHappendNextView.ViewBag.SearchReturnUrl = returnUrl;

            //Act
            var result = whatHappendNextView.RenderAsHtml(whatHappensNextViewModel);

            //Assert
            var searchLink = result.GetElementbyId("search-return-link");

            searchLink.Should().NotBeNull();
            searchLink.GetAttributeValue("href", returnUrl);
        }
        public void ShowsSuggestedApprenticeshipsAndSuggestedSearchUrl()
        {
            //Arrange
            var fixture                  = new Fixture();
            var suggestedViewModels      = fixture.CreateMany <SuggestedVacancyViewModel>().ToList();
            var whatHappensNextViewModel = new WhatHappensNextApprenticeshipViewModel
            {
                SuggestedVacancies = suggestedViewModels,
                SuggestedVacanciesSearchViewModel = new ApprenticeshipSearchViewModel()
            };

            //Act
            var whatHappendNextView = new WhatHappensNextViewBuilder().With(whatHappensNextViewModel).RenderAsHtml();

            whatHappendNextView.Should().NotBeNull();

            //Assert
            for (int i = 0; i < 3; i++)
            {
                var suggestedVac = whatHappendNextView.GetElementbyId("suggested-vacancy-" + suggestedViewModels[i].VacancyId);
                suggestedVac.InnerText.Should().Contain(suggestedViewModels[i].VacancyTitle);
                suggestedVac.InnerText.Should().Contain(suggestedViewModels[i].Distance);
            }
        }
Exemple #8
0
 public WhatHappensNextViewBuilder With(WhatHappensNextApprenticeshipViewModel viewModel)
 {
     _viewModel = viewModel;
     return(this);
 }