public void ShouldReturnFailedValidationIfTheViewModelIsNotCorrect()
        {
            const int vacancyReferenceNumber = 1;
            var       vacancy = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            vacancy.NewVacancyViewModel.Title = null; // Make the vacancy invalid

            var mediator = new VacancyMediatorBuilder().Build();

            var result = mediator.UpdateVacancy(vacancy.NewVacancyViewModel);

            result.AssertValidationResult(VacancyMediatorCodes.UpdateVacancy.FailedValidation);
        }
        public void ShouldGetStatusOkIfNoProblem()
        {
            const int vacancyReferenceNumber = 1;
            var       provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.GetNextAvailableVacancy()).Returns(new DashboardVacancySummaryViewModel());

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.RejectVacancy(vacancyReferenceNumber);

            result.Code.Should().Be(VacancyMediatorCodes.RejectVacancy.Ok);
        }
        public void ShouldReturnInvalidVacancyIfTheVacancyIsNotAvailableToQA()
        {
            const int vacancyReferenceNumber = 1;
            var       provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.RejectVacancy(vacancyReferenceNumber)).Returns(QAActionResultCode.InvalidVacancy);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.RejectVacancy(vacancyReferenceNumber);

            result.AssertMessage(VacancyMediatorCodes.RejectVacancy.InvalidVacancy, VacancyViewModelMessages.InvalidVacancy, UserMessageLevel.Error);
        }
        public void ShouldReturnFailedValidationIfTheViewModelIsNotCorrect()
        {
            const int vacancyReferenceNumber = 1;
            var       vacancy = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            vacancy.TrainingDetailsViewModel.ContactName = @"<script> </script>"; // Make the vacancy invalid

            var mediator = new VacancyMediatorBuilder().Build();

            var result = mediator.UpdateVacancy(vacancy.TrainingDetailsViewModel);

            result.AssertValidationResult(VacancyMediatorCodes.UpdateVacancy.FailedValidation);
        }
        public void ShouldReturnFailedValidationIfTheViewModelIsNotCorrect()
        {
            const int vacancyReferenceNumber = 1;
            var       vacancy = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            vacancy.VacancyRequirementsProspectsViewModel.DesiredQualifications = @"<script> </script>"; // Make the vacancy invalid

            var mediator = new VacancyMediatorBuilder().Build();

            var result = mediator.UpdateVacancy(vacancy.VacancyRequirementsProspectsViewModel);

            result.AssertValidationResult(VacancyMediatorCodes.UpdateVacancy.FailedValidation);
        }
        public void ShouldReturnPostcodeLookupFailedIfTheVacancyIsThereWasAnErrorGeocodingTheVacancy()
        {
            const int vacancyReferenceNumber = 1;
            var       provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.ApproveVacancy(vacancyReferenceNumber)).Returns(QAActionResultCode.GeocodingFailure);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.ApproveVacancy(vacancyReferenceNumber);

            result.AssertMessage(VacancyMediatorCodes.ApproveVacancy.PostcodeLookupFailed, VacancyViewModelMessages.PostcodeLookupFailed, UserMessageLevel.Error);
        }
Beispiel #7
0
        public void GetVacancySummaryViewModelShoudReturnOkIfValidationPassed()
        {
            const int vacancyReferenceNumber = 1;
            var       vacancyProvider        = new Mock <IVacancyQAProvider>();

            vacancyProvider.Setup(vp => vp.GetVacancySummaryViewModel(vacancyReferenceNumber)).Returns(GetValidVacancySummaryViewModel(vacancyReferenceNumber));

            var mediator = new VacancyMediatorBuilder().With(vacancyProvider).Build();

            var response = mediator.GetVacancySummaryViewModel(vacancyReferenceNumber);

            response.AssertCodeAndMessage(VacancyMediatorCodes.GetVacancySummaryViewModel.Ok);
        }
Beispiel #8
0
        public void GetVacancyQuestionsViewModelShouldGetViewmodelFromProvider()
        {
            const int vacancyReferenceNumber = 1;
            var       vacancyProvider        = new Mock <IVacancyQAProvider>();
            var       mediator  = new VacancyMediatorBuilder().With(vacancyProvider).Build();
            var       viewModel = new VacancyQuestionsViewModel();

            vacancyProvider.Setup(vp => vp.GetVacancyQuestionsViewModel(vacancyReferenceNumber)).Returns(viewModel);

            var result = mediator.GetVacancyQuestionsViewModel(vacancyReferenceNumber);

            result.AssertCodeAndMessage(VacancyMediatorCodes.GetVacancyQuestionsViewModel.Ok);
            vacancyProvider.Verify(vp => vp.GetVacancyQuestionsViewModel(vacancyReferenceNumber));
        }
        public void ShouldReturnNoAvailableVacanciesIfThereArentAnyAvailableVacancies()
        {
            const int vacancyReferenceNumber             = 1;
            DashboardVacancySummaryViewModel nullVacancy = null;

            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.GetNextAvailableVacancy()).Returns(nullVacancy);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.RejectVacancy(vacancyReferenceNumber);

            result.AssertMessage(VacancyMediatorCodes.RejectVacancy.NoAvailableVacancies, VacancyViewModelMessages.NoVacanciesAvailble, UserMessageLevel.Info);
        }
        public void ShouldCallProviderUnreserveForQA()
        {
            const int vacancyReferenceNumber = 1;
            var       viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.ReserveVacancyForQA(vacancyReferenceNumber)).Returns(viewModel);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            mediator.UnReserveVacancyForQA(vacancyReferenceNumber);

            provider.Verify(p => p.UnReserveVacancyForQA(vacancyReferenceNumber), Times.Once);
        }
        public void ShouldAlwaysReturnOk()
        {
            const int vacancyReferenceNumber = 1;
            var       viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.ReserveVacancyForQA(vacancyReferenceNumber)).Returns(viewModel);

            var mediator = new VacancyMediatorBuilder().Build();

            var result = mediator.UnReserveVacancyForQA(vacancyReferenceNumber);

            result.AssertCodeAndMessage(VacancyMediatorCodes.UnReserveVacancyForQA.Ok);
        }
        public void ShouldReturnInvalidVacancyIfTheVacancyIsNotAvailableToQA()
        {
            const int vacancyReferenceNumber = 1;
            var       provider       = new Mock <IVacancyQAProvider>();
            var       vacancy        = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);
            var       qaActionResult = new QAActionResult <VacancyRequirementsProspectsViewModel>(QAActionResultCode.InvalidVacancy);

            provider.Setup(p => p.UpdateVacancyWithComments(vacancy.VacancyRequirementsProspectsViewModel)).Returns(qaActionResult);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.UpdateVacancy(vacancy.VacancyRequirementsProspectsViewModel);

            result.AssertMessage(VacancyMediatorCodes.UpdateVacancy.InvalidVacancy, VacancyViewModelMessages.InvalidVacancy, UserMessageLevel.Error);
        }
Beispiel #13
0
        public void UpdateVacancyWithAVacancyThatDontAcceptsWarningsWithWarningsShouldNotUpdateVacancy()
        {
            var vacancyProvider = new Mock <IVacancyQAProvider>();

            var mediator  = new VacancyMediatorBuilder().With(vacancyProvider).Build();
            var viewModel = GetValidVacancySummaryViewModel(1);

            viewModel.VacancyDatesViewModel.ClosingDate = new DateViewModel(DateTime.UtcNow.AddDays(10));
            viewModel.AcceptWarnings = false;

            var result = mediator.UpdateVacancy(viewModel);

            result.AssertValidationResult(VacancyMediatorCodes.UpdateVacancy.FailedValidation);
            vacancyProvider.Verify(vp => vp.UpdateVacancyWithComments(viewModel), Times.Never);
        }
Beispiel #14
0
        public void ShouldReturnAMessageIfTheVacancyReturnedIsNull()
        {
            const int vacancyReferenceNumber = 1;
            VacancyViewModel viewModel = null;

            var provider = new Mock<IVacancyQAProvider>();

            provider.Setup(p => p.ReviewVacancy(vacancyReferenceNumber)).Returns(viewModel);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.ReviewVacancy(vacancyReferenceNumber);

            result.AssertMessage(VacancyMediatorCodes.ReviewVacancy.InvalidVacancy,
                VacancyViewModelMessages.InvalidVacancy, UserMessageLevel.Error);
        }
        public void ShouldReturnOkIsThereIsNotAnyIssue()
        {
            const int vacancyReferenceNumber = 1;
            var       provider       = new Mock <IVacancyQAProvider>();
            var       vacancy        = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);
            var       qaActionResult = new QAActionResult <VacancyRequirementsProspectsViewModel>(QAActionResultCode.Ok, vacancy.VacancyRequirementsProspectsViewModel);

            provider.Setup(p => p.UpdateVacancyWithComments(vacancy.VacancyRequirementsProspectsViewModel)).Returns(qaActionResult);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.UpdateVacancy(vacancy.VacancyRequirementsProspectsViewModel);

            result.AssertCodeAndMessage(VacancyMediatorCodes.UpdateVacancy.Ok);
            result.ViewModel.ShouldBeEquivalentTo(vacancy.VacancyRequirementsProspectsViewModel);
        }
        public void ShouldNotIncludeAnyMessageIfTheVacancyReservedIsTheRequestedOne()
        {
            const int vacancyReferenceNumber = 1;
            var       viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.ReserveVacancyForQA(vacancyReferenceNumber)).Returns(viewModel);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.ReserveVacancyForQA(vacancyReferenceNumber);

            result.AssertCodeAndMessage(VacancyMediatorCodes.ReserveVacancyForQA.Ok);
            result.ViewModel.VacancyReferenceNumber.Should().Be(vacancyReferenceNumber);
        }
        public void ShouldReturnAMessageIfNoVacancyIsAvailable()
        {
            const int        vacancyReferenceNumber = 1;
            VacancyViewModel viewModel = null;

            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.ReserveVacancyForQA(vacancyReferenceNumber)).Returns(viewModel);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.ReserveVacancyForQA(vacancyReferenceNumber);

            result.AssertMessage(VacancyMediatorCodes.ReserveVacancyForQA.NoVacanciesAvailable,
                                 "All vacancies have been reviewed.", UserMessageLevel.Info);
            result.ViewModel.Should().BeNull();
        }
        public void ShouldGetTheNextVacancyIfVacancyIsRejected()
        {
            const int vacancyReferenceNumber = 1;
            var       pendingQAVacancies     = VacancyMediatorTestHelper.GetPendingVacancies(new[]
            {
                vacancyReferenceNumber
            });
            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.GetPendingQAVacancies()).Returns(pendingQAVacancies.ToList());

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            mediator.RejectVacancy(vacancyReferenceNumber);

            provider.Verify(p => p.GetNextAvailableVacancy(), Times.Once);
        }
        public void ShouldUpdateTheStatusOfTheVacancyToLive()
        {
            const int vacancyReferenceNumber = 1;
            var       pendingQAVacancies     = VacancyMediatorTestHelper.GetPendingVacancies(new[]
            {
                vacancyReferenceNumber
            });
            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.GetPendingQAVacancies()).Returns(pendingQAVacancies.ToList());

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            mediator.ApproveVacancy(vacancyReferenceNumber);

            provider.Verify(p => p.ApproveVacancy(vacancyReferenceNumber), Times.Once);
        }
Beispiel #20
0
        public void ShouldCallTheVacancyValidator()
        {
            const int vacancyReferenceNumber = 1;
            var viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            var provider = new Mock<IVacancyQAProvider>();
            provider.Setup(p => p.ReviewVacancy(vacancyReferenceNumber)).Returns(viewModel);

            var validator = new Mock<VacancyViewModelValidator>();
            validator.Setup(v => v.Validate(It.IsAny<VacancyViewModel>()))
                .Returns(new ValidationResult());

            var mediator = new VacancyMediatorBuilder().With(validator).With(provider).Build();

            mediator.ReviewVacancy(vacancyReferenceNumber);

            validator.Verify(v => v.Validate(It.IsAny<VacancyViewModel>()), Times.Once);
        }
Beispiel #21
0
        public void UpdateVacancyWithAVacancyThatAcceptsWarningsWithWarningsShouldUpdateVacancy()
        {
            var vacancyProvider = new Mock <IVacancyQAProvider>();

            var mediator  = new VacancyMediatorBuilder().With(vacancyProvider).Build();
            var viewModel = GetValidVacancySummaryViewModel(1);

            viewModel.VacancyDatesViewModel.ClosingDate = new DateViewModel(DateTime.UtcNow.AddDays(10));
            viewModel.AcceptWarnings = true;

            vacancyProvider.Setup(vp => vp.UpdateVacancyWithComments(viewModel))
            .Returns(new QAActionResult <FurtherVacancyDetailsViewModel>(QAActionResultCode.Ok,
                                                                         new FurtherVacancyDetailsViewModel()));

            var result = mediator.UpdateVacancy(viewModel);

            result.AssertCodeAndMessage(VacancyMediatorCodes.UpdateVacancy.Ok);
            vacancyProvider.Verify(vp => vp.UpdateVacancyWithComments(viewModel));
        }
        public void ShouldReturnTheNextAvailableVacancyAfterRejectingOne()
        {
            const int vacancyReferenceNumber     = 1;
            const int nextVacancyReferenceNumber = 2;

            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.GetNextAvailableVacancy())
            .Returns(new DashboardVacancySummaryViewModel {
                VacancyReferenceNumber = nextVacancyReferenceNumber
            });

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.RejectVacancy(vacancyReferenceNumber);

            result.AssertCodeAndMessage(VacancyMediatorCodes.RejectVacancy.Ok);
            result.ViewModel.VacancyReferenceNumber.Should().Be(nextVacancyReferenceNumber);
        }
Beispiel #23
0
        public void ShouldReturnTheViewModelIfAllIsOk()
        {
            const int vacancyReferenceNumber = 1;
            var viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);

            var provider = new Mock<IVacancyQAProvider>();

            provider.Setup(p => p.ReviewVacancy(vacancyReferenceNumber)).Returns(viewModel);

            var validator = new Mock<VacancyViewModelValidator>();
            validator.Setup(v => v.Validate(It.IsAny<VacancyViewModel>()))
                .Returns(new ValidationResult());

            var mediator = new VacancyMediatorBuilder().With(validator).With(provider).Build();

            var result = mediator.ReviewVacancy(vacancyReferenceNumber);

            result.AssertCodeAndMessage(VacancyMediatorCodes.ReviewVacancy.Ok);
            result.ViewModel.VacancyReferenceNumber.Should().Be(vacancyReferenceNumber);
        }
        public void ShouldIncludeAMessageIfTheVacancyReservedIsNotTheRequestedOne()
        {
            const int vacancyReferenceNumber        = 1;
            const int anotherVacancyReferenceNumber = 2;
            var       viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(anotherVacancyReferenceNumber);

            var provider = new Mock <IVacancyQAProvider>();

            provider.Setup(p => p.ReserveVacancyForQA(vacancyReferenceNumber)).Returns(viewModel);

            var mediator = new VacancyMediatorBuilder().With(provider).Build();

            var result = mediator.ReserveVacancyForQA(vacancyReferenceNumber);

            result.Code.Should().Be(VacancyMediatorCodes.ReserveVacancyForQA.NextAvailableVacancy);
            result.ViewModel.VacancyReferenceNumber.Should().NotBe(vacancyReferenceNumber);
            result.ViewModel.VacancyReferenceNumber.Should().Be(anotherVacancyReferenceNumber);
            result.AssertMessage(VacancyMediatorCodes.ReserveVacancyForQA.NextAvailableVacancy,
                                 "The first vacancy you chose is already being reviewed by another adviser. This is the next available option.",
                                 UserMessageLevel.Info);
        }
Beispiel #25
0
        public void ShouldReturnTheViewModelAndAMessageIfTheVacancySourceIsNotRaaAndHasValidationErrors(VacancySource vacancySource, string code, string message)
        {
            const int vacancyReferenceNumber = 1;
            var viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber, vacancySource);

            var provider = new Mock<IVacancyQAProvider>();

            provider.Setup(p => p.ReviewVacancy(vacancyReferenceNumber)).Returns(viewModel);

            var validator = new Mock<VacancyViewModelValidator>();
            var validationFailure = new ValidationFailure("NewVacancyViewModel.Title", "someError");
            validator.Setup(v => v.Validate(It.IsAny<VacancyViewModel>()))
                .Returns(new ValidationResult(new[] { validationFailure }));

            var mediator = new VacancyMediatorBuilder().With(validator).With(provider).Build();

            var result = mediator.ReviewVacancy(vacancyReferenceNumber);

            result.ViewModel.VacancyReferenceNumber.Should().Be(vacancyReferenceNumber);
            result.AssertValidationResultWithMessage(code, message, UserMessageLevel.Info, true);
        }
Beispiel #26
0
        public void ShouldReturnAResponseWithValidationErrorsIfThereAreValidationErrors()
        {
            const int vacancyReferenceNumber = 1;
            var viewModel = VacancyMediatorTestHelper.GetValidVacancyViewModel(vacancyReferenceNumber);
            viewModel.NewVacancyViewModel.Title = null;

            var provider = new Mock<IVacancyQAProvider>();
            provider.Setup(p => p.ReviewVacancy(vacancyReferenceNumber)).Returns(viewModel);

            var validator = new Mock<VacancyViewModelValidator>();
            var validationFailure = new ValidationFailure("NewVacancyViewModel.Title", "someError");
            validator.Setup(v => v.Validate(It.IsAny<VacancyViewModel>()))
                .Returns(new ValidationResult(new[] {validationFailure}));

            var mediator = new VacancyMediatorBuilder().With(validator).With(provider).Build();

            var result = mediator.ReviewVacancy(vacancyReferenceNumber);

            result.AssertValidationResult(VacancyMediatorCodes.ReviewVacancy.FailedValidation, true);
            result.ViewModel.VacancyReferenceNumber.Should().Be(vacancyReferenceNumber);
        }
Beispiel #27
0
        public void UpdateVacancyWillNotUpdateVacancyIfViewModelIsNotValid()
        {
            var vacancyProvider = new Mock <IVacancyQAProvider>();

            var mediator  = new VacancyMediatorBuilder().With(vacancyProvider).Build();
            var viewModel = new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(DateTime.UtcNow),
                    PossibleStartDate = new DateViewModel(DateTime.UtcNow)
                },
                Wage = new WageViewModel()
                {
                    Type = WageType.ApprenticeshipMinimum, Classification = WageClassification.ApprenticeshipMinimum, Amount = null, AmountLowerBound = null, AmountUpperBound = null, Text = null, Unit = WageUnit.NotApplicable, HoursPerWeek = null
                }
            };

            var result = mediator.UpdateVacancy(viewModel);

            result.AssertValidationResult(VacancyMediatorCodes.UpdateVacancy.FailedValidation);
            vacancyProvider.Verify(vp => vp.UpdateVacancyWithComments(viewModel), Times.Never);
        }
Beispiel #28
0
        public void GetVacancySummaryViewModelShoudReturnValidationFailedIfValidationFailed()
        {
            const int vacancyReferenceNumber = 1;
            var       vacancyPostingProvider = new Mock <IVacancyQAProvider>();

            vacancyPostingProvider.Setup(vp => vp.GetVacancySummaryViewModel(vacancyReferenceNumber)).Returns(new FurtherVacancyDetailsViewModel
            {
                VacancyDatesViewModel = new VacancyDatesViewModel
                {
                    ClosingDate       = new DateViewModel(DateTime.UtcNow),
                    PossibleStartDate = new DateViewModel(DateTime.UtcNow)
                },
                Wage = new WageViewModel()
                {
                    Type = WageType.ApprenticeshipMinimum, Classification = WageClassification.ApprenticeshipMinimum, Amount = null, AmountLowerBound = null, AmountUpperBound = null, Text = null, Unit = WageUnit.NotApplicable, HoursPerWeek = null
                }
            });

            var mediator = new VacancyMediatorBuilder().With(vacancyPostingProvider).Build();

            var response = mediator.GetVacancySummaryViewModel(vacancyReferenceNumber);

            response.AssertValidationResult(VacancyMediatorCodes.GetVacancySummaryViewModel.FailedValidation);
        }