Hi, I am trying to build a test against some legacy method that implement out parameters. Could you give me an example how to do this?
Very grateful
Hi, I am trying to build a test against some legacy method that implement out parameters. Could you give me an example how to do this?
Very grateful
Just assign the out
or ref
parameter from the test.
Given this interface:
public interface ILegacy
{
bool Foo(out string bar);
}
You can write a test like this:
[TestMethod]
public void Test13()
{
string bar = "ploeh";
var legacyStub = new Mock<ILegacy>();
legacyStub.Setup(l => l.Foo(out bar))
.Returns(true);
Assert.IsTrue(legacyStub.Object.Foo(out bar));
Assert.AreEqual("ploeh", bar);
}
Anything wrong with the second example at the top of http://code.google.com/p/moq/wiki/QuickStart ? You really should be giving examples of what you're trying to do if you're not going to look for things like this.