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

Cannot setup a callback on a protected method #217

Closed
Marimout opened this issue Nov 19, 2015 · 1 comment
Closed

Cannot setup a callback on a protected method #217

Marimout opened this issue Nov 19, 2015 · 1 comment

Comments

@Marimout
Copy link

Hello,

I cannot setup a callback on a protected method (by the way, Verify doesn't work either).

The code looks like following :

public abstract class AbstractClass
{
    protected abstract void OneProtectedMethod();
}

public class OneClass : AbstractClass
{
    protected override void OneProtectedMethod()
    {
        Console.WriteLine("Hello");
    }

    public void DoMethod()
    {
        OneProtectedMethod();
    }
}

[Test]
public void should_call_protected_method()
{
    var mock = new Mock<OneClass>();

    mock.Protected().Setup("OneProtectedMethod").Callback(() => Console.WriteLine("Goodbye"));

    var o = new OneClass();

    o.DoMethod();

    mock.Protected().Verify("OneProtectedMethod", Times.Once());
}

Am I doing anything wrong ? Or is there any issue ?

Thanks.

@Marimout
Copy link
Author

My bad. I didn't use that mocked object as it should be. Sorry.

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

No branches or pull requests

1 participant