Asi*_*xea 7 testing wpf unit-testing behavior
我正在使用附加的行为向我的代码添加拖放功能.到目前为止,一切工作正常,但我的问题是当我想测试我的行为类.
例如,其中一个行为类将类似于以下内容:
public class DroppableContainerBehavior: Behavior<FrameworkElement>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.AllowDrop = true;
AssociatedObject.Drop += new DragEventHandler(AssociatedObject_Drop);
AssociatedObject.DragOver += new DragEventHandler(AssociatedObject_DragOver);
AssociatedObject.DragLeave += new DragEventHandler(AssociatedObject_DragLeave);
}
private void AssociatedObject_Drop(object sender, DragEventArgs e)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
我现在的问题是当我想为AssociatedObject_Drop方法创建一个单元测试时,我需要创建一个DragEventArgs对象,但这个类是密封的.
我的印象是我做错了什么..我的问题是,我应该测试我的行为类吗?行为与UI有关,通常不值得测试UI.我对吗?也许我必须改变我的行为代码,使其更可测试?有任何想法吗?
谢谢你的帮助!