Esempio n. 1
0
        public void GetLatLongForCityAsync__CallsWithGet()
        {
            var handlerMock = SetupBackend(x => x.Method == HttpMethod.Get);

            var client = new HttpClient(handlerMock.Object);
            var geo    = new OpenCageGeo(client, apiKey);

            Func <Task> act = async() => await geo.GetLatLongForCityAsync("Foobar");

            act.Should().NotThrow();
        }
Esempio n. 2
0
        public void GetLatLongForCityAsync__CallsToOpenCage()
        {
            var handlerMock = SetupBackend(x => x.RequestUri.AbsoluteUri.StartsWith("https://api.opencagedata.com/geocode/v1/json?"));

            var client = new HttpClient(handlerMock.Object);
            var geo    = new OpenCageGeo(client, apiKey);

            Func <Task> act = async() => await geo.GetLatLongForCityAsync("Foobar");

            act.Should().NotThrow();
        }
Esempio n. 3
0
        public void GetLatLongFromCityAsync__ThrowsExceptionWhenNoLocationFound()
        {
            var handlerMock = SetupBackend(response: NoResultsFoundResponse);

            var client = new HttpClient(handlerMock.Object);
            var geo    = new OpenCageGeo(client, apiKey);

            Func <Task> act = async() => await geo.GetLatLongForCityAsync("Des Moines");

            act.Should().Throw <ApiException>().WithMessage($"*Location not found");
        }
Esempio n. 4
0
        public void GetLatLongFromCityAsync__AddsTheLocationToTheQueryString()
        {
            var city        = "Des Moines";
            var handlerMock = SetupBackend(x => x.RequestUri.Query.Contains($"q={WebUtility.UrlEncode(city)}"));

            var client = new HttpClient(handlerMock.Object);
            var geo    = new OpenCageGeo(client, apiKey);

            Func <Task> act = async() => await geo.GetLatLongForCityAsync(city);

            act.Should().NotThrow();
        }
Esempio n. 5
0
        public void GetLatLongFromCityAsync__AddsTheApiKey()
        {
            var apiKey      = "Foobar";
            var handlerMock = SetupBackend(x => x.RequestUri.Query.Contains($"key={apiKey}"));

            var client = new HttpClient(handlerMock.Object);
            var geo    = new OpenCageGeo(client, apiKey);

            Func <Task> act = async() => await geo.GetLatLongForCityAsync("Des Moines");

            act.Should().NotThrow();
        }
Esempio n. 6
0
        public async Task GetLatLongFromCityAsync__ReturnsTheCoordsForTheRequested()
        {
            var handlerMock = SetupBackend();

            var client = new HttpClient(handlerMock.Object);
            var geo    = new OpenCageGeo(client, apiKey);

            var coords = await geo.GetLatLongForCityAsync("Des Moines");

            coords.Lat.Should().BeApproximately(lat, 2d);
            coords.Lng.Should().BeApproximately(lng, 2d);
            coords.ToString().Should().BeEquivalentTo(location);
        }