无法使用Rhino Mocks使用具有数组参数的构造函数来模拟类 [英] Cannot mock class with constructor having array parameter using Rhino Mocks

查看:50
本文介绍了无法使用Rhino Mocks使用具有数组参数的构造函数来模拟类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们无法在RhinoMocks中模拟此类.

We are not able to mock this class in RhinoMocks.

public class Service
{
    public Service(Command[] commands){}
}
public abstract class Command {}

// Code
var mock = MockRepository.GenerateMock<Service>(new Command[]{}); // or
mock = MockRepository.GenerateMock<Service>(null)

Rhino模拟无法抱怨它找不到具有匹配参数的构造函数. 我在做什么错了?

Rhino mocks fails complaining that it cannot find a constructor with matching arguments. What am I doing wrong?

谢谢

推荐答案

尝试如下:

var mock = MockRepository.GenerateMock<Service>(
    new object[] { new Command[0] }
);

这篇关于无法使用Rhino Mocks使用具有数组参数的构造函数来模拟类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆