Wednesday, May 12, 2010

Testing Subsonic based projects

Testing Subsonic based projects is a breeze. No mock frameworks needed. All you have to do is add an app.config file and some mock objects righ into Subsonic. Have a look at the following:

In the App.config file of my test project:

<add name="VisenoConnection" connectionstring="Test">

My Setup method:
public void StartTest()
List companies = new List();
for (int i = 0; i < 100; i++)
VisenoCompany company = new VisenoCompany();
company.Id = i;
company.Name = "webtop";
company.Address = "address";

companies[1].CompanyKey = "123";


My test method:
public void TestGetCompany()
CompanyRepository companyRepository = new CompanyRepository();
VisenoCompany company = companyRepository.Get(1);
Assert.That(company.Id == 1);
Assert.That(company.CompanyKey == "123");
Assert.That(company.Name == "webtop");

Subsonic now uses memory in stead of database. In this case the repositories and generated classes are even in a different project.