Yesterday I came upon an oddity when I was refactoring code. Deciding
to dive a little deeper I uncovered the following that I was hoping
someone could help me sort through.
[Test]
public void
fails_on_mocking_a_derived_class_generic_method_and_executing_a_base_class_generic_method_is_different()
{
var derivedClass = new DerivedClassFromBaseClass();
var genericInterface =
MockRepository.GenerateMock<IGenericInterface>();
genericInterface.Expect(x => x.Test(derivedClass));
genericInterface.Test(derivedClass as TestBaseClass);
genericInterface.VerifyAllExpectations();
}
[Test]
public void should_pass_based_on_derivedClass_without_template()
{
var derivedClass = new DerivedClassFromBaseClass();
var iinterface = MockRepository.GenerateMock<IInterface>();
iinterface.Expect(x => x.Test(derivedClass as TestBaseClass));
iinterface.Test(derivedClass);
iinterface.VerifyAllExpectations();
}
public class DerivedClassFromBaseClass : TestBaseClass
{
}
public abstract class TestBaseClass
{
}
public interface IInterface
{
void Test(TestBaseClass obj);
}
public interface IGenericInterface
{
void Test<T>(T obj) where T : TestBaseClass;
}
At first glance I was puzzled why the failing test wasn't passing, but
as I dived deeper I realized that the generic method's signature was
different based upon which generic type was being inferred. Is this
just a case of me doing thing incorrectly and I should be setting the
expectation on the test Method as follows:
genericInterface.Expect(x => x.Test(derivedClass as TestBaseClass));
Or should I dive further into the code and see if the method
comparisons should walk the inheritance chain to determine equality
somewhere around the ProxyMethodExpectationTriplet.
--
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.