views:

87

answers:

2

Hi, In my unit test instead of IgnoreArguments i want to use some partial matching of arguments in rhino mocks testing. How to do that?

Thanks, John

+2  A: 
// arrange
var fooStub = MockRepository.GenerateStub<IFoo>();

// act
fooStub.Bar("arg1", "arg2", 3);

// assert
fooStub.AssertWasCalled(
    x => x.Bar(
        Arg<string>.Is.Equal("arg1"), 
        Arg<string>.Is.Anything, 
        Arg<int>.Is.Equal(3))
);
Darin Dimitrov
A: 

You can use constraints. You ignore the arguments passed into the expectation call and then add explicit constraints for each argument. An example from the Rhino Mocks documentation:

Expect.Call(view.Ask(null,null)).IgnoreArguments().Constraints(
   Is.Anything(), 
   Is.TypeOf(typeof(SomeType))).Return(null);
Don Kirkby