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

'Invalid parameter count' thrown during setup of Callback for Instance methods that return void #11

Closed
paulose opened this issue Oct 7, 2015 · 4 comments
Labels

Comments

@paulose
Copy link

paulose commented Oct 7, 2015

context.Setup(() => It.IsAny<MessageQueue>().Send(message)).Callback((Message m) =>
{
    called = true;
});

When calling the above line, Smocks throws an error 'Invalid parameter count'. I am trying to mock the System.Messaging.MessageQueue.Send method here.

@vanderkleij
Copy link
Owner

Thanks for reporting this problem. I can reproduce the issue and will look into it shortly.

If you only intend to use this to confirm that the setup was called, you can use .Verifiable() instead of Callback(), followed by a call to context.Verify() after the method should've been invoked.

@vanderkleij vanderkleij added the bug label Oct 7, 2015
@paulose
Copy link
Author

paulose commented Oct 7, 2015

Thanks. I got it working for the moment with Verifiable. The issue seems to be in the condition for extraParameters in the SetupBase.cs

protected int ParameterCount
{
    get
    {
        int extraParameters = (!MethodCall.Method.IsStatic && 
            !MethodCall.Method.IsConstructor) ? 1 : 0;
        return MethodCall.Method.GetParameters().Length + extraParameters;
    }
}

@vanderkleij
Copy link
Owner

Fixed in nuget package 0.4.17. Thanks for reporting and pointing out where the issue arose! 👍

@paulose
Copy link
Author

paulose commented Oct 7, 2015

Works like a charm. Thanks for closing the issue at that speed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants