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

Fix issue #163 - Use the "Protected" extensions to test non-protected members #240

Closed
davidkassa opened this issue Jan 11, 2016 · 3 comments

Comments

@davidkassa
Copy link

I recently ran into this issue for similar reasons.

@davidkassa
Copy link
Author

@stakx
Copy link
Contributor

stakx commented Jun 3, 2017

public interface IFoo
{
    string Bar { get; }
}

[Fact]
public void TestMethod()
{
    var mock = new Mock<IFoo>();
    mock.Protected().SetupGet<string>(nameof(IFoo.Bar)).Returns(default(string));
    var bar = mock.Object.Bar;
    mock.VerifyAll();
}

I'll try to summarise the old Google Code issue's comments:

  • It was stated that this is by design. And it is. The fact that there is an error message stating very clearly what should be done instead:

    System.ArgumentException : To specify a setup for public property IFoo.Bar,
    use the typed overloads, such as:
    mock.Setup(x => x.Bar).Returns(value);
    mock.SetupGet(x => x.Bar).Returns(value); //equivalent to previous one
    mock.SetupSet(x => x.Bar).Callback(callbackDelegate);
    
  • An overload .Protected(bool allowPublicMembers) was suggested.

  • A rename of the Moq.Protected namespace into Moq.Unsafe was suggested.

The discussion on Google Code apparently never came to an end. What exactly are you requesting by reopening this issue?

@stakx
Copy link
Contributor

stakx commented Jun 27, 2017

@davidkassa: For the moment, I am closing this issue due to inactivity. We can always reopen it if you still want to follow up on this. In that case, just reply back.

@stakx stakx closed this as completed Jun 27, 2017
@devlooped devlooped locked and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants