public async Task Then_the_learning_stopped_event_is_raised_when_learning_is_stopped_and_the_incentive_is_already_in_a_stopped_state()
        {
            //Arrange
            _incentiveModel.Status = IncentiveStatus.Stopped;

            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            var stoppedStatus = new LearningStoppedStatus(true, DateTime.Now.AddDays(-2));

            var learningData = new LearningData(true);

            learningData.SetIsStopped(stoppedStatus);
            var submissionData = _fixture.Create <SubmissionData>();

            submissionData.SetSubmissionDate(DateTime.Today);
            submissionData.SetLearningData(learningData);

            _learner = new LearnerFactory().GetExisting(
                _fixture.Build <LearnerModel>()
                .With(x => x.SubmissionData, submissionData)
                .With(x => x.ApprenticeshipIncentiveId, _incentive.Id)
                .With(x => x.ApprenticeshipIncentiveId, _incentive.Id)
                .Create());

            _mockLearnerDomainRepository.Setup(m => m.GetOrCreate(_incentive)).ReturnsAsync(_learner);

            // Act
            await _sut.Handle(command);

            // Assert
            _incentive.FlushEvents().Count(e => e is LearningStopped).Should().Be(0);
        }
Beispiel #2
0
        public async Task Then_HasPossibleChangeOfCircumstances_set_to_false_when_change_of_circs_complete()
        {
            //Arrange
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            // Act
            await _sut.Handle(command);

            // Assert
            _incentive.HasPossibleChangeOfCircumstances.Should().BeFalse();
        }
Beispiel #3
0
        public async Task Then_process_should_exit_if_no_possible_change_of_circumstances()
        {
            //Arrange
            _incentive.SetHasPossibleChangeOfCircumstances(false);
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            // Act
            await _sut.Handle(command);

            // Assert
            _mockLearnerDomainRespository.Verify(x => x.GetOrCreate(It.IsAny <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>()), Times.Never);
            _mockIncentiveDomainRespository.Verify(x => x.Save(It.IsAny <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>()), Times.Never);
        }
        public async Task Then_the_learning_stopped_event_is_not_raise_when_submission_data_was_not_found()
        {
            //Arrange
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            _learner.SetSubmissionData(null);

            // Act
            await _sut.Handle(command);

            // Assert
            _incentive.FlushEvents().Count(e => e is LearningStopped).Should().Be(0);
        }
        public async Task Then_the_learning_stopped_status_is_not_updated_when_submission_data_was_not_found()
        {
            //Arrange
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            _learner.SetSubmissionData(null);

            // Act
            await _sut.Handle(command);

            // Assert
            _incentive.GetModel().Status.Should().Be(IncentiveStatus.Active);
        }
Beispiel #6
0
        public async Task Then_the_start_date_is_not_updated_when_submission_has_no_start_date()
        {
            //Arrange
            var originalStartDate = _incentive.StartDate;
            var command           = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            _learner.SubmissionData.LearningData.SetStartDate(null);

            // Act
            await _sut.Handle(command);

            // Assert
            _incentive.StartDate.Should().Be(originalStartDate);
        }
Beispiel #7
0
        public async Task Then_the_start_date_is_updated()
        {
            //Arrange
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            _learner.SubmissionData.SetSubmissionDate(_fixture.Create <DateTime>());
            _learner.SubmissionData.SetLearningData(new LearningData(true));
            _learner.SubmissionData.LearningData.SetStartDate(_fixture.Create <DateTime>());

            // Act
            await _sut.Handle(command);

            // Assert
            _incentive.StartDate.Should().Be(_learner.SubmissionData.LearningData.StartDate.Value);
        }
Beispiel #8
0
        public async Task Then_the_StartdateChanged_event_is_not_raised_if_the_start_date_is_the_same_as_the_previous_start_date()
        {
            //Arrange
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            _learner.SubmissionData.SetSubmissionDate(_fixture.Create <DateTime>());
            _learner.SubmissionData.SetLearningData(new LearningData(true));
            _learner.SubmissionData.LearningData.SetStartDate(_incentive.StartDate);

            // Act
            await _sut.Handle(command);

            // Assert
            _incentive.FlushEvents().Count(e => e is StartDateChanged).Should().Be(0);
        }
Beispiel #9
0
        public async Task Then_the_StartdateChanged_event_is_raised()
        {
            //Arrange
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            _learner.SubmissionData.SetSubmissionDate(_fixture.Create <DateTime>());
            _learner.SubmissionData.SetLearningData(new LearningData(true));
            var newStartDate      = _incentive.StartDate.AddMonths(2);
            var previousStartDate = _incentive.StartDate;

            _learner.SubmissionData.LearningData.SetStartDate(newStartDate);

            // Act
            await _sut.Handle(command);

            // Assert
            var @event = _incentive.FlushEvents().Single(e => e is StartDateChanged) as StartDateChanged;

            @event.ApprenticeshipIncentiveId.Should().Be(_incentive.Id);
            @event.NewStartDate.Should().Be(newStartDate);
            @event.PreviousStartDate.Should().Be(previousStartDate);
        }
Beispiel #10
0
        public async Task Then_the_changes_are_persisted()
        {
            //Arrange
            var command = new LearnerChangeOfCircumstanceCommand(_incentive.Id);

            _learner.SubmissionData.LearningData.SetStartDate(_fixture.Create <DateTime>());

            int itemsPersisted = 0;

            _mockIncentiveDomainRespository.Setup(m => m.Save(It.Is <Domain.ApprenticeshipIncentives.ApprenticeshipIncentive>(a => a.Id == command.ApprenticeshipIncentiveId)))
            .Callback(() =>
            {
                itemsPersisted++;
            });


            // Act
            await _sut.Handle(command);

            // Assert
            itemsPersisted.Should().Be(1);
        }