예제 #1
0
        private async Task GetSelectAddress(EditDetailsCompositeViewModel viewModel, EditDetailsAdditionalData additionalData)
        {
            if (additionalData.SelectAddress != null)
            {
                try
                {
                    if (!string.IsNullOrEmpty(additionalData.SelectedAddress.Id))
                    {
                        additionalData.SelectedAddress = await _addressSearchService.GetAddress(additionalData.SelectedAddress.Id);
                    }

                    if (additionalData.SelectedAddress != null)
                    {
                        viewModel.Identity.PersonalDetails.AddressLine1 = additionalData.SelectedAddress.Line1;
                        viewModel.Identity.PersonalDetails.AddressLine2 = additionalData.SelectedAddress.Line2;
                        viewModel.Identity.PersonalDetails.AddressLine3 = additionalData.SelectedAddress.Line3;
                        viewModel.Identity.PersonalDetails.AddressLine4 = additionalData.SelectedAddress.Line4;
                        viewModel.Identity.PersonalDetails.Town         = additionalData.SelectedAddress.City;
                        viewModel.Identity.PersonalDetails.HomePostCode = additionalData.SelectedAddress.PostalCode;
                    }
                }
                catch
                {
                    viewModel.Identity.PersonalDetails.FindAddressServiceResult = ErrorMessageServiceUnavailable;
                }
            }
        }
        public async Task WhenSelectAddressPosted_ThenReturnViewModelWithSelectedAddress()
        {
            var controller = new EditYourDetailsController(_compositeSettings, _authService, _addressSearchService,
                                                           _dssReader, _dssWriter, _documentService, _config)
            {
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext()
                }
            };

            _dssReader.GetCustomerData(Arg.Any <string>()).ReturnsForAnyArgs(new Customer
            {
                Contact = new Contact
                {
                    EmailAddress = "test"
                }
            });

            _addressSearchService.GetAddress(Arg.Any <string>()).ReturnsForAnyArgs(new PostalAddressModel
            {
                PostalCode = "test"
            });

            var viewModel = GetViewModel();

            viewModel.Identity.PersonalDetails.HomePostCode = "lg23hg";

            var result = await controller.Body(viewModel, new FormCollection(new Dictionary <string, StringValues>
            {
                { "selectAddress", "selectAddress" },
                { "select-address", "{\"id\":\"test\"}" }
            })) as ViewResult;

            result.Should().NotBeNull();
            ((EditDetailsCompositeViewModel)result.ViewData.Model).Identity.PersonalDetails.HomePostCode.Should()
            .Be("test");
        }