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

Invalid setup on non-virtual member, but the member is virtual #182

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

Invalid setup on non-virtual member, but the member is virtual #182

aggieben opened this issue Jun 19, 2015 · 1 comment

Comments

@aggieben
Copy link

I have concrete class which inherits an abstract class and overrides some if its members, and then in my test scenario, I want proxy specific ones of those for the test. Like this:

public class Base
{
    public abstract void F();
    public abstract void G();
}

public class MockBase : Base
{
    public override int F() { /* stuff */ }
    public override void G() { /* stuff */ }
}

public class TestClass
{
    [Fact]
    public void DoTest()
    {
        var mock = new Mock<MockBase>() { CallBase = true };
        mock.Setup(mb => mb.F()).Returns(7);  // <== this shouldn't fail

        // rest of test
    } 
}

Overridden methods are themselves virtual unless marked with sealed.

@aggieben
Copy link
Author

Doh! Nevermind...The Base class I'm working with as a public and a protected F, and the public one is not virtual.

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