Tuesday, March 8, 2016

Unit Testing and Mocking with Entity Framework

One of the major problems with Unit Testing .NET applications in the past has been the inability to test data access layers that leverage Entity Framework.

Fortunately, though, Microsoft has now provided an article which describes how to do just that!

Mocking Entity Framework when Unit Testing ASP.NET Web API 2
http://www.asp.net/web-api/overview/testing-and-debugging/mocking-entity-framework-when-unit-testing-aspnet-web-api-2

This article describes how to implement an interface for Entity Framework that will then not only allow you to use Unit Testing and Mocking for your Entity Framework classes, but also leverage Dependency Injection!

All of this functionality comes with using the newer DbContext functionality that was made available since Entity Framework v. 4.1!

No comments:

Post a Comment