request for constructing CityResponse members for unit testing
sbrown-nw opened this issue · 2 comments
Hello,
There are quite a few optional parameters for the MaxMind.GeoIP2.Responses.CityResponse constructor. I would like to construct a CityResponse so I can provide it to a mock setup return call which will allow me to uni test mapping between objects in a .Net 4.6 c# environment. Can you please provide some examples for what parameters are needed for the following members:
City (I need to get City.Name)
Country (I need to get Country.IsoCode)
MostSpecificSubdivision (I need to get MostSpecificSubdivision.IsoCode)
Postal (I need to get Postal.Code)
Location (I need to get Location.Latitude and Location.Longitude)
This would be greatly appreciated.
Thanks,
Scott
All of the optional parameters should, in fact, be optional. You will need to pass in the parameters you need (e.g., isoCode
for Country
). For the names, it is expecting a dictionary with this structure:
{
"de": "USA",
"en": "United States",
"es": "Estados Unidos",
"fr": "États-Unis",
"ja": "アメリカ合衆国",
"pt-BR": "Estados Unidos",
"ru": "США",
"zh-CN": "美国"
}
en
is the default language that will be used for Name
unless you are specifically passing other locales.
Thank you, your reply cleared things up for me. Here is some sample code if anyone needs it for future reference:
var cityResponse = new MaxMind.GeoIP2.Responses.CityResponse(
country: new MaxMind.GeoIP2.Model.Country(geoNameId: 6252001, isoCode: "US", names: new Dictionary<string, string> { { "en", "US" } }),
city: new MaxMind.GeoIP2.Model.City(geoNameId: 5786882, names: new Dictionary<string, string> { { "en", "Bellevue" } }),
subdivisions: new List<MaxMind.GeoIP2.Model.Subdivision> {
new MaxMind.GeoIP2.Model.Subdivision(geoNameId: 5815135, isoCode: "WA", names: new Dictionary<string, string> { { "en", "WA" } }) },
postal: new MaxMind.GeoIP2.Model.Postal(code: "98004"),
location: new MaxMind.GeoIP2.Model.Location(latitude: 47.6154, longitude: -122.2103));