public void SetUp() { _legalEntitiesService = new Mock <ILegalEntitiesService>(); _configuration = new Mock <IOptions <ExternalLinksConfiguration> >(); _sut = new ApplyOrganisationController(_legalEntitiesService.Object, _configuration.Object); _fixture = new Fixture(); _accountId = _fixture.Create <string>(); _viewModel = _fixture.Create <ChooseOrganisationViewModel>(); _viewModel.AccountId = _accountId; }
public async Task <IActionResult> ChooseOrganisation(string accountId) { var legalEntities = await _legalEntitiesService.Get(accountId); var model = new ChooseOrganisationViewModel(_linksConfiguration.ManageApprenticeshipSiteUrl, accountId) { LegalEntities = legalEntities }; return(View(model)); }
public static ChooseOrganisationViewModel AddOrganisations(this ChooseOrganisationViewModel viewModel, IEnumerable <LegalEntityModel> legalEntities) { viewModel.Organisations = new List <OrganisationViewModel>(); legalEntities.OrderBy(n => n.Name).ToList().ForEach(o => viewModel.Organisations.Add( new OrganisationViewModel { Name = o.Name, AccountLegalEntityId = o.AccountLegalEntityId })); return(viewModel); }
public void Organisation_names_should_be_ordered_alphabetically() { // Arrange var model = new ChooseOrganisationViewModel(); // Act model.AddOrganisations(_organisations); // Assert model.Organisations[0].Name.Should().Be(_organisations[1].Name); model.Organisations[1].Name.Should().Be(_organisations[0].Name); model.Organisations[2].Name.Should().Be(_organisations[3].Name); model.Organisations[3].Name.Should().Be(_organisations[2].Name); }
public async Task <IActionResult> ChooseOrganisation(ChooseOrganisationViewModel model) { if (!string.IsNullOrEmpty(model.Selected)) { return(RedirectToAction("ListPaymentsForLegalEntity", new { model.AccountId, accountLegalEntityId = model.Selected })); } model.LegalEntities = await _legalEntitiesService.Get(model.AccountId); if (string.IsNullOrEmpty(model.Selected)) { ModelState.AddModelError(model.LegalEntities.Any() ? model.LegalEntities.First().AccountLegalEntityId : "LegalEntityNotSelected", model.LegalEntityNotSelectedMessage); } return(View(model)); }
public async Task Then_the_payments_are_shown_for_the_selected_account_organisation() { var accountLegalEntityId = _fixture.Create <string>(); var model = new ChooseOrganisationViewModel(_manageAccountsUrl, _accountId) { Selected = accountLegalEntityId }; var result = await _sut.ChooseOrganisation(model); var redirectResult = result as RedirectToActionResult; redirectResult.Should().NotBeNull(); redirectResult.ActionName.Should().Be("ListPaymentsForLegalEntity"); redirectResult.RouteValues["accountId"].Should().Be(_accountId); redirectResult.RouteValues["accountLegalEntityId"].Should().Be(accountLegalEntityId); }
public async Task <IActionResult> ChooseOrganisation(ChooseOrganisationViewModel viewModel) { if (!string.IsNullOrEmpty(viewModel.Selected)) { return(RedirectToAction("Index", "Hub", new { viewModel.AccountId, accountLegalEntityId = viewModel.Selected })); } viewModel.AddOrganisations(await _legalEntitiesService.Get(viewModel.AccountId)); viewModel.SetManageAccountsUrl(_configuration.ManageApprenticeshipSiteUrl); if (string.IsNullOrEmpty(viewModel.Selected)) { ModelState.AddModelError(viewModel.Organisations.Any() ? viewModel.Organisations.First().AccountLegalEntityId : "OrganisationNotSelected", viewModel.OrganisationNotSelectedMessage); } return(View(viewModel)); }
public async Task <IActionResult> GetChooseOrganisation(ChooseOrganisationViewModel viewModel) { var legalEntities = await _legalEntitiesService.Get(viewModel.AccountId); if (legalEntities.Count() == 1) { return(RedirectToAction("Index", "Hub", new { viewModel.AccountId, accountLegalEntityId = legalEntities.First().AccountLegalEntityId })); } if (legalEntities.Count() > 1) { viewModel.AddOrganisations(legalEntities); viewModel.SetManageAccountsUrl(_configuration.ManageApprenticeshipSiteUrl); return(View("ChooseOrganisation", viewModel)); } return(RedirectToAction("Forbidden", "Apply", new { viewModel.AccountId })); }