public async Task WebServiceOptionsConstructor() { var stringContent = new StringContent(CountryJson); stringContent.Headers.ContentType = new MediaTypeHeaderValue( "application/vnd.maxmind.com-country+json"); stringContent.Headers.Add("Content-Length", CountryJson.Length.ToString()); var message = new HttpResponseMessage(HttpStatusCode.OK) { Content = stringContent }; // HttpClient mock var uri = new Uri($"https://test.maxmind.com/geoip/v2.1/country/me"); var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Get, uri.ToString()) .WithHeaders("Accept", "application/json") .Respond(message); var options = Options.Create(new WebServiceClientOptions { AccountId = 6, LicenseKey = "0123456789", Host = "test.maxmind.com", Timeout = 3000, Locales = new List <string> { "en" } }); var client = new WebServiceClient( new HttpClient(mockHttp), options ); var result = await client.CountryAsync(); Assert.NotNull(result); Assert.Equal("1.2.3.0/24", result.Traits.Network?.ToString()); }
public async Task WebServiceOptionsConstructor() { _server .Given( Request.Create() .WithPath("/geoip/v2.1/country/me") .UsingGet() ) .RespondWith( Response.Create() .WithStatusCode(HttpStatusCode.OK) .WithHeader("Content-Type", "application/vnd.maxmind.com-country+json") .WithBody(CountryJson) ); var options = Options.Create(new WebServiceClientOptions { AccountId = 6, LicenseKey = "0123456789", Host = _server.Urls[0].Replace("http://", ""), DisableHttps = true, Timeout = 3000, Locales = new List <string> { "en" } }); var client = new WebServiceClient( new HttpClient(), options ); var result = await client.CountryAsync(); Assert.NotNull(result); Assert.Equal("1.2.3.0/24", result.Traits.Network?.ToString()); }
public async Task <string> GetCountryNameAsync(string ip) { var location = await _maxMindClient.CountryAsync(ip); return(location.Country.Name); }
public async Task <IActionResult> Get(string id) { var location = await _maxMindClient.CountryAsync(id); return(Ok(location)); }