Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to test TransactionScope

Posted on 2012-03-20
3
Medium Priority
?
374 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
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

772 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