【发布时间】:2017-08-18 14:43:14
【问题描述】:
我正在尝试最小化一个具有内部构造函数的具体类,即在MyAssembly 我有
public class MyClass {
internal MyClass(){}
// other methods including factory instance method
}
然后在 `TestAssembly' 的测试中我有
var mock = new Mock<MyClass>();
在MyAssembly我已将以下内容添加到AssemblyInfo.cs
[assembly: InternalsVisibleTo("TestAssembly")]
但即使将TestAssembly 设置为MyAssembly 的朋友,Moq 仍然会抛出错误
Castle.DynamicProxy.InvalidProxyConstructorArgumentsException
Can not instantiate proxy of class: Civica.Metadata.Models.Entities.Stage.
Could not find a parameterless constructor.
Moq 应该能够以这种方式使用内部构造函数创建模拟吗?
【问题讨论】:
-
Moq 将无法访问构造函数来模拟实现。
-
@Nkosi 即使我将其标记为内部可见?我可以在我的测试项目中使用内部构造函数创建我的类的实例,那么为什么不能 Moq?
-
看起来有人找到了答案。试试看。
标签: c# moq .net-assembly