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

base class can not be mocked #1332

Closed
MiaHesham opened this issue Feb 16, 2023 · 1 comment
Closed

base class can not be mocked #1332

MiaHesham opened this issue Feb 16, 2023 · 1 comment

Comments

@MiaHesham
Copy link

MiaHesham commented Feb 16, 2023

public class ITestController : Controller
{

    public ITestController() {
    }
    
    public virtual bool re(string z)
    {
        if(z == null) { return false; }
        else
        {
            return true;
        }
    }
}

public class TestController : ITestController
{

    public TestController() {
    }
    public int Index(int x,int y)
    {
         if (base.re("ll")==true)
            {
                return x * y;
            }
            return x + y;
        
       
    }
   
}

[Fact]
public async Task test()
{
var _TestController = new Mock { CallBase = true };
_TestController.Setup(a => a.re(It.IsAny())).Returns(true);

        var res=  _TestController.Object.Index(1, 2);
        Assert.Equal(res,5);

    }

my problem is re function will be evaluated.
I don't need to evaluate re function

@stakx
Copy link
Contributor

stakx commented Feb 16, 2023

This issue tracker focuses on the development of Moq (feature requests and bug reports), please post plain usage questions elsewhere (e.g. on sites such as Stack Overflow where you'll have a larger audience).

@stakx stakx closed this as completed Feb 16, 2023
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