RhinoMocks グループにはすでにスレッドがあります。
GenerateMock は動的モックを作成します。動的モックは、指定されていない (=期待される) 呼び出しを許可します。これが発生した場合、null (または戻り値の型の既定値) を返すだけです。
注:繰り返しは (スタブのような) 動作の仕様であり、期待値で指定されていても期待値ではありません。
特定の数以上の呼び出しを避けたい場合は、次のように記述できます。
[Test]
public void uhh_what()
{
var a = MockRepository.GenerateMock<IPrebuiltNotifier>();
a.Expect(x => x.Notify()).Repeat.Once();
a.Stub(x => x.Notify()).Throw(new InvalidOperationException("gotcha"));
a.Notify();
// this fails
a.Notify();
a.VerifyAllExpectations();
}
または
[Test]
public void uhh_what()
{
var a = MockRepository.GenerateMock<IPrebuiltNotifier>();
a.Notify();
a.Notify();
// this fails
a.AssertWasCalled(
x => x.Notify(),
o => o.Repeat.Once());
}