Moq + Unit Testing - System.Reflection.TargetParameterCountException: Parameter count mismatch

后端 未结 4 370
轻奢々
轻奢々 2020-11-30 12:15

I\'m tring to use a lambda with a multiple-params function but Moq throws this exception at runtime when I attempt to call the mock.Object.Convert(value, null, null, n

4条回答
  •  执笔经年
    2020-11-30 12:41

    In my case, I thought that the type in Returns<> is the output type, but in fact it was the input type(s).

    So if you have a method

    public virtual string Foo(int a, int b) { ... }
    

    The correct clause is .Returns(...), NOT .Returns(...) which is what I thought initially.

    My mistake was because I was testing a function with the same input and return type initially - for example public virtual string Foo(string a).

提交回复
热议问题