Is there a point Unit Testing a Repository? Entity Framework 4.1 -


i have been watching various videos , reading various blogs go unit testing repository.

the common pattern create fake repository implements same interface real one. fake 1 uses internal dictionary or something.

so in effect unit testing logic of fakerepository never go production.

now may use dependency injection inject mock dbcontext using idbcontext interface. testing each repository method in effect forward dbcontext (which mocked).

so unless each repository method has lots of logic before calling on dbcontext seems bit pointless?

i think better have tests on repository integration tests , have them hitting database?

the new ef 4.1 makes easy can create database on fly based on connection string in test project, can delete after tests run using dbcontext.database methods.

your objections partially correct. correctness depends on way how repository defined.

  • first faking or mocking repository not testing repository testing layers using repository.
  • if repository exposes iqueryable , upper layer can build linq-to-entities query mocking repository means testing non existing logic. need integration test , run query against real testing database. can either redeploy database each test make slow or can run each test in transaction , rollback when test completes.
  • if repository doesn't exposes iqueryable can still think black box , mock it. query logic inside repository , tested separately integration tests.

i refer set of other answers repository , testing.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -