maxmind/GeoIP2-dotnet

Private setters prevent unit testing

jwynveen opened this issue · 3 comments

All of the properties of the response objects seem to have private setters. When trying to unit test functionality in my site that hits the MaxMind service, I can mock (using Moq) the interface behind the client (IGeoIP2Provider) to simulate responses, but I'm unable to manually create response objects because none of the setters are available.

Ideally, the setters would be public for testing purposes. Either that, or the response objects would be interfaces that could also be mocked for testing purposes.

Here is an example of what I would like to mock:

var response = new CityResponse
{
    Postal = new Postal {Code = "12345"}    //not possible because of private setters
};
Mock<IGeoIP2Provider> GeoProvider = new Mock<IGeoIP2Provider>();
GeoProvider.Setup(x => x.City(It.IsAny<string>())).Returns(response);

I don't know if we would want public setters as mutable data is messy, but it would make sense to add a constructor with named/optional arguments.

As a stop-gap, you could deserialize to the class using Newtonsoft.Json as is done in this test and internally.

A constructor with optional arguments would be great. What would be the timing for this to be implemented and released? Are we looking at days, weeks, or months?

I don't think we have a particular timeline. Pull requests are welcomed though.