I have been writing unit tests using NUnit and Moq with my Silverlight code for some time. One problem I am facing is related to DependencyObjects.
If something comes from DependencyObject, then I cannot create an instance in my test. For example, MouseEventArgs comes from DependencyObject. If I have code that accepts these arguments, I cannot create the arguments for several reasons ... one of them is the DependencyObject.
As far as I understand, the base constructor of DependencyObject is trying to work with some static that does not exist if the entire Silverlight system is not running and running. Any class construction that comes from DependencyObject throws an exception. Bummer.
I do not use the Silverlight Unit Test Framework because it really is not unit testing and requires a user interface. I need real, headless tests.
In any case, the best I've come up with - is to wrap these objects and provide them with the type of interfaces ITimelineMarker, and I give them extension methods for this: timelineMarker.ToInterface(). This works well, and I can mock them ... but I was wondering:
Has anyone come up with a better way to handle DepencencyObjects in Silverlight Unit Tests?
source
share