How are people unit testing with Entity Framework 6, should you bother?

前端 未结 11 1991

I am just starting out with Unit testings and TDD in general. I have dabbled before but now I am determined to add it to my workflow and write better software.

I ask

11条回答
  •  情话喂你
    2020-11-28 17:43

    There is Effort which is an in memory entity framework database provider. I've not actually tried it... Haa just spotted this was mentioned in the question!

    Alternatively you could switch to EntityFrameworkCore which has an in memory database provider built-in.

    https://blog.goyello.com/2016/07/14/save-time-mocking-use-your-real-entity-framework-dbcontext-in-unit-tests/

    https://github.com/tamasflamich/effort

    I used a factory to get a context, so i can create the context close to its use. This seems to work locally in visual studio but not on my TeamCity build server, not sure why yet.

    return new MyContext(@"Server=(localdb)\mssqllocaldb;Database=EFProviders.InMemory;Trusted_Connection=True;");
    

提交回复
热议问题