lundi 22 juin 2015

Creating object with a base class which needs a mocked interface using AutoFixture

I hope someone can help me with this as I'm new to AutoFixture. I'm currently trying to rewrite some of our old unit tests using AAA syntax, AutoFixture, RhinoMocks and NUnit instead of our current hard coded test data but I'm running into trouble.

I have a service which inherits a base class but the base class requires a type of respository.

Public class PropertyService : BaseService<IPropertyRepository>, IPropertyService { ... }

My question is how I go about testing this. I need to test a method on the propertyservice which calls the repository on the base class. So I need the repository to be mocked but as it stands if I try the following:

var propertyService = _fixture.Create<PropertyService>();

I get a exception from StructureMap, our DI container, No Default Instance defined for PluginFamily Repository.IPropertyRepository.

With my limited knowledge on AutoFixture I think what I need is a real version of my PropertyService but I need a mocked version of the IPropertyRepository but I've been trying for the last 3 hours to do that with no joy. I've tried to create a mocked version of IPropertyService and then inject that into the fixture but that doesn't seem to work, I still get the StructureMap error above.

If someone can make sense of my waffling and point my in the right direction I would be most grateful.

Aucun commentaire:

Enregistrer un commentaire