You can not use Arg.Do(...), or any Arg. methods, on non-substitutes
or on non-virtual methods (as Brendan pointed out). They tell
NSubstitute to do stuff internally, but externally they just return
null.
If you want to stub out the result of `callMethod` I'd normally
extract out a class (or Func) that handles the required behaviour and
substitute that.
public class MethodTwoEr {
public virtual string MethodTwo(object x) { ... }
}
public class myClassName {
MethodTwoEr a;
public myClassName(MethodTwoEr a) { this.a = a; }
public void myMethod() {
// stuff
var result = a.MethodTwo(variable);
// more stuff with result
}
[Test]
public void TestMyMethod() {
var sub = Substitute.For<MethodTwoEr>();
sub.MethodTwo("hello").Returns("World");
var myClass = new myClassName(sub);
myClass.myMethod();
//assert that myMethod used the return value form
MethodTwoEr.MethodTwo properly.
}
Does that help?
Cheers,
David