使用
mocks.Record
要设置模拟对象,请使用
mocks.PlayBack
运行测试。
public class A { }
public class B : A { }
public interface IMyInterface
{
A GetA();
}
[TestFixture]
public class RhinoTestFixture
{
[Test]
public void TestStub()
{
// Create a stub
var mocks = new MockRepository();
IMyInterface stub;
using (mocks.Record())
{
stub = mocks.Stub<IMyInterface>();
stub.Expect(x => stub.GetA()).Return((new B()));
}
using (mocks.Playback())
{
var myA = stub.GetA();
Assert.IsNotNull(myA);
}
}
}