public async Task Then_with_single_legal_entity_then_redirects_correctly(bool isTransfer, EmployerAgreementStatus status, int templateVersionNumber, ExpectedAction expectedAction) { //Arrange if (expectedAction == ExpectedAction.AgreementNotSigned) { _linkGeneratorResult = $"accounts/{_chooseOrganisationRequest.AccountHashedId}/apprentices/{LegalEntityCode}/AgreementNotSigned"; } if (expectedAction == ExpectedAction.SelectProvider) { _linkGeneratorResult = $"accounts/{_chooseOrganisationRequest.AccountHashedId}/apprentices/provider/create"; } _linkGenerator.Setup(x => x.CommitmentsLink(It.IsAny <string>())).Returns(_linkGeneratorResult); _modelMapper.Setup(x => x.Map <SelectLegalEntityViewModel>(It.Is <SelectLegalEntityRequest>(r => r == _chooseOrganisationRequest))) .ReturnsAsync(new SelectLegalEntityViewModel { LegalEntities = new[] { new LegalEntity { Agreements = new List <Agreement> { new Agreement { Status = status, TemplateVersionNumber = templateVersionNumber } }, Code = LegalEntityCode, Name = LegalEntityName } }, CohortRef = CohortRefViewModel }); //Act _chooseOrganisationRequest.transferConnectionCode = isTransfer ? _chooseOrganisationRequest.transferConnectionCode : string.Empty; var result = await _controller.SelectLegalEntity(_chooseOrganisationRequest); //Assert var redirectToActionResult = result as RedirectToActionResult; switch (expectedAction) { case ExpectedAction.AgreementNotSigned: Assert.AreEqual(expectedAction.ToString(), redirectToActionResult.ActionName); break; case ExpectedAction.SelectProvider: Assert.AreEqual(expectedAction.ToString(), redirectToActionResult.ActionName); break; default: throw new NotImplementedException(); } }
public async Task WithSingleLegalEntityThenRedirectsCorrectly(bool isTransfer, EmployerAgreementStatus status, int templateVersionNumber, ExpectedAction expectedAction) { var transferConnectionCode = GetTransferConnectionCode(isTransfer); var response = new OrchestratorResponse <SelectLegalEntityViewModel> { Data = new SelectLegalEntityViewModel { LegalEntities = new[] { new LegalEntity { Agreements = new List <Agreement> { new Agreement { Status = status, TemplateVersionNumber = templateVersionNumber } }, Code = LegalEntityCode, Name = LegalEntityName } }, CohortRef = CohortRefViewModel } }; Orchestrator.Setup(o => o.GetLegalEntities(HashedAccountId, transferConnectionCode, CohortRefParam, null)) .ReturnsAsync(response); var result = await Controller.SelectLegalEntity(HashedAccountId, transferConnectionCode); object expectedRouteValues; switch (expectedAction) { case ExpectedAction.AgreementNotSigned: expectedRouteValues = new { TransferConnectionCode = transferConnectionCode, HashedAccountId, LegalEntityCode, CohortRef = CohortRefViewModel, HasSignedAgreement = false, LegalEntityName }; break; case ExpectedAction.SearchProvider: expectedRouteValues = new { TransferConnectionCode = transferConnectionCode, LegalEntityCode, CohortRef = CohortRefViewModel }; break; default: throw new NotImplementedException(); } AssertRedirectAction(result, expectedAction.ToString(), expectedRouteValues: expectedRouteValues); }