Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

partial argument match in rhino mocks

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

like image 623
john Avatar asked Dec 01 '09 07:12

john


2 Answers

// 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))
);
like image 116
Darin Dimitrov Avatar answered Nov 01 '22 10:11

Darin Dimitrov


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);
like image 38
Don Kirkby Avatar answered Nov 01 '22 11:11

Don Kirkby