【发布时间】:2014-11-03 10:31:40
【问题描述】:
使用 FakeItEasy 和 xBehave.net,我正在尝试模拟 System.Windows.Forms.TreeView。
我收到以下错误:
FakeItEasy.Core.FakeCreationException : Failed to create fake of type "System.Windows.Forms.TreeView".
Below is a list of reasons for failure per attempted constructor:
No constructor arguments failed:
No usable default constructor was found on the type System.Windows.Forms.TreeView.
An exception was caught during this call. Its message was:
Exception has been thrown by the target of an invocation.
这让我很困惑,因为文档中唯一的 constructor I see 是一个公共的默认构造函数。
这是给出错误的演示代码:
using System.Windows.Forms;
using Xbehave;
using FakeItEasy;
namespace MockingTreeView
{
public class Class1
{
TreeView treeView;
[Scenario]
public void MockingTreeView()
{
"Given there is a treeView".f(() =>
{
// Apparently UIPermissionAttribute can't be mocked by this framework
Castle.DynamicProxy.Generators.AttributesToAvoidReplicating.Add(typeof(System.Security.Permissions.UIPermissionAttribute));
treeView = A.Fake<TreeView>();
});
}
}
}
有谁知道出了什么问题或如何解决这个问题?谢谢。
【问题讨论】:
标签: c# treeview fakeiteasy