In spite of these limitations, we still have a driving need and concern to write good software using SOLID principles and to do what we can to unit test the code. The question then becomes, how do you achieve these goals in a world that has long since moved on to far more flexible versions of the language and tools?
To achieve this, time was spent evaluating and googling for solutions. The coding environment and unit testing framework were easy as we had both available and they do support .NET 2.0. The mocking framework, however, proved to be a bit more troublesome. In the end, we used Visual Studio 2013, NUnit (version 2.6.4 through NuGet) and NMock (version 2.0.0.44).
To get started you may notice that there is no built-in Test Project for .NET 2.0 in VS2013. Don't worry, simply create a new Library Project and then add your NUnit reference. Create a new class, add the <TestFixture> tag to the top and away you go!
.NET 2.0 is lacking many of the features you may be accustomed to with .NET 4 or 4.5, including lambdas and generics, while VB.Net does not even support LINQ. This severely reduces the mocking frameworks available to you as most require a minimum of .NET 3.5 to operate (because they rely heavily upon generics).
So, what is a developer to do? Introducing NMock (http://nmock.sourceforge.net/)! I have used MOQ for years, but in the last year I have become quite familiar with NMock and have grown to accept it as a decent substitute.
Instead of MOQ's Setup function, you use Stub and Expect. You specify the Methods and Properties to mock by name and you can even verify the incoming parameters on the methods using "NMock2.Is..." syntax. Should you need additional matching functionality, particularly for handling lists, you will likely have to write your own or modify existing ones. For my project, I ended up extending the IsList Matcher (found on the nmock documentation page: http://nmock.sourceforge.net/advanced.html) with functionality that allowed me to do "Contains" and "EquivalentTo" checks.
Here's it in use:
Or here with a real-world example:
Here's it in use:
Or here with a real-world example:
That about covers it. You can read more about using NMock on the project's sourceforge page or on StackOverflow, but it is pretty powerful, extensible, and a decent fill-in for more modern and mainstream mocking frameworks.
Enjoy and happy coding!