One of my goals for this blog is to illustrate the correct use of the Civil 3D API in order to help others build their applications and extensions. This is a software development blog, which means there will be a lot of code samples demonstrating the features available in the Civil 3D API. I was thinking that if I am going to spend a lot of time and effort writing code samples for the blog, it will be worthwhile to insure the code produced was reusable, so others can leverage my work in their own applications.
Following that thought, I created project “Colibra” (Civil Object LIBRary). “Colibra” is an attempt to create a collection of utilities that simplify Civil 3D API development by abstracting the complexity of the Civil 3D API into classes and components that can be reused in different applications. The implementation of “Colibra” will eliminate redundancies in code commonly found when using the Civil 3D API, simplifying the implementation of extensions and applications.
Of course, “Colibra” is a very ambitious project, and it will need some time to be completed. But in the meantime, it will give me a consistent theme for the blog; and at the same time, it will allow me to demonstrate how the Civil 3D API should be used, while discussing best practices when using external APIs.
The Source Code
Since my first exposure to TDD (Test Driven Development), I felt in love with the techniques and practices it promotes. To the point that feel very uncomfortable when I write code without writing tests first. So, I did a little extra work to insure I can use TDD while implementing “Colibra”.
The sample code provided in this post contains a Visual Studio solution with several projects to create the skeleton of the “Colibra” project. I have not started the implementation of “Colibra”, but you can find an initial project where the code will be added. Since I will be using TDD techniques for the implementation, the solution contains a “ColibraShould” project where unit tests for the “Colibra” library will be implemented.
There are several unit test frameworks available for .NET code. For your own applications running outside of AutoCAD Civil 3D, you may want to look at NUnit or the Unit Test Framework part of Visual Studio. Unfortunately, these frameworks are not easy to use with AutoCAD Civil 3D code (or any other AutoCAD Vertical for that matter). To simplify things, I created “TinyTest”. “TinyTest”is a simplified unit test library that will give us enough functionality to be able to write unit test for “Colibra”. Again, I feel insecure when writing code without unit tests; therefore, I created “TinyTestTesting” which allows me to unit test the unit test framework. Still with me?
In order to run the unit test inside of AutoCAD Civil 3D, I created “TinyRunner”. This project implements a Civil 3D extension that allows us to load the unit tests DLLs and run the unit tests for “Colibra”. In a future post, I will talk about the implementation of “TinyRunner”, which is relevant to the topic of this blog. For now, you can download the sample code and begin familiarizing yourself with the projects and if curious, with the implementation of “TinyTest” and the testing project.