D
D
Dmitry2016-08-20 23:44:47
ASP.NET
Dmitry, 2016-08-20 23:44:47

How to test the DAL layer using unit tests?

Hello! Tell me how best to test the DAL layer, there is a DAL layer, and the DAL.Test project contains tests for it, the Entity Framework is added to the DAL layer, is it necessary to add the Entity Framework to the DAL.Test project, or DAL.Test should not know anything about Entity Framework and should only call methods from DAL? And if you do not add Entity, then how to test the repositories that are in the DAL

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2016-08-21
@Free_ze

You need to lock DbContext. To get rid of EF and its DbContext, you need to build an architecture in such a way as to completely hide the DbContext from the repository under its abstraction. This abstraction and wet. And test repositories on a fake data provider.

A
Alexander Ryzhov, 2016-08-29
@RyzhovAlexandr

For DAL testing, if it completely uses only EntityFramework methods for saving and accessing data, you can not use a real database, but use Effort . But for this you need to create a test DbContext that would use this library.
DAL.Test should refer to everything that is needed to create a real class under test (for example, a repository) and a fake DataContext that Effort would use internally.
If the repository uses ExecuteQuery to work with the database, then Effort will not work, you will have to use a real database - but you can already say integration tests. They have a plus - that they are closer to real scenarios, but a minus - they are more difficult to support.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question