0

Is there any way to use moq without definig interfaces?? I had try to use with method that i am testing.

var real = new SubCoreClass();
var mock = new Mock<SubCoreClass>();

But i got error in Setup:

mock.Setup(t => t.method(It.IsAny<string>(),It.IsAny<string>(),It.IsAny<string>()));

: Invalid setup on a non-virtual

Yeganeh Salami
  • 575
  • 7
  • 29
  • 2
    I do believe that any abstract class and virtual methods in any class can be mocked. In short, `method()` needs to be either virtual or abstract. – fredrik Oct 10 '18 at 07:48
  • 3
    You can use Moq to mock abstract methods or virtual methods as well as interfaces (all of which are counted as virtual methods), but I suspect that's not the answer you're looking for. It just won't work with non-virtual methods, since then there is nothing for Moq to override/implement. – Matthew Watson Oct 10 '18 at 07:49
  • Any mocking-framework just *overrides* all virtual members/interface members. If there´s no such member, there´s no way to override the member. – MakePeaceGreatAgain Oct 10 '18 at 08:00

0 Answers0