简体   繁体   English

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

[英]How to save arguments of function call in Rhino Mocks?

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


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

In readPrg.init I will have a several calls on repository object. readPrg.init我将对repository对象进行多次调用。 For example repository.AddProgram(programName); 例如repository.AddProgram(programName);

How I will be able to know later on exit from readPrg.init to know the arguments that my prerecorded function calls been executed. 稍后在readPrg.init退出时readPrg.init知道预记录函数调用已执行的参数。

Thanks for help. 感谢帮助。

You'd call repository.AssertWasCalled(x => x.AddProgram(programName)) after you call init. 调用init后,您将调用repository.AssertWasCalled(x => x.AddProgram(programName)) Look also in the original post of Rhino Mocks AAA syntax Rhino Mocks AAA语法的原始帖子中也可以查看
Another option, you could use Expect: 另一种选择,您可以使用Expect:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM