2009-12-01 71 views

回答

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

您可以使用constraints。您忽略傳入期望調用的參數,然後爲每個參數添加顯式約束。來自Rhino Mocks文檔的示例:

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