2

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
  • 218,019
  • 46
  • 414
  • 706
Sachin Kainth
  • 43,353
  • 79
  • 196
  • 295
  • 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

10

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
  • 703,665
  • 143
  • 1,211
  • 1,438