Cimpress-MCP / PostalCodes.Net

Library for managing postal codes in .NET
11 stars 10 forks source link

Mocking ICountryFactory is impossible #57

Open gharizanov opened 9 years ago

gharizanov commented 9 years ago

I’m trying to mock ICountryFactory but with no luck. Here is the code:

    var _countryFactory = new Mock<ICountryFactory>();

        _countryFactory
            .Setup(f => f.CreateCountry(It.IsAny<string>()))
            .Returns(new Country
            {
                Name = "Switzerland"
            });

And then I get these errors:

istanishev commented 9 years ago

As a work around you can do something like this:

        var _countryFactory = new Mock<ICountryFactory>();

        _countryFactory
            .Setup(f => f.CreateCountry(It.IsAny<string>()))
            .Returns( CountryFactory.CreateCountry("CH") );

Not sure if this actually helps so I'm curious to understand what is the use case?