-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
System.ArgumentException : Invalid callback. Setup on method with 0 parameter(s) cannot invoke callback with different number of parameters (1) #579
Comments
Possibly a duplicate of #572. Can you please post a minimal but complete test code that reproduces the problem you're describing? |
Sorry, but please post minimal but complete (self-contained) repro code here. |
using System;
using NUnit.Framework;
using Moq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var a = new A();
Console.WriteLine(a.DoTheThing("thing"));
Console.ReadKey();
}
}
[TestFixture]
public class AFixture
{
[Test]
public void DoTheThingTest()
{
// this test fails with Invalid callback error
var a = Mock.Of<IA>();
var aMock = Mock.Get(a);
aMock.Setup(i => i.DoTheThing(It.IsAny<string>())).Returns<string>(v => "Not A Thing");
}
[Test]
public void DoAThing()
{
// This test passes
var a = Mock.Of<IA>();
var aMock = Mock.Get(a);
aMock.Setup(i => i.DoAThing()).Returns<string>(v => "Not A Thing");
}
}
public interface IA
{
string DoAThing();
string DoTheThing(string a);
}
public class A : IA
{
public string DoAThing()
{
return "A Thing Default";
}
public string DoTheThing(string a)
{
return "The Thing" + a;
}
}
} |
@neurohunter - Could you perhaps explain what your post above is about? |
@stakx I found this issue with Invalid callback in Moq in my project, found this issue discussion here and noticed that it was closed because no reproduction scenario is provided. So I've basically appended the scenario that I've used to represent the issue. |
@neurohunter, OK thanks! I didn't look above your post, I just saw a block of code without any explanation so I was confused enough already to not even look any further. Sorry for that. 😄 |
@neurohunter - I'm a bit confused however. The test that you've marked as |
@stakx Yes, you're right, I've added comments later by hand and, apparently, mixed things up. using System;
using NUnit.Framework;
using Moq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var a = new A();
Console.WriteLine(a.DoTheThing("thing"));
Console.ReadKey();
}
}
[TestFixture]
public class AFixture
{
[Test]
public void DoTheThingTest()
{
// This test passes
var a = Mock.Of<IA>();
var aMock = Mock.Get(a);
aMock.Setup(i => i.DoTheThing(It.IsAny<string>())).Returns<string>(v => "Not A Thing");
}
[Test]
public void DoAThing()
{
// this test fails with Invalid callback error
var a = Mock.Of<IA>();
var aMock = Mock.Get(a);
aMock.Setup(i => i.DoAThing()).Returns<string>(v => "Not A Thing");
}
}
public interface IA
{
string DoAThing();
string DoTheThing(string a);
}
public class A : IA
{
public string DoAThing()
{
return "A Thing Default";
}
public string DoTheThing(string a)
{
return "The Thing" + a;
}
}
} Main method is not supposed to do anything, it's just there. |
OK, in that case this is simply caused by the documented change as mentioned in the changelog:
This was requested by #445. |
In my test I get error described in this issue title:
My code for this Setup:
var userList = userRepository.GetAll().Where(x => users.Contains(x.Id)).ToList();
Moq 4.8.1. When I was using 4.7.145 everything was OK.
The text was updated successfully, but these errors were encountered: