Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit Testing DbContext
    primarykey
    data
    text
    <p>I've researched some information about techniques I could use to <strong>unit test a DbContext</strong>. I would like to add some <strong>in-memory data</strong> to the context so that my tests could run against it. I'm using Database-First approach.</p> <p>The two articles I've found most usefull were <a href="http://romiller.com/2010/09/07/ef-ctp4-tips-tricks-testing-with-fake-dbcontext/" rel="nofollow noreferrer">this</a> and <a href="http://refactorthis.wordpress.com/2011/05/31/mock-faking-dbcontext-in-entity-framework-4-1-with-a-generic-repository/" rel="nofollow noreferrer">this</a>. That approach relies on creating an IContext interface that both MyContext and FakeContext will implement, allowing to Mock the context.</p> <p>However, I'm trying to avoid using repositories to abstract EF, as <a href="http://jamesmckay.net/2011/03/abstracting-your-orm-is-a-futile-exercise/" rel="nofollow noreferrer">pointed</a> <a href="https://stackoverflow.com/questions/5488313/organizationally-where-should-i-put-common-queries-when-using-entity-framework-c/5488947#5488947">by</a> <a href="https://stackoverflow.com/questions/5625746/generic-repository-with-ef-4-1-what-is-the-point">some</a> people, since EF 4.1 already implements repository and unit of work patterns through DbSet and DbContext, and I really would like to preserve all the features implemented by the EF Team without having to maintain them myself with a generic repository, as I already did in other project (and it was kind of painful).</p> <p>Working with an IContext will lead me to the same path (or won't it?).</p> <p>I thought about <strong>creating a FakeContext that inherits from main MyContext</strong> and thus take advantage of the DbContext underneath it to run my tests without hitting the database. I couldn't find similar implementations, so I'm hoping someone can help me on this.</p> <p><strong>Am I doing something wrong, or could this lead me to some problems that I'm not anticipating?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload