Setting out and ref args

Out and ref arguments can be set using a Returns() callback, or using When..Do.

public interface ILookup {
    bool TryLookup(string key, out string value);

For the interface above we can configure the return value and set the output of the second argument like this:

var value = "";
var lookup = Substitute.For<ILookup>();
    .TryLookup("hello", out value)
    .Returns(x => { 
        x[1] = "world!";
        return true;

var result = lookup.TryLookup("hello", out value);

Assert.AreEqual(value, "world!");