如何用Rhino Mocks模拟索引属性?

时间:2009-01-09 22:09:24

标签: c# .net rhino-mocks

如何使用Rhino Mocks模拟索引属性?

1 个答案:

答案 0 :(得分:22)

我假设您使用this[]

表示属性
  var mockClass = MockRepository.GenerateMock<MockClass>();

  mockClass.Expect( m => m["key"] ).Return( "value" );  // return a value
  mockClass.Expect( m => m["key2"] = "value2" );  // set a value

  ... some test in here using something that depends on mockClass...


  mockClass.VerifyAllExpectations();