Danieoli
Danieoli

Reputation: 25

linq unit tests

If I have a method like this:

public void methodName(value 1, value 2)
{
    var query = this.table
    join that.table on this.table.column equals that.table.column
    where column equals column
}

For a test method, would I just insert test values into whichever tables, instantiate an object, call the method, and pass two vars that are equal to whatever test values I inserted into the db? Any help is appreciated.

Upvotes: 1

Views: 1257

Answers (1)

Vojtěch Dohnal
Vojtěch Dohnal

Reputation: 8104

Assuming that the application is using Entity framework, you should use testing tools appropriate for the ORM the application is using.

With Entitiy framework you can use Mocking Framework.

When writing tests for your application it is often desirable to avoid hitting the database. Entity Framework allows you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.

By using in-memory mocked data for testing you skip testing your database and your tests will not reveal possible problems with database access.

Upvotes: 1

Related Questions