开发者

Stub property and save other behaviour

开发者 https://www.devze.com 2022-12-20 19:48 出处:网络
Is it possible to stub only one property and keep other\'s behaviour using Rhino Mocks? Upd. Example: I have a class with two properties

Is it possible to stub only one property and keep other's behaviour using Rhino Mocks?

Upd. Example: I have a class with two properties

public class ClassA
{
 public string Property1
 {
  get
  {
   return "Property1";
  }
 }

 public string Property2
 {
  get
  {
   return "Property2";
  }
 }
}

I would like to get an instance of this object with the stubbed only Property1 (and property2 should work as it does).

When I use the following code:

ClassA classA = MockRepository.GenerateStub<ClassA>();
classA.Stub(c => c.Pr开发者_C百科operty1).Return("stubbed property 1");

and then try to access classA.Property2 it returns null.


Take a look at Partial Mock

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号