I cannot understand why FakeItEasy
does not allow me to set return value for public method with parameters.
The code:
var fakeInstanse = A.Fake<SomeClass>();
A.CallTo(() => fakeInstanse.Method(param1, param1));
The Method
is the public one, accepts two parameters. Normally I would call Returns()
method on second line of code, but Visual Studio does not show it among available.
What might affect this behavior? What part of SomeClass
or Method
definition might cause this?
In general, this should work. Check out this passing test:
public class SomeClass
{
public virtual int Method(int arg1, int arg2)
{
return 7;
}
}
[TestFixture]
public class TestFixture
{
[Test]
public void Should_be_able_to_set_return_value()
{
const int param1 = 9;
var fakeInstanse = A.Fake<SomeClass>();
A.CallTo(() => fakeInstanse.Method(param1, param1))
.Returns(8);
Assert.That(fakeInstanse.Method(param1, param1), Is.EqualTo(8));
}
}
What's the return type of your Method
? From your description, I'd guess that it's void
.
Could you show us the declaration of SomeClass (and SomeClass.Method)? Otherwise, we're not going to be able to give constructive answers. Also, you may find some help at the FakeItEasy "what can be faked" documentation page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With