【发布时间】:2011-12-01 08:41:29
【问题描述】:
我有这个方法调用
SecurityController.GetUserPermissions( _
HttpContext.Current.User.Identity.Name.ToString, GroupAdmin, GroupTrans)
其中 GroupAdmin 和 GroupTrans 是字符串数组,是 ByRef 参数。
所以基本上它的作用是,给定一个用户名,填写管理员权限数组和允许的事务数组。
这是我无法更改的遗留代码。
这是我的部分测试:
var moqSecurityController = new Mock<ISecurityController>();
var refParam = new string[1] {"test"};
moqSecurityController
.Setup(x => x.GetUserPermissions("Bob", ref refParam, ref refParam))
.Callback((string userName, string[] groupAdmin, string[] groupTrans) =>
{
groupAdmin[0] = "Test a";
groupTrans[0] = "Test b";
});
最后,我希望在 GroupAdmin 和 GroupTrans 中都有“测试”,但我得到了 一个错误:
Invalid callback. Setup on method with parameters (String,String[]&,String[]&)
cannot invoke callback with parameters (String,String[],String[])
我错过了什么?谁能帮我模拟一下?
谢谢
【问题讨论】:
标签: unit-testing mocking nunit moq pass-by-reference