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

后端 未结 4 382
轻奢々
轻奢々 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:44

    Not an answer for OP but perhaps for future googlers:

    I had a Callback that didn't match the signature of the method being setup

    Mock
        .Setup(r => r.GetNextCustomerNumber(It.IsAny()))
        .Returns(AccountCounter++)
        .Callback(badStringParam, leadingDigit =>
        {
            // Doing stuff here, note that the 'GetNextCustomerNumber' signature is a single int 
            // but the callback unreasonably expects an additional string parameter.
        });
    

    This was the result of some refactoring and the refactoring tool of course couldn't realise that the Callback signature was incorrect

提交回复
热议问题