public async Task EditSoleTraderOrganisationDetails_ModelIsValid_UpdatesDetailsAndRedirectsToSchemeOverview() { var viewModel = new EditSoleTraderOrganisationDetailsViewModel { OrganisationType = OrganisationType.SoleTraderOrIndividual, BusinessAddress = new Core.Shared.AddressData(), CompanyName = "CompanyName", OrgId = Guid.NewGuid(), SchemeId = Guid.NewGuid() }; A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <UpdateOrganisationDetails> ._)) .Returns(true); new HttpContextMocker().AttachToController(controller); var result = await controller.EditSoleTraderOrganisationDetails(viewModel); A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <UpdateOrganisationDetails> ._)) .MustHaveHappened(Repeated.Exactly.Once); result.Should().NotBeNull(); result.Should().BeOfType <RedirectToRouteResult>(); var redirectResult = (RedirectToRouteResult)result; redirectResult.RouteValues["Action"].Should().Be("Overview"); redirectResult.RouteValues["overviewDisplayOption"].Should().Be(OverviewDisplayOption.OrganisationDetails); }
public async Task <ActionResult> EditSoleTraderOrganisationDetails(Guid?schemeId, Guid orgId, Guid?aatfId, FacilityType?facilityType) { await SetBreadcrumb(schemeId, aatfId, orgId, facilityType); using (var client = apiClient()) { var organisationData = await client.SendAsync(User.GetAccessToken(), new GetInternalOrganisation(orgId)); if (!organisationData.CanEditOrganisation) { return(new HttpForbiddenResult()); } var countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false)); var model = new EditSoleTraderOrganisationDetailsViewModel { OrganisationType = organisationData.OrganisationType, BusinessTradingName = organisationData.TradingName, CompanyName = organisationData.Name, BusinessAddress = organisationData.BusinessAddress, SchemeId = schemeId, OrgId = orgId, AatfId = aatfId, FacilityType = facilityType.GetValueOrDefault() }; model.BusinessAddress.Countries = countries; return(View(model)); } }
public async void EditSoleTraderOrganisationDetails_ModelIsInvalid_GetsCountriesAndReturnsDefaultView() { var countries = new List <CountryData>(); A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetCountries> ._)) .Returns(countries); new HttpContextMocker().AttachToController(controller); controller.ModelState.AddModelError("SomeProperty", "IsInvalid"); var viewModel = new EditSoleTraderOrganisationDetailsViewModel { OrganisationType = OrganisationType.SoleTraderOrIndividual, BusinessAddress = new Core.Shared.AddressData(), CompanyName = "CompanyName", OrgId = Guid.NewGuid(), SchemeId = Guid.NewGuid() }; var result = await controller.EditSoleTraderOrganisationDetails(viewModel); A.CallTo(() => weeeClient.SendAsync(A <string> ._, A <GetCountries> ._)) .MustHaveHappened(Repeated.Exactly.Once); countries.Should().BeSameAs(viewModel.BusinessAddress.Countries); result.Should().NotBeNull(); result.Should().BeOfType <ViewResult>(); var viewResult = (ViewResult)result; viewResult.ViewName.Should().BeEmpty(); viewResult.Model.Should().Be(viewModel); }
public async Task <ActionResult> EditSoleTraderOrganisationDetails(EditSoleTraderOrganisationDetailsViewModel model) { await SetBreadcrumb(model.SchemeId, model.AatfId, model.OrgId, model.FacilityType); if (!ModelState.IsValid) { using (var client = apiClient()) { model.BusinessAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false)); } return(View(model)); } using (var client = apiClient()) { var orgData = new OrganisationData { Id = model.OrgId, OrganisationType = model.OrganisationType, TradingName = model.BusinessTradingName, Name = model.CompanyName, BusinessAddress = model.BusinessAddress, }; await client.SendAsync(User.GetAccessToken(), new UpdateOrganisationDetails(orgData)); await cache.InvalidateOrganisationSearch(); } if (model.SchemeId.HasValue) { return(RedirectScheme(model.SchemeId.Value)); } if (model.AatfId.HasValue) { return(RedirectToAatf(model.AatfId.Value)); } return(View(model)); }