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
            });
        }
        public async Task ThenShouldResolveDataLocksLinkedToAppriceshipWhenStopDateEqualsStartDate()
        {
            var listOfDataLockStatuses = new List<DataLockStatus>
            {
                new DataLockStatus {DataLockEventId = 1},
                new DataLockStatus {DataLockEventId = 2}
            };
            ExampleValidRequest.StopDate = TestApprenticeship.StartDate.Value;
            MockDataLockRepository.Setup(x => x.GetDataLocks(It.IsAny<long>(), false)).ReturnsAsync(listOfDataLockStatuses);

            await Handler.Handle(ExampleValidRequest);

            MockDataLockRepository.Verify(x => x.GetDataLocks(TestApprenticeship.Id, false));
            MockDataLockRepository.Verify(x => x.ResolveDataLock(It.Is<IEnumerable<long>>(p => p.SequenceEqual(new [] {1L, 2L}))));
        }
        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 async Task ThenACourseDataLocksThatHaveBeenTriagedAsResetAreResolved()
        {
            var dataLocks = new List <DataLockStatus>
            {
                new DataLockStatus
                {
                    TriageStatus = TriageStatus.Restart,
                    IsResolved   = false,
                    ErrorCode    = DataLockErrorCode.Dlock04
                }
            };

            MockDataLockRepository.Setup(x => x.GetDataLocks(444, false)).ReturnsAsync(dataLocks);

            await Handler.Handle(ExampleValidRequest);

            MockDataLockRepository.Verify(x => x.UpdateDataLockStatus(It.Is <DataLockStatus>(a => a.IsResolved)),
                                          Times.Once);
        }
        public async Task ThenIfStopBackdatedToStartThenAllOutstandingDataLocksAreResolved()
        {
            ExampleValidRequest.DateOfChange = TestApprenticeship.StartDate.Value;

            var dataLocks = new List <DataLockStatus>
            {
                new DataLockStatus
                {
                    DataLockEventId = 1,
                    TriageStatus    = TriageStatus.Restart,
                    IsResolved      = false,
                    ErrorCode       = DataLockErrorCode.Dlock04
                },
                new DataLockStatus
                {
                    DataLockEventId = 2,
                    TriageStatus    = TriageStatus.Unknown,
                    IsResolved      = false,
                    ErrorCode       = DataLockErrorCode.Dlock03
                },
                new DataLockStatus
                {
                    DataLockEventId = 3,
                    TriageStatus    = TriageStatus.Change,
                    IsResolved      = false,
                    ErrorCode       = DataLockErrorCode.Dlock07
                }
            };

            MockDataLockRepository.Setup(x => x.GetDataLocks(444, false)).ReturnsAsync(dataLocks);

            await Handler.Handle(ExampleValidRequest);

            MockDataLockRepository.Verify(x => x.GetDataLocks(TestApprenticeship.Id, false));

            MockDataLockRepository.Verify(x =>
                                          x.ResolveDataLock(It.Is <IEnumerable <long> >(p => p.SequenceEqual(new List <long> {
                1, 2, 3
            }))));
        }