Esempio n. 1
0
        public async Task CopyAatfPost_ValidViewModel_ReturnsRedirect()
        {
            Guid orgId     = Guid.NewGuid();
            var  viewModel = CreateCopyAatfViewModel();

            viewModel.StatusValue    = 1;
            viewModel.SizeValue      = 1;
            viewModel.ComplianceYear = 2019;
            viewModel.Name           = "Name";
            viewModel.ApprovalNumber = "WEE/AB1234CD/ATF";

            var request = fixture.Create <AddAatf>();

            var aatf = new AatfData()
            {
                Id = viewModel.Id,

                Organisation = new OrganisationData()
                {
                    Id = viewModel.OrganisationId
                }
            };

            A.CallTo(() => mapper.Map <CopyAatfViewModel>(aatf)).Returns(viewModel);

            var validationResult = new ValidationResult();

            A.CallTo(() => validationWrapper.ValidateByYear(A <string> ._, viewModel, viewModel.ComplianceYear)).Returns(validationResult);

            var result = await controller.CopyAatfDetails(viewModel) as RedirectToRouteResult;

            result.RouteValues["action"].Should().Be("ManageAatfs");
            result.RouteValues["controller"].Should().Be("Aatf");
        }
Esempio n. 2
0
        private async Task <ActionResult> CopyFacilityDetails(CopyFacilityViewModelBase viewModel)
        {
            PreventSiteAddressNameValidationErrors();
            SetBreadcrumb(viewModel.FacilityType, viewModel.Name);
            viewModel = await PopulateViewModelLists(viewModel);

            using (var client = apiClient())
            {
                if (!ModelState.IsValid)
                {
                    if (!viewModel.ModelValidated)
                    {
                        ModelState.RunCustomValidation(viewModel);
                    }

                    ModelState.ApplyCustomValidationSummaryOrdering(CopyFacilityViewModelBase.ValidationMessageDisplayOrder);
                    return(View("Copy", viewModel));
                }

                var result = await validationWrapper.ValidateByYear(User.GetAccessToken(), viewModel, viewModel.ComplianceYear);

                if (!result.IsValid)
                {
                    ModelState.AddModelError("ApprovalNumber", Constants.ApprovalNumberExistsForCYError);
                    return(View("Copy", viewModel));
                }

                if (ModelState.IsValid)
                {
                    var request = new AddAatf()
                    {
                        Aatf           = AatfHelper.CreateFacilityData(viewModel),
                        OrganisationId = viewModel.OrganisationId,
                        AatfId         = viewModel.AatfId,
                        AatfContact    = viewModel.ContactData
                    };

                    await client.SendAsync(User.GetAccessToken(), request);

                    await cache.InvalidateAatfCache(request.OrganisationId);
                }

                return(RedirectToAction("ManageAatfs", "Aatf", new { viewModel.FacilityType }));
            }
        }