How would you TDD the functionality of getting the corresponding process of a running windows service?
Posted
by
Matt Spinelli
on Programmers
See other posts from Programmers
or by Matt Spinelli
Published on 2011-02-10T20:01:54Z
Indexed on
2011/02/10
23:33 UTC
Read the original article
Hit count: 287
Purpose
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.
example: Function GetProcess(ByVal serviceName As String) As Process
Rules
- 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.
System.Diagnostics.Process
) - Test Frameworks:
- Nunit or MSTest
- Isolation Frameworks:
- Moq, Rhino Mock, or Microsoft Moles
- Must write true unit tests (no integration tests)
Additional notes
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.
© Programmers or respective owner