.net - Is it good practice to use Entity Framework in unit tests? -


i'm writing nunit tests service.

i've decided sending direct sql statements database instead of using entity framework model certain of results, i.e. testing in database , not entity framework tells me in database (e.g. reporting cached result, etc.)

the drawback is getting tedious write code using sqlcommand, sqldatareader, etc. , being able use ef model easier.

how others doing this? practice use entity framework when writing tests or should direct calls database used ensure accurate results?

i bad practice when testing service cause creates dependency on database.

what did, roll model classes repository pattern. repository pattern coded interface change implementation of database querying without effecting other parts of code. mocked , used testing. interface constructed.

using system; using system.collections; using system.collections.generic; using system.linq;  namespace app.core.repositories {     public interface irepository<tkey, tmodel>         tkey : icomparable         tmodel : class     {         tmodel only(tkey key);         iqueryable<tmodel> where(func<tmodel, bool> query);          tmodel single(func<tmodel, bool> query);         tmodel first(func<tmodel, bool> query);         iqueryable<tmodel> all();          void insert(tmodel entity);         void insert(ienumerable<tmodel> entities);          void update(tmodel entity);         void update(ienumerable<tmodel> entities);          void remove(tmodel entities);         void remove(func<tmodel, bool> query);         void remove(ienumerable<tmodel> entities);     }      public interface irepository<tmodel> : irepository<int, tmodel> tmodel : class { }      public interface irepository : irepository<int, object> { } } 

Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -