Hi,
In reference to an earlier question of mine link text, I have been searching for good ways to write code that is very dependant on 3d party libraries, but still unit-testable.
Just to sketch the contest (so you don't have to read the previous post), I am writing code with the AutoCAD API. This way my code is very dependant on that API, and even worse, AutoCAD requires the code to be running inside AutoCAD context, otherwise there are Licensing exceptions. This causes unit testing with the AutoCAD API as being a no-no.
Now, I'm wondering if using the Adapter Pattern for this would be a nice work-around? This way I could work with my own adapter classes and unit test that functionality.
Would this be a possible implentation of the adapter pattern and would this be a good idea? Are there things I'm overlooking?
Any other suggestions, all is welcome
edit:
- as Gerrie suggested, wrapping the acad classes could be a route to go. Because the API is not as straight-forward, we already are wrapping a lot of the acad functionality. This way we can provide common tasks to the developer in an easy and stable way. But, the wrapping code is the code that we want to unit test...
So for example, a Polyline Wrapper. I would need: - Acad Polyline class - Polyline Adapter Class, mimicking the Acad Polyline - Polyline Wrapper Class, providing stable and encapsulated code for common functionalities.
In (pseudo) code:
public class PolylineAdapter:IPolyline
{
private Acad.Polyline acadPolyline; // initialized through constructor
public void AddVertexAt(int i, IPoint2d pt) { // call acadPolyline.AddVertexAt }
}
public class PolylineWrapper
{
private PolylineAdapter internalPolyline;
public void AddVertex(WrappedPoint2d pt)
{
// this I can now unit-test
writeEnableInternalPolyline();
internalPolyline.AddVertexAt(0, pt.InternalPoint);
writeDisableInternalPolyline();
}
}