Tuesday, January 13, 2009

Reset Database after Unit Tests are run

I was doing RnD using VSTS 2008 for Unit tests. One of the issue I faced was the data used to get changed after my tests were passed. This scenario created one more need for me to find a method to rollback what ever changes my Unit tests used to make to my database.

I tried out MdbUnit, NUnit but I was still searching for something which is provided by Microsoft itself. Reading to few blogs I successfully made it work.

public void Initialize()
ServiceConfig config = new ServiceConfig();
config.Transaction = TransactionOption.RequiresNew;

public void Cleanup()
if (ContextUtil.IsInTransaction)

After I wrote this in my Test.cs file I faced another error
system.Data.Entity Exception: The underlying provider failed on Open. ---> System.Transactions.TransactionManagerCommunicationException: Network access for Distributed Transaction Manager (MSDTC) has been disabled.

The following link helped me


Wallah my Unit test problem is solved!

No comments: