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 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 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);
        }
        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 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);
        }
예제 #9
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);
        }
예제 #10
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);
        }
예제 #12
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);
        }
예제 #13
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);
        }