Solved

how to test TransactionScope

Posted on 2012-03-20
3
335 Views
Last Modified: 2012-04-09
i have a wrapper class for TransactionScopes being used in multiple places, one of them is the root.  what is the best way to test my nested TransactionScopes actually work?  For example, i want to make sure that when my wrapper's Displose() is called, all TransactionScopes are now null.  also, what is the best way to find out which TransactionScope i am looking at, via System.Thread.Current?
0
Comment
Question by:mmingfeilam
  • 2
3 Comments
 
LVL 11

Expert Comment

by:b_levitt
Comment Utility
Can you describe why you need this (it might help me answer the question)?  TransactionScope already supports nesting so I'm trying to understand what you are doing to determine if the test you are looking for simply tests the functionality of TransactionScope.
0
 

Author Comment

by:mmingfeilam
Comment Utility
yes you are right, i am simply doing the unenviable, testing out someone else's code.  the wrapper class is to make sure all TransactionScope is using the ReadCommitted isolation level.
0
 
LVL 11

Accepted Solution

by:
b_levitt earned 500 total points
Comment Utility
You want to test the read commited isolation level vs other isolation levels?  Or you simply want to confirm that a transaction is properly being rolled back?

A basic test would be (basics like connecting to the db have been omited):
Int32 id;
using(TransactionScope transaction = new TransactionScope())
{
  
  id = MyBusinessClass.ExecuteMyMethod()
  
  //query db to check for new records:
  SqlCommand cmd = new SqlCommand("select 1 from mytable where id=" + id.ToString());
  //test should be 1 and not null
  Object test = cmd.ExecuteScalar()

  //don't complete so the transaction is rolled back
  //transaction.Complete()
}
//query db to check for new records:
SqlCommand cmd = new SqlCommand("select 1 from mytable where id=" + id.ToString());
//test should now be null since transaction has been rolled back.
Object test = cmd.ExecuteScalar()

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now