Using FakeItEasy and xBehave.net, I'm trying to mock a System.Windows.Forms.TreeView.
I get the following error:
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.
This confuses me because the only constructor I see in the docs is a public, default constructor.
Here's demo code that gives the error:
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>();
});
}
}
}
Does anyone know what's going wrong or how to troubleshoot this? Thanks.