public override void SetUp()
        {
            base.SetUp();


            ExampleValidRequest = new PauseApprenticeshipCommand
            {
                AccountId        = 111L,
                ApprenticeshipId = 444L,
                DateOfChange     = DateTime.Now.Date,
                UserName         = "******"
            };

            TestApprenticeship = new Apprenticeship
            {
                CommitmentId  = 123L,
                PaymentStatus = PaymentStatus.Active,
                StartDate     = DateTime.UtcNow.Date.AddMonths(6)
            };

            MockCurrentDateTime.SetupGet(x => x.Now).Returns(DateTime.UtcNow);

            MockApprenticeshipRespository
            .Setup(x => x.GetApprenticeship(It.Is <long>(y => y == ExampleValidRequest.ApprenticeshipId)))
            .ReturnsAsync(TestApprenticeship);

            MockApprenticeshipRespository
            .Setup(x => x.UpdateApprenticeshipStatus(TestApprenticeship.CommitmentId,
                                                     ExampleValidRequest.ApprenticeshipId,
                                                     PaymentStatus.Paused))
            .Returns(Task.FromResult(new object()));
        }
예제 #2
0
        public void ShouldBeInvalidIfYoungerThan15OnStartDate()
        {
            MockCurrentDateTime.SetupGet(x => x.Now).Returns(new DateTime(2017, 06, 10));
            ExampleValidApprenticeship.StartDate   = new DateTime(2017, 08, 01);
            ExampleValidApprenticeship.DateOfBirth = new DateTime(2003, 04, 01);

            var result = Validator.Validate(ExampleValidApprenticeship);

            result.IsValid.Should().BeFalse();
        }
예제 #3
0
        public void ShouldThrowStartDateValidationErrorAfterR14CloseAndStopDateBeforeStartDate()
        {
            TestApprenticeship.StartDate     = new DateTime(2017, 3, 1);
            ExampleValidRequest.DateOfChange = new DateTime(2017, 1, 1);                         //last academic year
            MockCurrentDateTime.Setup(x => x.Now).Returns(new DateTime(2017, 10, 19, 18, 0, 1)); //after cut-off

            Func <Task> act = async() => await Handler.Handle(ExampleValidRequest);

            act.ShouldThrow <ValidationException>()
            .WithMessage("Invalid Date of Change. Date cannot be before the training start date.");
        }
예제 #4
0
        public void ShouldFailValidationForPlanedEndDateWithCurrentDate()
        {
            MockCurrentDateTime.SetupGet(x => x.Now).Returns(new DateTime(2017, 7, 15));
            ValidModel.ApprenticeshipViewModel.StartDate = new DateTimeViewModel(new DateTime(2017, 7, 20));
            ValidModel.ApprenticeshipViewModel.EndDate   = new DateTimeViewModel(new DateTime(2017, 7, 18));

            var result = Validator.Validate(ValidModel);

            result.IsValid.Should().BeFalse();
            result.Errors[0].ErrorMessage.Should().Be("You must not enter an <strong>end date</strong> that's earlier than the start date");
        }
예제 #5
0
        public void ShouldBeValidIfOlderThan15OnStartDate(int year, int month, int day)
        {
            var dob = new DateTime(year, month, day);

            MockCurrentDateTime.SetupGet(x => x.Now).Returns(new DateTime(2017, 6, 10));
            ExampleValidApprenticeship.StartDate   = new DateTime(2017, 8, 1);
            ExampleValidApprenticeship.DateOfBirth = dob;

            var result = Validator.Validate(ExampleValidApprenticeship);

            result.IsValid.Should().BeTrue();
        }
        public override void SetUp()
        {
            base.SetUp();


            ExampleValidRequest = new StopApprenticeshipCommand
            {
                AccountId        = 111L,
                ApprenticeshipId = 444L,
                DateOfChange     = DateTime.UtcNow.Date.AddMonths(6),
                UserName         = "******"
            };

            TestApprenticeship = new Apprenticeship
            {
                Id            = 444L,
                CommitmentId  = 123L,
                PaymentStatus = PaymentStatus.Active,
                StartDate     = DateTime.UtcNow.Date.AddMonths(6)
            };

            MockCurrentDateTime.SetupGet(x => x.Now)
            .Returns(DateTime.UtcNow);

            MockApprenticeshipRespository.Setup(x =>
                                                x.GetApprenticeship(It.Is <long>(y => y == ExampleValidRequest.ApprenticeshipId)))
            .ReturnsAsync(TestApprenticeship);

            MockApprenticeshipRespository.Setup(x =>
                                                x.UpdateApprenticeshipStatus(
                                                    It.Is <long>(c => c == TestApprenticeship.CommitmentId),
                                                    It.Is <long>(a => a == ExampleValidRequest.ApprenticeshipId),
                                                    It.Is <PaymentStatus>(s => s == PaymentStatus.Withdrawn)))
            .Returns(Task.FromResult(new object()));

            MockDataLockRepository.Setup(x => x.GetDataLocks(ExampleValidRequest.ApprenticeshipId, false))
            .ReturnsAsync(new List <DataLockStatus>());

            MockDataLockRepository.Setup(x => x.ResolveDataLock(It.IsAny <IEnumerable <long> >()))
            .Returns(Task.CompletedTask);

            MockCommitmentRespository.Setup(x => x.GetCommitmentById(
                                                It.Is <long>(c => c == TestApprenticeship.CommitmentId)))
            .ReturnsAsync(new Commitment
            {
                Id = 123L,
                EmployerAccountId = ExampleValidRequest.AccountId
            });
        }
예제 #7
0
        public override void SetUp()
        {
            base.SetUp();


            MockCurrentDateTime.SetupGet(x => x.Now).Returns(new DateTime(2017, 6, 1));

            var startDate = MockCurrentDateTime.Object.Now.Date.AddMonths(-6);
            var pauseDate = startDate.AddMonths(1);

            TestApprenticeship = new Apprenticeship
            {
                CommitmentId  = 123L,
                PaymentStatus = PaymentStatus.Paused,
                StartDate     = startDate,
                PauseDate     = pauseDate
            };

            ExampleValidRequest = new ResumeApprenticeshipCommand
            {
                AccountId        = 111L,
                ApprenticeshipId = 444L,
                DateOfChange     = pauseDate.Date,
                UserName         = "******"
            };

            _testCommitment = new Commitment
            {
                Id = 123L,
                EmployerAccountId = ExampleValidRequest.AccountId
            };

            MockApprenticeshipRespository.Setup(x =>
                                                x.GetApprenticeship(It.Is <long>(y => y == ExampleValidRequest.ApprenticeshipId)))
            .ReturnsAsync(TestApprenticeship);

            MockApprenticeshipRespository.Setup(x =>
                                                x.UpdateApprenticeshipStatus(
                                                    It.Is <long>(c => c == TestApprenticeship.CommitmentId),
                                                    It.Is <long>(a => a == ExampleValidRequest.ApprenticeshipId),
                                                    It.Is <PaymentStatus>(s => s == PaymentStatus.Active)))
            .Returns(Task.FromResult(new object()));


            MockCommitmentRespository.Setup(x => x.GetCommitmentById(
                                                It.Is <long>(c => c == TestApprenticeship.CommitmentId)))
            .ReturnsAsync(_testCommitment);
        }
        public override void SetUp()
        {
            base.SetUp();


            ExampleValidRequest = new UpdateApprenticeshipStopDateCommand
            {
                AccountId = 111L,
                ApprenticeshipId = 444L,
                StopDate = DateTime.UtcNow.Date,
                UserName = "******"
            };

            _testCommitment = new Commitment
            {
                Id = 123L,
                EmployerAccountId = ExampleValidRequest.AccountId
            };

            TestApprenticeship = new Apprenticeship
            {
                Id = 444L,
                CommitmentId = 123L,
                PaymentStatus = PaymentStatus.Withdrawn,
                StopDate = DateTime.UtcNow.Date.AddMonths(3),
                StartDate = DateTime.UtcNow.Date.AddMonths(-1)
            };


            MockCurrentDateTime.SetupGet(x => x.Now)
                .Returns(DateTime.UtcNow);


            MockApprenticeshipRespository.Setup(x =>
                    x.GetApprenticeship(It.Is<long>(y => y == ExampleValidRequest.ApprenticeshipId)))
                .ReturnsAsync(TestApprenticeship);
            MockApprenticeshipRespository.Setup(x =>
                    x.UpdateApprenticeshipStatus(It.IsAny<long>(), It.IsAny<long>(), It.IsAny<PaymentStatus>()))
                .Returns(Task.FromResult(new object()));
            MockDataLockRepository.Setup(x => x.GetDataLocks(ExampleValidRequest.ApprenticeshipId, false))
                .ReturnsAsync(new List<DataLockStatus>());

            MockCommitmentRespository.Setup(x => x.GetCommitmentById(123L)).ReturnsAsync(_testCommitment);

            MockApprenticeshipEventsPublisher.Setup(x => x.Publish(It.IsAny<IApprenticeshipEventsList>()))
                .Returns(Task.FromResult(new Unit()));
        }
        public void ShouldThrowStartDateValidationErrorAfterR14CloseAndStopDateBeforeStartDate()
        {
            MockCommitmentRespository.Setup(x => x.GetCommitmentById(123L)).ReturnsAsync(new Commitment
            {
                Id = 123L,
                EmployerAccountId = ExampleValidRequest.AccountId
            });

            TestApprenticeship.StartDate     = new DateTime(2016, 3, 1);
            ExampleValidRequest.DateOfChange = new DateTime(2016, 1, 1);               //last academic year
            MockCurrentDateTime.Setup(x => x.Now).Returns(new DateTime(2016, 10, 19)); //after cut-off

            Func <Task> act = async() => await Handler.Handle(ExampleValidRequest);

            act.ShouldThrow <ValidationException>()
            .WithMessage("Invalid Date of Change. Date cannot be before the training start date.");
        }
예제 #10
0
        public void ThenItValidatesDataofChangeAccordingToAcademicYearRule(
            DateTime academicYearStart,
            DateTime academicYearEnd,
            DateTime academicYearR14Cutoff,
            DateTime startDate,
            DateTime pausedDate,
            DateTime resumeDate,
            DateTime timeNow,
            bool expectToPassValidation,
            bool validatesOnStartDate, string scenario)
        {
            MockAcademicYearDateProvider.Setup(y => y.CurrentAcademicYearStartDate).Returns(academicYearStart);
            MockAcademicYearDateProvider.Setup(y => y.CurrentAcademicYearEndDate).Returns(academicYearEnd);
            MockAcademicYearDateProvider.Setup(y => y.LastAcademicYearFundingPeriod).Returns(academicYearR14Cutoff);

            if (timeNow > academicYearR14Cutoff)
            {
                MockAcademicYearValidator.Setup(v => v.Validate(It.IsAny <DateTime>()))
                .Returns(AcademicYearValidationResult.NotWithinFundingPeriod);
            }
            else
            {
                MockAcademicYearValidator.Setup(v => v.Validate(It.IsAny <DateTime>()))
                .Returns(AcademicYearValidationResult.Success);
            }

            MockCurrentDateTime.Setup(d => d.Now).Returns(timeNow);

            TestApprenticeship.PauseDate     = pausedDate.Date;
            ExampleValidRequest.DateOfChange = resumeDate.Date;

            Func <Task> act = async() => await Handler.Handle(ExampleValidRequest);

            if (expectToPassValidation)
            {
                act.ShouldNotThrow <ValidationException>();
            }
            else
            {
                act.ShouldThrow <ValidationException>()
                .Which.Message.Should().Be(validatesOnStartDate
                        ? "Invalid Date of Change. Date should be the academic year start date."
                        : "Invalid Date of Change. Date should be the pause date.");
            }
        }
예제 #11
0
        public void ShouldThrowValidationErrorAfterR14Close(AcademicYearValidationResult academicYearValidationResult,
                                                            bool expectedPassValidation)
        {
            TestApprenticeship.StartDate     = new DateTime(2017, 3, 1);                         //early last academic year
            ExampleValidRequest.DateOfChange = new DateTime(2017, 5, 1);                         //last academic year
            MockCurrentDateTime.Setup(x => x.Now).Returns(new DateTime(2017, 10, 19, 18, 0, 1)); //after cut-off

            MockAcademicYearValidator.Setup(x => x.Validate(It.IsAny <DateTime>()))
            .Returns(academicYearValidationResult);

            Func <Task> act = async() => await Handler.Handle(ExampleValidRequest);

            if (expectedPassValidation)
            {
                act.ShouldNotThrow <ValidationException>();
            }
            else
            {
                act.ShouldThrow <ValidationException>()
                .WithMessage("Invalid Date of Change. Date cannot be before the academic year start date.");
            }
        }