views:

226

answers:

2

I tried with NMock2 but I get TypeLoadExceptions when trying to pass the mocks into the constructor, also I saw TypeMock can do that but it costs 80$

+1  A: 

Moq does not support mocking out/ref parameters, but you can do it using Rhino Mocks using OutRef, which accepts one argument for each out/ref parameter in the method.

MockRepository mockRepository = new MockRepository();

// IService.Execute(out int result);
var mock = mockRepository.CreateStub<IService>();

int mockResult; // Still needed in order for Execute to compile

mock.Setup(x => x.Execute(out mockResult)).OutRef(5);
mock.Replay();

int result;

mock.Execute(out result);

Assert.AreEqual(5, result);
Richard Szalay
A: 

I found out myself, you can actually do that with Moq, it's like this:

var info = new Info { stuff = 1 };

textReader.Setup(o => o.Read<CandidateCsv>("", out info));

that's it :)

Omu
That's true, but you can't have Moq change the value of info when Read is executed.
Richard Szalay