新しいRhinoMocks3.5 Arrange / Act / Assert(AAA)テストスタイルを使用すると、テストの作成に問題が発生します。
リポジトリクラスのメソッドを呼び出すメソッドがあります。ActivateFoo。FooオブジェクトにはIsActiveプロパティがあります。ActivateFooオブジェクトの結果により、プロパティが変更されます。
サンプルコードは次のとおりです。
[TestMethod]
public void Should_update_foo_to_active_inside_of_repository()
{
// arrange
var repo = MockRepository.GenerateMock<IRepository>();
var foo = new Foo() { ID = 1, IsActive = false };
var target = new Presenter(repo);
repo.Expect(x => x.ActivateFoo(foo)).Return(true);
// act
target.Activate(foo);
// assert
Assert.IsTrue(foo.IsActive);
repo.VerifyAllExpectations();
}
コードの重要な部分は「ActivateFoo(foo))」の間にあると思います。および「Return(true);」。
メソッドチェーンが舞台裏でどのように機能するかを明確にするための1つのポイント、期待する行にコードが記述されている場合、それがReturn()の後か前かは重要ですか?(もちろん、ソリューションがExpectのMethodOptionsオーバーロードなどを使用している場合を除きます)。
助けてくれてありがとう。