public async Task ThenAHistoryRecordIsCreated() { MockCommitmentRespository.Setup(x => x.GetCommitmentById(123L)).ReturnsAsync(new Commitment { Id = 123L, EmployerAccountId = ExampleValidRequest.AccountId }); var expectedOriginalApprenticeshipState = JsonConvert.SerializeObject(TestApprenticeship); await Handler.Handle(ExampleValidRequest); var expectedNewApprenticeshipState = JsonConvert.SerializeObject(TestApprenticeship); MockHistoryRepository.Verify( x => x.InsertHistory( It.Is <IEnumerable <HistoryItem> >( y => y.First().ChangeType == ApprenticeshipChangeType.ChangeOfStatus.ToString() && y.First().CommitmentId == null && y.First().ApprenticeshipId == TestApprenticeship.Id && y.First().OriginalState == expectedOriginalApprenticeshipState && y.First().UpdatedByRole == CallerType.Employer.ToString() && y.First().UpdatedState == expectedNewApprenticeshipState && y.First().UserId == ExampleValidRequest.UserId && y.First().UpdatedByName == ExampleValidRequest.UserName)), Times.Once); }
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 ThenShouldCallTheRepositoryToUpdateTheStatus() { MockCommitmentRespository.Setup(x => x.GetCommitmentById(It.IsAny <long>())).ReturnsAsync(new Commitment { Id = 123L, EmployerAccountId = ExampleValidRequest.AccountId }); await Handler.Handle(ExampleValidRequest); MockApprenticeshipRespository.Verify(x => x.PauseOrResumeApprenticeship( It.Is <long>(a => a == 123L), It.Is <long>(a => a == ExampleValidRequest.ApprenticeshipId), It.Is <PaymentStatus>(a => a == PaymentStatus.Active))); }
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 async Task ThenShouldSendAnApprenticeshipEvent() { MockCommitmentRespository.Setup(x => x.GetCommitmentById(It.IsAny <long>())).ReturnsAsync(new Commitment { Id = 123L, EmployerAccountId = ExampleValidRequest.AccountId }); await Handler.Handle(ExampleValidRequest); MockEventsApi.Verify(x => x.PublishChangeApprenticeshipStatusEvent( It.IsAny <Commitment>(), It.IsAny <Apprenticeship>(), It.Is <PaymentStatus>(a => a == PaymentStatus.Active), It.Is <DateTime?>(a => a.Equals(TestApprenticeship.StartDate)), null)); }
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."); }
public void ThenThrowsExceptionIfApprenticeshipIsInProgressAndChangeDateIsInFuture() { var startDate = DateTime.UtcNow.AddMonths(-2).Date; TestApprenticeship.StartDate = startDate; MockCommitmentRespository.Setup(x => x.GetCommitmentById(123L)).ReturnsAsync(new Commitment { Id = 123L, EmployerAccountId = ExampleValidRequest.AccountId }); ExampleValidRequest.DateOfChange = DateTime.UtcNow.AddMonths(1).Date; Func <Task> act = async() => await Handler.Handle(ExampleValidRequest); act.ShouldThrow <ValidationException>().Which.Message.Should().Be("Invalid Date of Change. Date should be todays date."); }
public override void SetUp() { base.SetUp(); ExampleValidRequest = new PauseApprenticeshipCommand { AccountId = 111L, ApprenticeshipId = 444L, DateOfChange = DateTime.Now.Date, UserName = "******" }; _testCommitment = new Commitment { Id = 123L, EmployerAccountId = ExampleValidRequest.AccountId }; TestApprenticeship = new Apprenticeship { CommitmentId = 123L, PaymentStatus = PaymentStatus.Active, StartDate = DateTime.UtcNow.Date.AddMonths(-2) }; 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( ExampleValidRequest.ApprenticeshipId, TestApprenticeship.CommitmentId, PaymentStatus.Paused)) .Returns(Task.FromResult(new object())); MockCommitmentRespository.Setup(x => x.GetCommitmentById( It.Is <long>(c => c == TestApprenticeship.CommitmentId))) .ReturnsAsync(_testCommitment); }