26-July-2010 A project I am currently working on requires us to reference a third party assembly. As is quite often the case the assembly is not exposing types that are unit testing friendly. Ideally interfaces or abstract base classes would be great, but this is seldom the case. I've been refining a strategy to consume dependencies in a indirect manner so the hard coded types don't work their way through my code essentially having a "Medusa" effect. IE: Casting all of my types into stone and then they too cannot be replaced with test mocks. Consider the schematic diagram below. The blue assembly is the Medusa assembly, wanting to cast all my types into stone. But wait I have a magic mirror shield! The External Type Factory. This is intended to control the creation of types I need to consume from the external assembly. The other issue is being able to invoke methods in the external assembly that require the hard types(Widget, Color, and Thing) as parameters. The External Type Factory has adaptor methods to unwrap my wrappers back to their original types in an indirect manner to stop the petrification effect. The good:
The bad:
I might add detail to this as I continue the journey down this path. |