Mocking Database call Asp.net MVC application

How can I mock database calls so that my application logic is tested without a database?

+4
source share
4 answers

Use the repository template and make fun of it in your tests with a mocking structure like MoQ .

Edit: check out this article by Stephen Walter in MoQ.

+2
source

A repository pattern with a hard-coded implementation or using an XML file (my preference).

+1
source
procedure GetData (output arrayOfData) arrayOfData.record1.field1 = "dataA" arrayOfData.record1.field2 = "dataAB" arrayOfData.record2.field1 = "dataB" arrayOfData.record2.field2 = "dataBB" return arrayOfData) end procedure 

Then call GetData and in any case use this piece of data that you need for your logic. Modify GetData later to really get data from the database. Right now, just fake it and assign reasonable data to it manually.

0
source

Hope this article helps Stephen Walter.

This article reads to the reader through the process of using mocks for unit testing. This is a detailed article and pretty good.

It also has an example repository template highlighted by some community members.

Cheating with Rhino Mocks (ASP.NET MVC)

0
source

All Articles