Hi,
If I understand correctly, you have something like this:
public class Menu
{
private Parent m_Parent;
public Parent Parent
{
get { return m_Parent;}
set { m_Parent = value;}
}
public bool Do()
{
if (Parent != null)
{
return Parent.Foo();
}
else
{
return false;
}
}
}
public class Parent
{
public bool Foo()
{
return false;
}
}
And you want to mock both the call to the Parent property, and the call to Foo function. Here's a sample using reflective mocks:
[TestMethod,VerifyMocks]
public void TestWithMockingTheProperty()
{
MockObject<Parent> mockParent = MockManager.MockObject<Parent>();
mockParent.ExpectAndReturn("Foo", true);
Parent parent = mockParent.Object;
Mock mockMenu = MockManager.Mock<Menu>();
mockMenu.ExpectGetAlways("Parent", parent);
Menu menu = new Menu();
Assert.IsTrue(menu.Do());
}
And in Naturals:
[TestMethod,VerifyMocks]
public void TestWithMockingThePropertyNatural()
{
Menu menu = new Menu();
using (RecordExpectations rec = new RecordExpectations())
{
Parent fake = menu.Parent;
rec.RepeatAlways();
rec.ExpectAndReturn(fake.Foo(), true);
}
Assert.IsTrue(menu.Do());
}
Here's how to check the null part:
[TestMethod, VerifyMocks]
public void TestWithMockingThePropertyNullNatural()
{
Menu menu = new Menu();
using (RecordExpectations rec = new RecordExpectations())
{
rec.ExpectAndReturn(menu.Parent, null).RepeatAlways();
}
Assert.IsFalse(menu.Do());
}
Let me know if this works for you.