Solved

how to test TransactionScope

Posted on 2012-03-20
3
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:b_levitt
ID: 37752861
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
ID: 37779812
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
ID: 37783550
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

623 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