I've got a simple standard repository that loads an amalgamated entity in the database. It inserts all dependencies it have to browse the complete entity tree from the database through IDbConnection (wich provides the repository use of IDbCommand, IDbTransaction, IDataReader) which i could mock.

public class SomeCompositionRootEntityRepository : 
    public RecipeRepository(IDbConnection connection) { ... }
    public void Add(SomeCompositionRootEntity item) { ... }
    public bool Remove(SomeCompositionRootEntity item) { ... }
    public void Update(SomeCompositionRootEntity item) { ... }
    public SomeCompositionRootEntity GetById(object id) { ... }
    public bool Contains(object id) { ... }

Now you ask , wouldso would I write unit test with this in a great way? If I wish to test the reposity has browse the whole tree of objects and contains see clearly correcty, I will have to write a hughe mock that records and certifies the read of every single property of every single object within the tree. Is really what you want?

Update: I believe I have to refactor my repository to interrupt the repository functionality and unit test into more compact models. How could this be achieved?

I am certain I don't want to create unit test which involve reading through and writing to and from a real database.

Now you ask ,: What functionality would you like to test?

  1. Would you like to test that the repository really loads something? Within this situation I'd write a couple of (!) tests that feel the database.
  2. Or would you like to test the functionality within the repository techniques? Within this situation your mock approach could be appropriate.
  3. Or would you like to make certain the (trivial) techniques of the repository aren't damaged? Within this situation mocks and something test per method may be sufficient.

Just request yourself exactly what the tests shall ensure and design them along this target!

I believe I realize your question so correct me if I am wrong...

This can be a in which you mix the road from unit to integration. The exam is sensible (I have written these myself), but you are not necessarily testing your repository, rather you are testing that the entity (SomeCompositionRoot) maps properly. It is not placing/upgrading, but does involve a read towards the database.

Based on what ORM you utilize, this can be done millions of various ways and typically its simple enough.

::EDIT:: such as this for linq for instance ...

    public void ShouldMapBlahBlahCorrectly()

    private T CheckBasicMapping<T>() where T : class
        var target = _testContext.GetTable<T>().FirstOrDefault();
        return target;