public void Then_It_Belongs_To_The_Correct_EmployerAccount(ChangeOfPartyRequestType requestType) { //EmployerAccount could be the one on the apprenticeship, or the one on the COPR itself, depending on the request type _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyAccountId(); }
public DetailsViewModelMapperFixture WithChangeOfPartyRequest(ChangeOfPartyRequestType requestType, ChangeOfPartyRequestStatus status, Party?withParty = null) { var newApprenticeshipId = Fixture.Create <long>(); GetChangeOfPartyRequestsResponse = new GetChangeOfPartyRequestsResponse { ChangeOfPartyRequests = new List <GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest> { new GetChangeOfPartyRequestsResponse.ChangeOfPartyRequest { Id = 1, ChangeOfPartyType = requestType, OriginatingParty = requestType == ChangeOfPartyRequestType.ChangeEmployer ? Party.Provider : Party.Employer, Status = status, WithParty = withParty, NewApprenticeshipId = newApprenticeshipId } } }; _encodingService.Setup(x => x.Encode(It.Is <long>(id => id == newApprenticeshipId), EncodingType.ApprenticeshipId)) .Returns(EncodedNewApprenticeshipId); return(this); }
public ChangeOfPartyRequest(Apprenticeship apprenticeship, ChangeOfPartyRequestType changeOfPartyType, Party originatingParty, long newPartyId, int?price, DateTime?startDate, DateTime?endDate, UserInfo userInfo, DateTime now) { CheckOriginatingParty(originatingParty); CheckRequestType(originatingParty, changeOfPartyType); CheckPrice(originatingParty, changeOfPartyType, price); StartTrackingSession(UserAction.CreateChangeOfPartyRequest, originatingParty, apprenticeship.Cohort.AccountLegalEntityId, apprenticeship.Cohort.ProviderId, userInfo); ApprenticeshipId = apprenticeship.Id; ChangeOfPartyType = changeOfPartyType; OriginatingParty = originatingParty; AccountLegalEntityId = changeOfPartyType == ChangeOfPartyRequestType.ChangeEmployer ? newPartyId : default(long?); ProviderId = changeOfPartyType == ChangeOfPartyRequestType.ChangeProvider ? newPartyId : default(long?); Price = price; StartDate = startDate; EndDate = endDate; Status = ChangeOfPartyRequestStatus.Pending; CreatedOn = now; LastUpdatedOn = now; ChangeTrackingSession.TrackInsert(this); ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new ChangeOfPartyRequestCreatedEvent(Id, userInfo)); }
public WhenCohortIsCreatedTestFixture WithChangeOfPartyType(ChangeOfPartyRequestType value, bool employerLed = false) { Request.SetValue(x => x.ChangeOfPartyType, value); Request.SetValue(x => x.OriginatingParty, value == ChangeOfPartyRequestType.ChangeEmployer ? Party.Provider : Party.Employer); if (value == ChangeOfPartyRequestType.ChangeEmployer) { var accountLegalEntity = new AccountLegalEntity(); accountLegalEntity.SetValue(x => x.Id, _autoFixture.Create <long>()); accountLegalEntity.SetValue(x => x.Account, new Account()); accountLegalEntity.Account.SetValue(x => x.Id, _autoFixture.Create <long>()); accountLegalEntity.SetValue(x => x.AccountId, accountLegalEntity.Account.Id); Request.SetValue(x => x.AccountLegalEntity, accountLegalEntity); Request.SetValue(x => x.AccountLegalEntityId, accountLegalEntity?.Id); ContinuedApprenticeship.Cohort.SetValue(x => x.ProviderId, _autoFixture.Create <long>()); } else { if (employerLed) { var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); Request.SetValue(x => x.StartDate, date); Request.SetValue(x => x.EndDate, date.AddYears(1)); Request.SetValue(x => x.Price, 1000); } Request.SetValue(x => x.ProviderId, _autoFixture.Create <long>()); ContinuedApprenticeship.Cohort.SetValue(x => x.AccountLegalEntityId, _autoFixture.Create <long>()); ContinuedApprenticeship.Cohort.SetValue(x => x.EmployerAccountId, _autoFixture.Create <long>()); } return(this); }
public void Then_TransferSenderId_Is_Correct(ChangeOfPartyRequestType requestType, bool expectTransferSenderId) { _fixture .WithChangeOfPartyType(requestType) .WithTransferSender(); _fixture.CreateCohort(); _fixture.VerifyTransferSender(); }
private void CheckRequestType(Party originatingParty, ChangeOfPartyRequestType requestType) { var validRequestType = GetValidRequestTypeForOriginator(originatingParty); if (requestType != validRequestType) { throw new DomainException(nameof(ChangeOfPartyRequestType), $"{originatingParty} can only create requests of type {validRequestType}"); } }
public void Then_The_DraftApprenticeshipDetails_Are_Correct(ChangeOfPartyRequestType requestType, bool isContinuation) { _fixture.WithChangeOfPartyType(requestType); if (isContinuation) { _fixture.WithContinuation(); } _fixture.CreateCohort(); _fixture.VerifyDraftApprenticeshipDetails(); }
private void CheckPrice(Party originatingParty, ChangeOfPartyRequestType requestType, int?price) { if (requestType == ChangeOfPartyRequestType.ChangeProvider && originatingParty == Party.Employer) { return; } if (price == null || (price <= 0 || price > Constants.MaximumApprenticeshipCost)) { throw new DomainException(nameof(Price), $"Change of Party for Apprenticeship {ApprenticeshipId} requires Price between 1 and {Constants.MaximumApprenticeshipCost}; {price} is not valid"); } }
private void CheckStartDateForChangeOfParty(DateTime?startDate, ChangeOfPartyRequestType changeOfPartyType, Party originatingParty) { if (changeOfPartyType == ChangeOfPartyRequestType.ChangeProvider && originatingParty == Party.Employer) { return; } if (startDate == null || StopDate > startDate) { throw new DomainException(nameof(StopDate), $"Change of Party requires that Stop Date of Apprenticeship {Id} ({StopDate}) be before or same as new Start Date of {startDate}"); } }
private void CheckPartyIsValid(Party party, ChangeOfPartyRequestType changeOfPartyRequestType) { if (party == Party.Provider && changeOfPartyRequestType != ChangeOfPartyRequestType.ChangeEmployer) { throw new DomainException(nameof(party), $"CreateChangeOfPartyRequest is restricted to Providers only - {party} is invalid"); } if (party == Party.Employer && changeOfPartyRequestType != ChangeOfPartyRequestType.ChangeProvider) { throw new DomainException(nameof(party), $"CreateChangeOfPartyRequest is restricted to Employers only - {party} is invalid"); } }
public void ThenTheRequestTypeMustBeValid(Party originatingParty, ChangeOfPartyRequestType requestType, bool expectThrow) { _fixture .WithOriginatingParty(originatingParty) .WithRequestType(requestType) .CreateChangeOfPartyRequest(); if (expectThrow) { _fixture.VerifyException <DomainException>(); } }
public virtual ChangeOfPartyRequest CreateChangeOfPartyRequest(ChangeOfPartyRequestType changeOfPartyType, Party originatingParty, long newPartyId, int?price, DateTime?startDate, DateTime?endDate, UserInfo userInfo, DateTime now) { CheckIsStoppedForChangeOfParty(); CheckStartDateForChangeOfParty(startDate, changeOfPartyType, originatingParty); CheckNoPendingOrApprovedRequestsForChangeOfParty(); return(new ChangeOfPartyRequest(this, changeOfPartyType, originatingParty, newPartyId, price, startDate, endDate, userInfo, now)); }
public ChangeOfPartyRequestDomainServiceTestsFixture(Party party, ChangeOfPartyRequestType changeOfPartyRequestType) { Now = DateTime.UtcNow; var uow = new UnitOfWorkContext(); CurrentDateTime = new Mock <ICurrentDateTime>(); CurrentDateTime.Setup(d => d.UtcNow).Returns(Now); ProviderRelationshipsApiClient = new Mock <IProviderRelationshipsApiClient>(); ProviderRelationshipsApiClient.Setup(x => x.GetAccountProviderLegalEntitiesWithPermission( It.IsAny <GetAccountProviderLegalEntitiesWithPermissionRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(() => new GetAccountProviderLegalEntitiesWithPermissionResponse { AccountProviderLegalEntities = new List <AccountProviderLegalEntityDto> { new AccountProviderLegalEntityDto { AccountLegalEntityId = NewPartyId } } }); AuthenticationService = new Mock <IAuthenticationService>(); AuthenticationService.Setup(x => x.GetUserParty()).Returns(OriginatingParty); SetupTestData(); OriginatingParty = party; ChangeOfPartyRequestType = changeOfPartyRequestType; NewPartyId = Fixture.Create <long>(); Price = Fixture.Create <int?>(); StartDate = Fixture.Create <DateTime?>(); EndDate = Fixture.Create <DateTime?>(); UserInfo = Fixture.Create <UserInfo>(); _domainService = new ChangeOfPartyRequestDomainService( new Lazy <ProviderCommitmentsDbContext>(() => Db), AuthenticationService.Object, CurrentDateTime.Object, ProviderRelationshipsApiClient.Object); }
public async Task <ChangeOfPartyRequest> CreateChangeOfPartyRequest( long apprenticeshipId, ChangeOfPartyRequestType changeOfPartyRequestType, long newPartyId, int?price, DateTime?startDate, DateTime?endDate, UserInfo userInfo, CancellationToken cancellationToken) { var party = _authenticationService.GetUserParty(); CheckPartyIsValid(party, changeOfPartyRequestType); var apprenticeship = await _dbContext.Value.GetApprenticeshipAggregate(apprenticeshipId, cancellationToken); if (changeOfPartyRequestType == ChangeOfPartyRequestType.ChangeProvider) { CheckEmployerHasntSelectedTheirCurrentProvider(apprenticeship.Cohort.ProviderId, newPartyId, apprenticeship.Id); } if (party == Party.Provider && changeOfPartyRequestType == ChangeOfPartyRequestType.ChangeEmployer) { await CheckProviderHasPermission(apprenticeship.Cohort.ProviderId, newPartyId); } var result = apprenticeship.CreateChangeOfPartyRequest(changeOfPartyRequestType, party, newPartyId, price, startDate, endDate, userInfo, _currentDateTime.UtcNow); _dbContext.Value.ChangeOfPartyRequests.Add(result); return(result); }
public ChangeOfPartyRequestCreationTestFixture WithRequestType(ChangeOfPartyRequestType requestType) { RequestType = requestType; return(this); }
public ChangeOfPartyRequestDomainServiceTestsFixture WithChangeOfPartyRequestType(ChangeOfPartyRequestType requestType) { ChangeOfPartyRequestType = requestType; return(this); }
public void Then_ChangeOfPartyCohortCreatedEvent_Is_Emitted(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyCohortWithChangeOfPartyCreatedEvent(); }
public void Then_It_Is_Not_A_Draft(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyCohortIsNotDraft(); }
public void Then_WithParty_Is_Correct(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyWithOtherParty(); }
public void Then_Cohort_Creation_Is_Subject_To_StateTracking(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyTracking(); }
public void Then_ChangeOfPartyRequestId_Is_Correct(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyChangeOfPartyRequestId(); }
public void Then_The_Originator_Is_Correct(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyOriginator(); }
public void Then_It_Belongs_To_The_Correct_EmployerAccountLegalEntity(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyAccountLegalEntityId(); }
public void Then_AssignedToOtherPartyEvent_Is_Emitted(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyAssignedToOtherPartyEventIsEmitted(); }
public void Then_It_Belongs_To_The_Correct_Provider(ChangeOfPartyRequestType requestType) { _fixture.WithChangeOfPartyType(requestType); _fixture.CreateCohort(); _fixture.VerifyProvider(); }