// --- Helpers --- protected static Mock <IMediator> GetMediator(CommitmentView commitment) { var respons = new GetCommitmentQueryResponse { Commitment = commitment }; var mockMediator = new Mock <IMediator>(); mockMediator.Setup(m => m.Send(It.IsAny <GetCommitmentQueryRequest>(), new CancellationToken())) .Returns(Task.Factory.StartNew(() => respons)); mockMediator.Setup(m => m.Send(It.IsAny <GetTrainingProgrammesQueryRequest>(), new CancellationToken())) .ReturnsAsync(new GetTrainingProgrammesQueryResponse { TrainingProgrammes = new List <TrainingProgramme>() }); mockMediator.Setup(m => m.Send(It.IsAny <GetOverlappingApprenticeshipsQueryRequest>(), new CancellationToken())) .ReturnsAsync(() => new GetOverlappingApprenticeshipsQueryResponse { Overlaps = new List <ApprenticeshipOverlapValidationResult>() }); return(mockMediator); }
public async Task AndApprenticeshipIsOverFundingLimitThenACostWarningShouldBeAddedToViewModel() { var commitment = new CommitmentView { AgreementStatus = AgreementStatus.ProviderAgreed, EditStatus = EditStatus.ProviderOnly, Apprenticeships = new List <Apprenticeship> { new Apprenticeship { StartDate = new DateTime(2020, 2, 2), Cost = 500 } }, Messages = new List <MessageView>() }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); _mockMediator.Setup(m => m.Send(It.IsAny <GetTrainingProgrammesQueryRequest>(), new CancellationToken())) .ReturnsAsync(new GetTrainingProgrammesQueryResponse { TrainingProgrammes = new List <TrainingProgramme> { new TrainingProgramme { FundingPeriods = new List <TrainingProgrammeFundingPeriod> { new TrainingProgrammeFundingPeriod { EffectiveFrom = new DateTime(2020, 2, 1), EffectiveTo = new DateTime(2020, 3, 1), FundingCap = 100 } }, EffectiveFrom = new DateTime(2020, 2, 1), EffectiveTo = new DateTime(2020, 3, 1), Name = "Tit" } } }); _mockMediator.Setup(m => m.Send(It.IsAny <GetOverlappingApprenticeshipsQueryRequest>(), new CancellationToken())) .ReturnsAsync(new GetOverlappingApprenticeshipsQueryResponse { Overlaps = Enumerable.Empty <ApprenticeshipOverlapValidationResult>() }); var result = await _orchestrator.GetCommitmentDetails(1L, "ABBA213"); Assert.IsTrue(TestHelper.EnumerablesAreEqual(new[] { new KeyValuePair <string, string>("0", "Cost for Tit") }, result.Warnings.AsEnumerable())); }
private static ApprovalState GetApprovalState(CommitmentView commitment) { if (!commitment.Apprenticeships.Any()) { return(ApprovalState.ApproveAndSend); } var approvalState = commitment.Apprenticeships.Any(m => m.AgreementStatus == AgreementStatus.NotAgreed || m.AgreementStatus == AgreementStatus.ProviderAgreed) ? ApprovalState.ApproveAndSend : ApprovalState.ApproveOnly; return(approvalState); }
private CommitmentListItemViewModel MapFrom(CommitmentView listItem, string latestMessage) { return(new CommitmentListItemViewModel { HashedCommitmentId = HashingService.HashValue(listItem.Id), Reference = listItem.Reference, LegalEntityName = listItem.LegalEntityName, ProviderName = listItem.ProviderName, Status = listItem.GetStatus(), EmployerAccountId = listItem.EmployerAccountId, LatestMessage = latestMessage }); }
public async Task ThenCommitmentReadOnlyFlagIsSet(EditStatus editStatus, bool expectedIsReadOnly) { var commitment = new CommitmentView { AgreementStatus = AgreementStatus.ProviderAgreed, EditStatus = editStatus, Apprenticeships = new List <Apprenticeship>(), Messages = new List <MessageView>() }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); var result = await _orchestrator.GetCommitmentDetails(1L, "ABBA213"); result.IsReadOnly.Should().Be(expectedIsReadOnly); }
public async Task ThenTheCommitmentIsMarkedAsLinkedToChangeOfPartyRequestCorrectly(long?changeOfPartyRequestId, bool expectIsLinkedToChangeOfParty) { var commitment = new CommitmentView { AgreementStatus = AgreementStatus.ProviderAgreed, EditStatus = EditStatus.ProviderOnly, Apprenticeships = new List <Apprenticeship>(), Messages = new List <MessageView>(), ChangeOfPartyRequestId = changeOfPartyRequestId }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); var result = await _orchestrator.GetCommitmentDetails(1L, "ABBA213"); Assert.AreEqual(expectIsLinkedToChangeOfParty, result.IsLinkedToChangeOfPartyRequest); }
public async Task ThenFrameworksAreRetrievedForCohortsNotFundedByTransfer() { var commitment = new CommitmentView { AgreementStatus = AgreementStatus.ProviderAgreed, EditStatus = EditStatus.ProviderOnly, Apprenticeships = new List <Apprenticeship>(), Messages = new List <MessageView>(), TransferSender = null }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); await _orchestrator.GetCommitmentDetails(1L, "ABBA213"); _mockMediator.Verify(x => x.Send(It.Is <GetTrainingProgrammesQueryRequest>(r => r.IncludeFrameworks), It.IsAny <CancellationToken>()), Times.Once); }
public async Task ThenTheCommitmentIsMarkedAsFundedByTransferIfItHasATransferSenderId(long?transferSenderId, bool expectedTransferFlag) { var commitment = new CommitmentView { AgreementStatus = AgreementStatus.ProviderAgreed, EditStatus = EditStatus.ProviderOnly, Apprenticeships = new List <Apprenticeship>(), Messages = new List <MessageView>(), TransferSender = (transferSenderId != null ? new TransferSender { Id = transferSenderId, TransferApprovalStatus = TransferApprovalStatus.Pending } : null) }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); var result = await _orchestrator.GetCommitmentDetails(1L, "ABBA213"); Assert.AreEqual(expectedTransferFlag, result.IsFundedByTransfer); }
public async Task CommitmentWithOneProviderAgreed() { var commitment = new CommitmentView { AgreementStatus = AgreementStatus.ProviderAgreed, EditStatus = EditStatus.ProviderOnly, Apprenticeships = new List <Apprenticeship> { new Apprenticeship(), new Apprenticeship() }, Messages = new List <MessageView>() }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); var result = await _orchestrator.GetCommitmentDetails(1L, "ABBA213"); result.PendingChanges.Should().BeTrue(); }
public async Task ShouldBeAbleToViewACommitmentWhereBothPartiesHaveAgreed() { var commitment = new CommitmentView { AgreementStatus = AgreementStatus.BothAgreed, EditStatus = EditStatus.Both, Apprenticeships = new List <Apprenticeship> { new Apprenticeship(), new Apprenticeship() }, Messages = new List <MessageView>() }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); var result = await _orchestrator.GetCommitmentDetails(1L, "ABBA123"); result.IsReadOnly.Should().Be(true); }
public void ShouldReturnARequestStatus(TransferApprovalStatus transferApprovalStatus, EditStatus editStatus, RequestStatus requestStatus) { var commitment = new CommitmentView { TransferSender = new TransferSender { Id = 1, Name = "Name", TransferApprovalStatus = transferApprovalStatus }, AgreementStatus = AgreementStatus.BothAgreed, EditStatus = editStatus, Apprenticeships = new List <Apprenticeship> { new Apprenticeship(), new Apprenticeship() }, Messages = new List <MessageView>() }; _mockMediator = GetMediator(commitment); SetUpOrchestrator(); var result = _orchestrator.GetCommitmentDetails(1L, "ABBA213").Result; result.Status.Should().Be(requestStatus); }