简体   繁体   中英

How to Mock Indexed Property with Rhino Mocks?

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

I'm assuming you mean a property using 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM