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

Allow Strict behavior with CallBase = true #181

Closed
aggieben opened this issue Jun 18, 2015 · 1 comment
Closed

Allow Strict behavior with CallBase = true #181

aggieben opened this issue Jun 18, 2015 · 1 comment

Comments

@aggieben
Copy link

This issue went unaddressed on Google Code No. 293, but I'd like to see this change. I want to set MockBehavior.Strict so that when a test fails for lack of a mocked method/property, the error message tells me exactly what's missing. Under MockBehavior.Loose, it's a bit of a goose chase to figure out sometimes.

In my particular case right now, I have:

public abstract class A
{
    public abstract void DoThis();
    public abstract void DoThat();
}

public abstract class B : A
{
    public override void DoThis()
    {
       // Doing this...
    }
}

I really want to just let my Mock<B> call B.DoThis(), but with MockBehavior.Strict so I'll know exactly when/where Mock<B>.DoThat() gets called.

For now, my workaround is to use MockBehavior.Loose, override in B, and throw NotImplementedExceptions:

...
    public override void DoThat()
    {
        throw new NotImplementedException();
    }
...

This gets me to the desired behavior, but it's a lot more work than it seems like it ought to be.

@stakx
Copy link
Contributor

stakx commented Jun 27, 2017

@aggieben: Your issue turned 2 years old recently, but if you would still like to have it looked into, may I ask you to please provide a clearer description of what you were trying to do (including short but complete repro code), and where Moq didn't meet your expectations.

  • For one thing, I am not sure why you linked to that Google thread, it seems like an altogether different issue. The Google Code issue asks for a method-specific CallBase, your issue seems to revolve around MockBehavior.Strict.

  • Second, it is also not clear from your code example why a call to mock.DoThis() should ever result in Mock<B>.DoThat() getting invoked. You have neither specified that behavior in the mocked class, nor as a setup.

If you are no longer interested in this issue, you don't need to reply, and I'll close it in 1-2 weeks. If it just takes you longer respond, that's not a problem, we can always reopen the issue.

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

2 participants