Reputation: 79
I'm attempting to stub a method using a type constraint on one of the arguments. Normally I already know the type and write:
o.Stub(x => x.SomeMethod(Arg<bool>.Is.Anything)).Return(...);
Instead, I'd like to catch all calls to SomeMethod
where the first arg passed in derives from a base class, say B
. Is this possible? Can someone help with an example?
Pseudo code for what I'd like to specify:
o.Stub(x => x.SomeMethod(Arg.Type.Equals(typeof(B))).Return(...);
and have this catch calls like SomeMethod(a);
where a
is of type A
and A
derives from B
.
Upvotes: 0
Views: 297
Reputation: 3827
Rhino Mocks does support that as part of its constraints, your code should be something like:
o.Stub(x => x.SomeMethod(Arg<B>.Is.TypeOf)).Return(...);
Upvotes: 1
Reputation: 247068
Given your example.
o.Stub(x => x.SomeMethod(Arg<B>.Is.Anything)).Return(...);
...should work for any classes derived from B.
Upvotes: 0