I have a method that has an out parameter that returns a number of records. I would like to know how to mock it with FakeItEasy.
Asked
Active
Viewed 6,107 times
1 Answers
49
You should use the .AssignsOutAndRefParameters configuration method:
[Test]
public void Output_and_reference_parameters_can_be_configured()
{
var fake = A.Fake<IDictionary<string, string>>();
string ignored = null;
A.CallTo(() => fake.TryGetValue("test", out ignored))
.Returns(true)
.AssignsOutAndRefParameters("foo");
// This would of course be within you SUT.
string outputValue = null;
fake.TryGetValue("test", out outputValue);
Assert.That(outputValue, Is.EqualTo("foo"));
}

Patrik Hägne
- 16,751
- 5
- 52
- 60
-
1@Patrik Hägne, If i have 2 out arguments in a function then how pass it to AssignsOutAndRefParameters() function. – Umesha MS Dec 15 '14 at 12:18
-
1@UmeshaMS, `.AssignsOutAndRefParameters("out1", "out2") – Blair Conrad May 27 '16 at 18:32
-
Link to the official documentation: https://fakeiteasy.readthedocs.io/en/stable/assigning-out-and-ref-parameters/ – Malcolm Feb 05 '20 at 22:13