Why am I getting an Exception with the message “Invalid setup on a non-virtual (overridable in VB) member…”?

前端 未结 6 1608
野的像风
野的像风 2020-11-27 12:44

I have a unit test where I have to mock a non-virtual method that returns a bool type

public class XmlCupboardAccess
{
    public bool IsDataEntityInXmlCupbo         


        
6条回答
  •  无人及你
    2020-11-27 13:15

    You'll get this error as well if you are verifying that an extension method of an interface is called.

    For example if you are mocking:

    var mockValidator = new Mock>();
    mockValidator
      .Verify(validator => validator.ValidateAndThrow(foo, null));
    

    You will get the same exception because .ValidateAndThrow() is an extension on the IValidator interface.

    public static void ValidateAndThrow(this IValidator validator, T instance, string ruleSet = null)...

提交回复
热议问题