I'm presently working on a project that includes tests with RhinoMocks mocked objects. Since upgrading to RhinoMocks 3.6.1 from 3.6.0 previously working project code is failing during testing. The issue seems to be caused by changed behavior of mock objects between versions. Previously it was possible to gather MethodInfo from a mocked object via reflection, but that no longer seems to be the case. Should I be setting up my mocks in a different way?
A greatly simplified example follows:
Given an interface to be mocked
public interface IValidator<in T>
{
bool Validate(T obj);
}
in testing code the mock is created with an expectation:
var validator = MockRepository.GenerateMock<IValidator<string>>();
validator.Expect(v => v.Validate(Arg<string>.Is.Equal("input")))
.Return(true);
...
// the validator object is then passed into a consumer and assertions
// are checked to be sure the consumer and validator appropriately
// behave (outside scope of question)
Within the consumer class reflection is done to get the "Result" method from the interface in order to be invoked during standard execution:
var method = validator.GetType()
.GetMethod("Result", BindingFlags.Public | BindingFlags.Instance);
The problem is method
is now null when using the update version of RhinoMocks.
Aucun commentaire:
Enregistrer un commentaire