public void ExecuteAsync_CorrectlyMapsAddressScopeToGazetteerAndOutOfBorough(string addressScope,
                                                                                     GlobalConstants.Gazetteer expectedGazetteer, bool expectedOutOfBorough)
        {
            SetupValidatorToReturnValid();
            var request = new SearchAddressRequest
            {
                Postcode     = "E8",
                AddressScope = addressScope
            };

            _searchAddressGateway.Setup(s => s.SearchAddresses(It.Is <SearchParameters>(i =>
                                                                                        i.Gazetteer.Equals(expectedGazetteer) && i.OutOfBoroughAddress.Equals(expectedOutOfBorough))))
            .ReturnsAsync((null, 0)).Verifiable();
            _classUnderTest.ExecuteAsync(request);
            _addressGateway.Verify();
        }
Exemple #2
0
        public async Task<JsonResult> GetAddresses([FromQuery]string Postcode = null,
            [FromQuery]string USRN = null,
            [FromQuery]string UPRN = null,
            [FromQuery]GlobalConstants.PropertyClassPrimary? PropertyClass = null,
            [FromQuery]string PropertyClassCode = null,
            [FromQuery]GlobalConstants.AddressStatus AddressStatus = GlobalConstants.AddressStatus.ApprovedPreferred,
            [FromQuery]GlobalConstants.Format Format = GlobalConstants.Format.Simple,
            [FromQuery]GlobalConstants.Gazetteer Gazetteer = GlobalConstants.Gazetteer.Local,
            [FromQuery]int? Limit = GlobalConstants.LIMIT,
            [FromQuery]int? Offset = GlobalConstants.OFFSET)
        {
            try
            {
                AddressesQueryParams queryParams = new AddressesQueryParams();
                
                queryParams.Postcode = WebUtility.UrlDecode(Postcode);
                queryParams.UPRN = WebUtility.UrlDecode(UPRN);
                queryParams.USRN = WebUtility.UrlDecode(USRN);
                queryParams.PropertyClassCode = WebUtility.UrlDecode(PropertyClassCode);
                queryParams.PropertyClass = WebUtility.UrlDecode(PropertyClass.ToString());
                queryParams.AddressStatus = WebUtility.UrlDecode(AddressStatus.ToString());
                queryParams.Gazetteer = WebUtility.UrlDecode(Gazetteer.ToString());
                queryParams.Format = WebUtility.UrlDecode(Format.ToString());

                ValidationResult validatorFilterErrors = _validator.ValidateAddressesQueryParams(queryParams);

                if (!validatorFilterErrors.ErrorOccurred)
                {
                    Pagination pagination = new Pagination();
                    pagination.limit = Limit ?? default(int);
                    pagination.offset = Offset ?? default(int);

                    var result = await _addressesActions.GetAddresses(
                        queryParams,
                        pagination);

                    var json = Json(new { result, ErrorCode = "0", ErrorMessage = "" });
                    json.StatusCode = 200;
                    json.ContentType = "application/json";

                    return json;
                }
                else
                {
                    var errors = validatorFilterErrors.ErrorMessages;

                    var json = Json(errors);
                    json.StatusCode = 400;
                    json.ContentType = "application/json";
                    return json;
                }
            }
            catch (Exception ex)
            {
                var errors = new List<ApiErrorMessage>
                {
                    new ApiErrorMessage
                    {
                        developerMessage = ex.Message,
                        userMessage = "We had some problems processing your request"
                    }
                };
                _logger.LogError(ex.Message);
                var json = Json(errors);
                json.StatusCode = 500;
                json.ContentType = "application/json";
                return json;
            }
        }
Exemple #3
0
        public void GivenValidSearchAddressRequest_WhenCallingGet_ThenShouldReturnAPIResponseListOfAddresses(string postcode, GlobalConstants.Gazetteer gazetteer)
        {
            //arrange
            _mock.Setup(s => s.ExecuteAsync(It.IsAny <SearchAddressRequest>()))
            .Returns(new SearchAddressResponse
            {
                Addresses = new List <AddressResponse>()
            });

            var request = new SearchAddressRequest
            {
                PostCode  = postcode,
                Gazetteer = gazetteer.ToString()
            };
            //act
            var response = _classUnderTest.GetAddresses(request);

            //assert
            response.Should().NotBeNull();
            response.Should().BeOfType <OkObjectResult>();
            var objectResult = response as OkObjectResult;
            var getAddresses = objectResult?.Value as APIResponse <SearchAddressResponse>;

            getAddresses.Should().NotBeNull();
        }