I am using an attached Behaviours to add drag and drop functionality to my code. So far, everything is working fine, but my problem is when I want to test my behaviour classes.
For example, one of the behaviour classes would be something like the following:
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)
{
...
}
}
My problem now is when I want to create a unit test for the AssociatedObject_Drop method, i would need to create a DragEventArgs object, but this class is sealed.
I got the impression that I am doing something wrong.. My question is, should i be testing my behaviour classes? Behaviours are related with UI, and usually it's not worth it to test UI. Am i right? Maybe I have to change my behaviours code to make it more testable? any ideas?
Thanks for your help!
I would refactor the code and move out any business logic from AssociatedObject_Drop
into its own function(s) and then write my unit tests for those functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With