I have the following class structure that I need to unit test:
public interface IFoo
{
int Value { get;}
int GetValue();
}
public class BaseClass : IFoo
{
public virtual int Value { get { return 100; } }
public virtual int GetValue()
{
return Value;
}
}
public class ChildClass : BaseClass, IFoo
{
public override int GetValue()
{
return Value;
}
}
I am attempting to test the ChildClass.GetValue() method with RhinoMocks.
I have the following stub code:
public ChildClass CreateChildClass(int value)
{
var childClass = MockRepository.GenerateStub<ChildClass>();
childClass.Stub(x => x.Value).Return(value);
return childClass;
}
And the following UnitTest code:
public IEnumerable<IFoo> CreateList()
{
yield return CreateChildClass(1000);
yield return CreateChildClass(2000);
}
[TestMethod]
public void virtualMethodTest()
{
var list = CreateList();
var query = from p in list
select p.GetValue(); //I can't use p.Value
var sum = query.Sum(p => p);
}
The issue at hand is the sum is always zero. I can quick watch the list and see the two mock objects with the correct values from the CreateList().
Is it possible to unit test the virtual method on the child class? or do I need to use a different RhinoMocks approach?
Thanks