How effective is Unit Test DAL that uses ADO.NET and SQL Server with NUnit?

So, you have a DAL in C # that uses the repository template, and you have an interface for each repository. It is supported by ADO.NET, MS SQL Server, and stored procedure calls.

This is great for cutting / mocking the repository, where it is used differently when performing unit tests, and I love it!

However, I would like to add some unit tests for the DAL itself. It is preferable to use Rhino Mocks with NUnit. However, I am open to moving on to MoQ if you can make a solid case so that he can do what Rhino cannot do with this issue.

I would prefer that he did not talk to any database during Unit tests in order to keep them more β€œclean”, while still effectively testing the DAL itself. If, however, you really cannot effectively unit test the DAL itself without talking to the database, what could be the alternatives that could be memory replacements or portable file replacements compatible with SQL Server, and the same SqlConnection and SqlCommand calls.

Open for refactoring DAL, if necessary, to make it easier for injection, if it does not complicate the design at the same time. Microsoft Unity for DI with repository template is already in use.

+5
source share
1 answer

? DAL - , (ADO.NET, EntityFramework, NHibernate).

ADO.NET , , NHibernate :

public User GetUser(int id)
{
    using (var session = sessionFactory.OpenSession())
    {
        return session.Get<User>(id);
    }
}

, , , (sessionFactory ) , unit test (, , ).

unit test, , , , ( Get). , , , , , ( sessionFactory, , ).

( ), . , , , ( , ).

, DAL , , (, ) unit test), .

, . :

  • , ( ORM, , , ).
  • ( : , , ).

​​ , ( DAL) ( ).

+7

All Articles