3

I have a class that I am testing. This class uses takes in an interface as a constructor parameter. This interface has a method that has an out parameter.

What I want to do is mock this method so that the out parameter is always a particular value.

How can this be done?

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
  • 2
    This question may be of help: [Assigning out/ref parameters in Moq](http://stackoverflow.com/questions/1068095/assigning-out-ref-parameters-in-moq) – Scampbell Dec 19 '13 at 15:19

1 Answers1

13

To do this just create a local with the desired value and use that in the out position.

int theValue = 42;
Mock<ITarget> target = ...;
target.Setup(x => x.TheMethod(out theValue));
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454