I use PetaPoco in my current project as micro ORM, and I have to say that I like it. However, I found myself struggling with a simple script - unit testing services that use PetaPoco.Database
public class MyService : IMyService { private readonly PetaPoco.Database _database; public MyService(PetaPoco.Database database) { _database = database; } public void SaveSomething(MyObject myObject) {
I use IoC (Castle.Windsor) to inject both IMyService and PetaPoco.Database , where necessary.
Now, when I try to run a unit test on my service, I cannot correctly comment on stub PetaPoco.Database to make sure that the Save method was correctly called. I use NUnit and Rhino.Mocks for unit testing and ridicule.
[TestFixture] public class MyServiceTests { private PetaPoco.Database _database; [SetUp] public void SetUp() { _database = MockRepository.GenerateMock<Database>(""); } [Test] public void ShouldProperlySaveSomething() {
I know that this can be solved if I extract the interface from PetaPoco.Database and mock it or by virtualizing the PetaPoco methods that I want to make fun of, but the fact is that I do not want to make changes to PetaPoco at all.
Is this doable?
ljubomir
source share