Click here to Skip to main content
15,894,630 members
Articles / Programming Languages / C#

Data Access and Transaction Handling Framework

Rate me:
Please Sign up or sign in to vote.
4.69/5 (107 votes)
13 Jan 200510 min read 927.7K   2.1K   282  
Generic data access component for different datasources, sprocs/SQL, implicitly propagated transactions, explicitly managed transaction contexts etc.
using System;
using System.Threading;
using System.Diagnostics;
using NUnit.Framework;
using Framework.DataAccess;

namespace Framework.UnitTests
{
	/// <summary>
	/// Summary description for ThreadTests.
	/// </summary>
	[TestFixture]
	public class ThreadTests
	{
		private static int _numberOfThreads = 10;

		public ThreadTests() {}

		[Test]
		public void MultipleGetDefaultDataSource() 
		{
			Thread[] threads = new Thread[_numberOfThreads];

			FactoryTests tt = new FactoryTests();

			for (int i = 0; i < _numberOfThreads; i++) 
			{
				Thread t = new Thread(new ThreadStart(tt.GetDefaultDataSource));
				threads[i] = t;
				Debug.WriteLine("new thread:" + t.GetHashCode());
			}
			for (int i = 0; i < _numberOfThreads; i++) 
			{
				threads[i].Start();
			}
		}

		[Test]
		public void MultipleExecuteNonQuery() 
		{
			Thread[] threads = new Thread[_numberOfThreads];

			CommandTests tt = new CommandTests();

			for (int i = 0; i < _numberOfThreads; i++) 
			{
				Thread t = new Thread(new ThreadStart(tt.ExecuteNonQuery));
				threads[i] = t;
				Debug.WriteLine("new thread:" + t.GetHashCode());
			}
			for (int i = 0; i < _numberOfThreads; i++) 
			{
				threads[i].Start();
			}
		}

		[Test]
		public void MultipleRetrieveTestCommand1() 
		{
			Thread[] threads = new Thread[_numberOfThreads];

			CommandTests tt = new CommandTests();

			for (int i = 0; i < _numberOfThreads; i++) 
			{
				Thread t = new Thread(new ThreadStart(tt.RetrieveTestCommand1));
				threads[i] = t;
				Debug.WriteLine("new thread:" + t.GetHashCode());
			}
			for (int i = 0; i < _numberOfThreads; i++) 
			{
				threads[i].Start();
			}
		}

		[Test]
		public void MultipleExecuteReader() 
		{
			Thread[] threads = new Thread[_numberOfThreads];

			CommandTests tt = new CommandTests();

			for (int i = 0; i < _numberOfThreads; i++) 
			{
				Thread t = new Thread(new ThreadStart(tt.ExecuteReader));
				threads[i] = t;
				Debug.WriteLine("new thread:" + t.GetHashCode());
			}
			for (int i = 0; i < _numberOfThreads; i++) 
			{
				threads[i].Start();
			}
		}

		[Test]
		public void MultipleTransactionContexts() 
		{
			Thread[] threads = new Thread[_numberOfThreads];

			TransactionContextTests tct = new TransactionContextTests();

			for (int i = 0; i < _numberOfThreads; i++) 
			{
				Thread t = new Thread(new ThreadStart(tct.TestNestedContexts1));
				threads[i] = t;
				Debug.WriteLine("new thread:" + t.GetHashCode());
			}
			for (int i = 0; i < _numberOfThreads; i++) 
			{
				threads[i].Start();
			}
		}

		[Test]
		public void MultipleTransactionContextsWithDataAccess() 
		{
			Thread[] threads = new Thread[_numberOfThreads];

			TransactionContextTests tct = new TransactionContextTests();

			for (int i = 0; i < _numberOfThreads; i++) 
			{
				Thread t = new Thread(new ThreadStart(tct.TestNestedContextWithDataAccess1));
				threads[i] = t;
				Debug.WriteLine("new thread:" + t.GetHashCode());
			}
			for (int i = 0; i < _numberOfThreads; i++) 
			{
				threads[i].Start();
			}
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions