Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FakeItEasy does not allow to setup value to return

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?

like image 719
shytikov Avatar asked Sep 05 '25 17:09

shytikov


1 Answers

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.

like image 192
Blair Conrad Avatar answered Sep 07 '25 11:09

Blair Conrad