-
Notifications
You must be signed in to change notification settings - Fork 2
Stubs: Simple Method Usage
haven1433 edited this page Nov 21, 2018
·
1 revision
public interface IExample {
void VoidMethod();
int StructMethod();
}
Assign custom behavior to most methods by using the assignment operator.
public void SimpleMethodUsageStub() {
var stub = new StubExample();
IExample example = stub;
// setup a method by assigning a function to that method
stub.VoidMethod = () => { };
// you can even call the method the normal way from the stub.
stub.VoidMethod();
// methods that return something are setup in the same way
stub.StructMethod = () => 7;
var result = stub.StructMethod();
Assert.Equal(7, result);
Assert.Equal(7, example.StructMethod());
}