public void CreateApplicationReturnsExpiredOrWithdrawn()
        {
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();
            var apprenticeshipVacancyDetailProvider = new Mock <IApprenticeshipVacancyDetailProvider>();

            candidateService.Setup(cs => cs.CreateApplication(candidateId, ValidVacancyId)).Returns(new ApprenticeshipApplicationDetail {
                Status = ApplicationStatuses.ExpiredOrWithdrawn
            });
            apprenticeshipVacancyDetailProvider.Setup(p => p.GetVacancyDetailViewModel(candidateId, ValidVacancyId)).Returns((VacancyDetailViewModel)null);
            var viewModel = new ApprenticeshipApplicationProviderBuilder()
                            .With(candidateService).With(apprenticeshipVacancyDetailProvider).Build()
                            .GetOrCreateApplicationViewModel(candidateId, ValidVacancyId);

            viewModel.Should().NotBeNull();
            viewModel.Status.Should().Be(ApplicationStatuses.ExpiredOrWithdrawn);
            viewModel.ViewModelMessage.Should().Be(MyApplicationsPageMessages.ApprenticeshipNoLongerAvailable);
            viewModel.HasError().Should().BeTrue();
        }
        public void GivenException_ThenFailedApplicationViewModelIsReturned()
        {
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();
            var apprenticeshipVacancyProvider = new Mock <IApprenticeshipVacancyProvider>();

            apprenticeshipVacancyProvider.Setup(p => p.GetVacancyDetailViewModel(candidateId, ValidVacancyId)).Returns(new ApprenticeshipVacancyDetailViewModel());
            candidateService.Setup(cs => cs.GetApplication(candidateId, ValidVacancyId)).Returns(new ApprenticeshipApplicationDetail());
            candidateService.Setup(cs => cs.SubmitApplication(candidateId, ValidVacancyId)).Throws <Exception>();

            var returnedViewModel = new ApprenticeshipApplicationProviderBuilder()
                                    .With(apprenticeshipVacancyProvider).With(candidateService).Build()
                                    .SubmitApplication(candidateId, ValidVacancyId);

            returnedViewModel.HasError().Should().BeTrue();
            returnedViewModel.ViewModelStatus.Should().Be(ApplicationViewModelStatus.Error);
            returnedViewModel.ViewModelMessage.Should().NotBeNullOrEmpty();
            returnedViewModel.Status.Should().Be(ApplicationStatuses.Unknown);
        }
        public void PatchWithVacancyDetail_VacancyStatusUnavailable()
        {
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();
            var apprenticeshipVacancyProvider = new Mock <IApprenticeshipVacancyProvider>();

            apprenticeshipVacancyProvider.Setup(p => p.GetVacancyDetailViewModel(candidateId, ValidVacancyId)).Returns(new ApprenticeshipVacancyDetailViewModel {
                VacancyStatus = VacancyStatuses.Unavailable
            });
            candidateService.Setup(cs => cs.CreateApplication(candidateId, ValidVacancyId)).Returns(new ApprenticeshipApplicationDetail());
            candidateService.Setup(cs => cs.GetApprenticeshipApplications(candidateId, It.IsAny <bool>())).Returns(new ApprenticeshipApplicationSummary[0]);
            var viewModel = new ApprenticeshipApplicationProviderBuilder()
                            .With(candidateService).With(apprenticeshipVacancyProvider).Build()
                            .CreateApplicationViewModel(candidateId, ValidVacancyId);

            viewModel.Should().NotBeNull();
            viewModel.Status.Should().Be(ApplicationStatuses.ExpiredOrWithdrawn);
            viewModel.ViewModelMessage.Should().Be(MyApplicationsPageMessages.ApprenticeshipNoLongerAvailable);
            viewModel.HasError().Should().BeTrue();
        }
        public void GivenPatchWithVacancyDetailHasError_ThenMessageIsReturned()
        {
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();
            var apprenticeshipVacancyDetailProvider = new Mock <IApprenticeshipVacancyDetailProvider>();

            candidateService.Setup(cs => cs.GetApplication(candidateId, ValidVacancyId)).Returns(new ApprenticeshipApplicationDetailBuilder(candidateId, ValidVacancyId).Build);
            candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).Build);

            apprenticeshipVacancyDetailProvider.Setup(cs => cs.GetVacancyDetailViewModel(candidateId, ValidVacancyId)).Returns((VacancyDetailViewModel)null);

            var returnedViewModel = new ApprenticeshipApplicationProviderBuilder()
                                    .With(candidateService).With(apprenticeshipVacancyDetailProvider).Build()
                                    .GetWhatHappensNextViewModel(candidateId, ValidVacancyId);

            returnedViewModel.HasError().Should().BeTrue();
            returnedViewModel.ViewModelMessage.Should().NotBeNullOrEmpty();
            returnedViewModel.ViewModelMessage.Should().Be(MyApplicationsPageMessages.ApprenticeshipNoLongerAvailable);
            returnedViewModel.Status.Should().Be(ApplicationStatuses.Unknown);
        }
        public void CreateApplicationReturnsVacancyStatusesLive()
        {
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();
            var apprenticeshipVacancyDetailProvider = new Mock <IApprenticeshipVacancyDetailProvider>();

            candidateService.Setup(cs => cs.CreateApplication(candidateId, ValidVacancyId)).Returns(new ApprenticeshipApplicationDetail {
                VacancyStatus = VacancyStatuses.Live
            });
            apprenticeshipVacancyDetailProvider.Setup(p => p.GetVacancyDetailViewModel(candidateId, ValidVacancyId)).Returns(new VacancyDetailViewModel {
                VacancyStatus = VacancyStatuses.Live
            });
            var viewModel = new ApprenticeshipApplicationProviderBuilder()
                            .With(candidateService).With(apprenticeshipVacancyDetailProvider).Build()
                            .GetOrCreateApplicationViewModel(candidateId, ValidVacancyId);

            viewModel.Should().NotBeNull();
            viewModel.Status.Should().Be(ApplicationStatuses.Unknown);
            viewModel.ViewModelMessage.Should().BeNullOrEmpty();
            viewModel.HasError().Should().BeFalse();
        }
        public void ShouldHaveViewModelErrorMessage()
        {
            // Arrange.
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();
            var apprenticeshipVacancyProvider = new Mock <IApprenticeshipVacancyProvider>();

            var vacancy = new Fixture()
                          .Build <ApprenticeshipVacancyDetailViewModel>()
                          .With(fixture => fixture.VacancyStatus, VacancyStatuses.Live)
                          .With(fixture => fixture.ViewModelMessage, "Something wonderful happened")
                          .Create();

            apprenticeshipVacancyProvider
            .Setup(p => p.GetVacancyDetailViewModel(candidateId, ValidVacancyId))
            .Returns(vacancy);

            var application = new Fixture()
                              .Build <ApprenticeshipApplicationDetail>()
                              .With(fixture => fixture.Status, ApplicationStatuses.Draft)
                              .Create();

            candidateService
            .Setup(cs => cs.GetApplication(candidateId, ValidVacancyId))
            .Returns(application);

            var provider = new ApprenticeshipApplicationProviderBuilder()
                           .With(candidateService)
                           .With(apprenticeshipVacancyProvider)
                           .Build();

            // Act.
            var applicationPreviewViewModel = provider.GetApplicationPreviewViewModel(candidateId, ValidVacancyId);

            // Assert.
            applicationPreviewViewModel.Should().NotBeNull();

            applicationPreviewViewModel.ViewModelMessage.Should().Be(vacancy.ViewModelMessage);
            applicationPreviewViewModel.HasError().Should().BeTrue();
        }
        public void ShouldPatchWorkExperienceChanges()
        {
            var candidateId = Guid.NewGuid();
            var apprenticeshipApplicationProvider = new ApprenticeshipApplicationProviderBuilder().Build();
            var savedViewModel = new ApprenticeshipApplicationViewModelBuilder().Build();

            var workExperience = new[]
            {
                new WorkExperienceViewModelBuilder()
                .WithDescription("Work")
                .WithEmployer("Employer")
                .Build()
            };

            var newViewModel     = new ApprenticeshipApplicationViewModelBuilder().WithWorkExperience(workExperience).Build();
            var patchedViewModel = apprenticeshipApplicationProvider.PatchApplicationViewModel(candidateId, savedViewModel, newViewModel);

            patchedViewModel.Should().NotBeNull();
            patchedViewModel.ViewModelMessage.Should().BeNull();
            patchedViewModel.HasError().Should().BeFalse();
            patchedViewModel.Candidate.HasWorkExperience.Should().BeTrue();
            patchedViewModel.Candidate.WorkExperience.Should().Equal(workExperience);
        }
Exemple #8
0
        public void GivenVacancyIsExpired_ThenViewModelStatusIsExpired()
        {
            var candidateId      = Guid.NewGuid();
            var candidateService = new Mock <ICandidateService>();
            var apprenticeshipVacancyProvider = new Mock <IApprenticeshipVacancyProvider>();

            candidateService.Setup(cs => cs.GetApplication(candidateId, ValidVacancyId)).Returns(new ApprenticeshipApplicationDetailBuilder(candidateId, ValidVacancyId).Build);
            candidateService.Setup(cs => cs.GetCandidate(candidateId)).Returns(new CandidateBuilder(candidateId).Build);
            candidateService.Setup(cs => cs.GetApprenticeshipApplications(candidateId, It.IsAny <bool>())).Returns(new ApprenticeshipApplicationSummary[0]);
            candidateService.Setup(
                cs => cs.GetSuggestedApprenticeshipVacancies(It.IsAny <ApprenticeshipSearchParameters>(), candidateId, ValidVacancyId))
            .Returns(new SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters>(0, new List <ApprenticeshipSearchResponse>(), null, new ApprenticeshipSearchParameters {
                Location = new Location()
            }));
            apprenticeshipVacancyProvider.Setup(cs => cs.GetVacancyDetailViewModel(candidateId, ValidVacancyId)).Returns(new ApprenticeshipVacancyDetailViewModelBuilder().WithVacancyStatus(VacancyStatuses.Expired).Build());

            var returnedViewModel = new ApprenticeshipApplicationProviderBuilder()
                                    .With(candidateService).With(apprenticeshipVacancyProvider).Build()
                                    .GetWhatHappensNextViewModel(candidateId, ValidVacancyId, null);

            returnedViewModel.HasError().Should().BeFalse();
            returnedViewModel.ViewModelMessage.Should().BeNullOrEmpty();
            returnedViewModel.VacancyStatus.Should().Be(VacancyStatuses.Expired);
        }