Ejemplo n.º 1
0
        public async Task Success()
        {
            GetPostcodeCoordinatesRequest getPostcodeCoordinatesRequest = new GetPostcodeCoordinatesRequest()
            {
                Postcodes = new List <string>()
                {
                    "NG1 1AA"
                },
            };

            Core.Services.AddressService addressService = new Core.Services.AddressService(_httpClientWrapper.Object);

            GetPostcodeCoordinatesResponse result = await addressService.GetPostcodeCoordinatesAsync(getPostcodeCoordinatesRequest, CancellationToken.None);

            Assert.IsTrue(result.PostcodeCoordinates.Any(x => x.Postcode == "NG1 1AA" && x.Latitude == 45 && x.Longitude == 50));

            _httpClientWrapper.Setup(x => x.PostAsync(It.Is <HttpClientConfigName>(y => y == HttpClientConfigName.AddressService), It.Is <string>(y => y == "api/GetPostcodeCoordinates"), It.IsAny <HttpContent>(), It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 2
0
        public async Task Unsuccessful()
        {
            HttpResponseMessage httpResponseMessage = CreateUnsuccesssfuResponseWrapperHttpResponseMessage <GetPostcodeCoordinatesResponse>();

            _httpClientWrapper.Setup(x => x.PostAsync(It.IsAny <HttpClientConfigName>(), It.IsAny <string>(), It.IsAny <HttpContent>(), It.IsAny <CancellationToken>())).ReturnsAsync(httpResponseMessage);

            GetPostcodeCoordinatesRequest getPostcodeCoordinatesRequest = new GetPostcodeCoordinatesRequest()
            {
                Postcodes = new List <string>()
                {
                    "NG1 1AA"
                },
            };

            Core.Services.AddressService addressService = new Core.Services.AddressService(_httpClientWrapper.Object);

            Exception ex = Assert.ThrowsAsync <Exception>(async() => await addressService.GetPostcodeCoordinatesAsync(getPostcodeCoordinatesRequest, CancellationToken.None));

            Assert.AreEqual("Calling Address Service GetPostcodeCoordinatesAsync endpoint unsuccessful: Error", ex.Message);
        }