Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf behavior unit test

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!

like image 249
Asier Barrenetxea Avatar asked Jul 05 '11 09:07

Asier Barrenetxea


1 Answers

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.

like image 92
Avada Kedavra Avatar answered Sep 20 '22 09:09

Avada Kedavra