28

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.

Thomas Sobieck
  • 1,416
  • 1
  • 20
  • 27
Charles Ouellet
  • 6,338
  • 3
  • 41
  • 57

1 Answers1

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