My two pence worth ....
public class MyClass
{
public MyInnerClass MyProperty { get;set; }
}
public class MyInnerClass
{
public MyFoo Foo { get;set; }
}
var instance = new MyClass();
instance.MyProperty.Foo = new MyFoo();
... the code you are suggesting violates the "Law of Demeter"
really you should encapsulate MyInnerClass , i.e.
public class MyClass
{
private MyInnerClass MyProperty { get;set; }
public MyFoo Foo
{
get { return MyProperty.Foo; }
set { MyProperty.Foo = value; }
}
}
the "Law of Demeter" says that a client of an object should not know
about the internals of the object; and therefore in the example, the
client should not know that Foo is actually a property of
MyInnerClass.
I hope that makes sense ...
However, in order to address your question with regards to how to mock
this stuff (prior to modifying your implementation, should you choose
to do so) ...
var mockedMyInnerClass = MockRepository.GenerateStub<MyInnerClass>();
var mockedMyFoo = MockRepository.GenerateStub<MyFoo>();
mockedMyInnerClass.Stub(mock => mock.Foo).Return(mockedMyFoo);
var myClass = new MyClass();
myClass.MyProperty = mockedMyInnerClass;
On Nov 24, 12:30 pm, Gary <[email protected]> wrote:
> Assuming a mocked object x, of type X (see below), how can I accomodate
> the call to
> x.property_of_x.foo
> in client code, i.e. a class under test?
>
> class X
> {
> public Thing property_of_x
> {
> set { ... }
> }
>
> }
>
> class Thing
> {
> public String foo
> {
> set { ... }
> }
>
> }
>
> --
> Gary Please do NOT send me 'courtesy' replies off-list.
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.