Solved

how to test TransactionScope

Posted on 2012-03-20
3
354 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Windows app updating JSON file error. 9 49
c#, datatable, aspx 4 50
Put File 6 36
C#:  Need to switch between timer loop and token driven loop 2 30
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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