public void Setup() { _validator = new ApprenticeshipStatusChangeCommandValidator(); _exampleCommand = new ResumeApprenticeshipCommand { AccountId = 1L, ApprenticeshipId = 444L }; }
public async Task Handle_WhenHandlingCommand_ResumeApprenticeship_CreatesAddHistoryEvent() { // Arrange var apprenticeship = await SetupApprenticeship(); var command = new ResumeApprenticeshipCommand { ApprenticeshipId = apprenticeship.Id, UserInfo = new UserInfo() }; // Act await _handler.Handle(command, new CancellationToken()); // Simulate Unit of Work contex transaction ending in http request. await _dbContext.SaveChangesAsync(); // Assert var historyEvent = _unitOfWorkContext.GetEvents().OfType <EntityStateChangedEvent>() .First(e => e.EntityId == apprenticeship.Id); historyEvent.EntityType.Should().Be("Apprenticeship"); var definition = new { PaymentStatus = PaymentStatus.Paused }; var historyState = JsonConvert.DeserializeAnonymousType(historyEvent.UpdatedState, definition); historyState.PaymentStatus.Should().Be(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 async Task Handle_WhenHandlingCommand_ThrowErrorForNonPausedApprenticeshipStatus(PaymentStatus paymentStatus) { // Arrange var apprenticeship = await SetupApprenticeship(Party.Employer, paymentStatus); var command = new ResumeApprenticeshipCommand { ApprenticeshipId = apprenticeship.Id, UserInfo = new UserInfo() }; // Act var exception = Assert.ThrowsAsync <DomainException>(async() => await _handler.Handle(command, new CancellationToken())); // Assert exception.DomainErrors.Should().BeEquivalentTo(new { ErrorMessage = "Only paused record can be activated" }); }
public async Task Handle_WhenHandlingCommand_ThrowDomainExceptionIfPartyIsNotEmployer(Party party) { // Arrange var apprenticeship = await SetupApprenticeship(party); var command = new ResumeApprenticeshipCommand { ApprenticeshipId = apprenticeship.Id, UserInfo = new UserInfo() }; // Act var exception = Assert.ThrowsAsync <DomainException>(async() => await _handler.Handle(command, new CancellationToken())); // Assert exception.DomainErrors.Should().BeEquivalentTo(new { ErrorMessage = $"Only employers are allowed to edit the end of completed records - {party} is invalid" }); }
public override void SetUp() { base.SetUp(); MockCurrentDateTime.SetupGet(x => x.Now).Returns(new DateTime(2017, 6, 1)); ExampleValidRequest = new ResumeApprenticeshipCommand { AccountId = 111L, ApprenticeshipId = 444L, DateOfChange = MockCurrentDateTime.Object.Now.Date, UserName = "******" }; TestApprenticeship = new Apprenticeship { CommitmentId = 123L, PaymentStatus = PaymentStatus.Paused, PauseDate = MockCurrentDateTime.Object.Now.AddMonths(-2).Date, StartDate = MockCurrentDateTime.Object.Now.Date.AddMonths(6) }; 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())); }