Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking ICountryFactory is impossible #57

Open
gharizanov opened this issue Jul 21, 2015 · 1 comment
Open

Mocking ICountryFactory is impossible #57

gharizanov opened this issue Jul 21, 2015 · 1 comment

Comments

@gharizanov
Copy link

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:

  • The type 'PostalCodes.Country' has no constructors defined
  • Property or indexer 'Name' cannot be assigned to -- it is read only
@istanishev
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants