john
john

Reputation: 111

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

Upvotes: 11

Views: 2915

Answers (2)

Don Kirkby
Don Kirkby

Reputation: 56620

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);

Upvotes: 7

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

// 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))
);

Upvotes: 16

Related Questions