如何在Rhino Mocks中保存函数调用的参数?

时间:2011-09-18 09:45:46

标签: c# mocking rhino-mocks

    MockRepository mocks = new Rhino.Mocks.MockRepository();  
    IActiveProgram  repository = mocks.CreateMock<IActiveProgram>();  


    var readPrg = new ReadProgram();
    readPrg.init("333", "eee", "", null, repository);

readPrg.init中,我将对repository个对象进行多次调用。 例如repository.AddProgram(programName);

稍后我会从readPrg.init退出时知道我预先记录的函数调用已执行的参数。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

调用init后,您将调用repository.AssertWasCalled(x => x.AddProgram(programName))。另见the original post of Rhino Mocks AAA syntax
另一种选择,你可以使用Expect:

repository.Expect(x => x.AddProgram(programName)).Repeat.Times(50)
var readPrg = new ReadProgram();
readPrg.init("333", "eee", "", null, repository);
repository.VerifyAllExpectations()