BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in Biztalk Adapters

 
 
Page 1389 of 21350

Get Database rollback powers in your NUnit Tests!

Blogger : Geekswithblogs.net
All posts : All posts by Geekswithblogs.net
Category : Biztalk Adapters
Blogged date : 2008 Dec 18

Ok - no credit to me for any of this good stuff. All I'm doing here is posting on how to get database rollback working in your Nunit tests.

Roy Osherove created something called XtUnit - "An Unofficial Unit Testing Extensibility Framework - Add new attributes to NUnit or MbUnit easily" - http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx

His blog talks you through all the cool stuff that you can do with this framework, like implementing your own attributes to do cool things pre and post method execution. But the thing I wanted more than anything was to add rollback powers to existing NUNit tests, I didn't want to switch to MbUnit to do this, I just wanted to be able to do it with my existing tests.

It was pretty simple to get working, but the documentation is a tiny bit in-complete, so this is what you need to do.

I'm in Visual Studio 2008, using LLBLGenPro to talk to the database (obviously you don't need to use LLBLGen Pro, but why the hell not!)

  1. Download the binaries. You could download the source but you'll need to migrate it to 2008, and I didn't need the src.
  2. Reference the binary file that is downloaded in your test project.
  3. Make sure that your test fixture class derives from ExtensibleFixture
  4. Add the DataRollBack attribute to your test method

Done!

Here's the code for completion. My example as basically adding a row to a table called "GlobalSearch", in case the LLBLGen stuff looks confusing to you.

   1: [TestFixture]
   2: public class Class1 : ExtensibleFixture
   3: {
   4:     [Test, DataRollBack]
   5:     public void TestDataRollBack()
   6:     {
   7:         var adapter = new DataAccessAdapter("connection string here", false, CatalogNameUsage.ForceName, " ");
   8:         // Create a new GlobalSearchEntity, save it, then rollback
   9:         var g = new GlobalSearchQueueEntity();
  10:         g.RecordId = 100;
  11:         g.ToolCode = "TOOLCODE";
  12:         adapter.SaveEntity(g);
  13:     }
  14: }


Read comments or post a reply to : Get Database rollback powers in your NUnit Tests!
Page 1389 of 21350

Newest posts
 

    Email TopXML