Over the last year or more I've been learning unit testing via books I've read recently like The Art of Unit Testing, Working Effectively with Legacy Code, and others. I've also been using unit tests, mocking frameworks, and the like, periodically at work and definitely see the value.
However, I'm still having a hard time wrapping my mind around TDD (as opposed to TAD) when the situation calls for code that is gong to mostly use external API calls.
Problem to solve
Get the process associated with a windows service using the service name.
Function GetProcess(ByVal serviceName As String) As Process
- Show each major iteration in production & test code using TDD
- No need to see any other code or configuration that is required to get things to run. Just curious about the interfaces, concrete classes, and test methods.
- C# or VB.NET
- Must use the .Net framework regarding services/processes (i.e.
- Test Frameworks:
- Nunit or MSTest
- Isolation Frameworks:
- Moq, Rhino Mock, or Microsoft Moles
- Must write true unit tests (no integration tests)
As far as I can tell there are two approaches design wise.
- Use an Inversion of Control approach along with using the Adapter and/or Facade patterns to wrap the underlying .net framework objects dealing with processes and services.
- Keep the .net framework code in the class containing the Get Process method and use code detouring (interception) via Microsoft Moles to isolate the hard dependencies from the method under test.