Geoff Lane does a very good job of explaining .NET Mock objects.
People were requesting a “concrete” example so I implemented an example C# console application (although this can easily be made into an ASP.NET web application).
Geoff hints to using Spring .NET to wire things up, but that might be too confusing for some people. And maybe a little over board for a simple example (open closed principle).
So instead I created a PersonServiceManager that creates a “concrete” PersonService via IPersonRepository injection. The GUI communicates to the PersonServiceManager through an IPersonService interface.
Instead of “mocking” an IPersonRepository, we are actually implementing it then injecting it into PersonService (just like our NUnit test). The PersonServiceManager handles passing the appropriate database connection string down to the data layer. In my example, the data layer object PersonDb (which implements IPersonRepository and used for injection) utilizes the DbProviderFactory.
Here is the sample source (C# Console App).
Also remember that the sample source could be broken down into separate assemblies in a real world project.