Click here to Skip to main content
15,896,915 members
Articles / Database Development / SQL Server / SQL Server 2008

Simple Data Access in C#

Rate me:
Please Sign up or sign in to vote.
4.11/5 (15 votes)
11 Jan 2009CPOL5 min read 83.9K   1.4K   58  
Fast and easy to use data access class library.
using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Yap.Data.Client;


namespace Yap.Data.UnitTest
{
	[TestClass]
	public class TransactionScopeTestFixture
	{
		[TestMethod]
		[ExpectedException(typeof(InvalidOperationException))]
		public void Constructor_ParentScopeIsNotSessionOrTransaction_ThrowInvalidOperationException()
		{
			new TransactionScope();
		}

		[TestMethod]
		public void Constructor__NameShouldBeSetAccordinglyToNestingLevel()
		{
			using (new SessionScope())
			{
				using (var t0 = new TransactionScope())
				{
					Assert.AreEqual("T0", t0.Name);
					using (var t00 = new TransactionScope())
					{
						Assert.AreEqual("T0-0", t00.Name);
						using (var t000 = new TransactionScope())
						{
							Assert.AreEqual("T0-0-0", t000.Name);
							t000.Rollback();
						}
						using (var t001 = new TransactionScope())
						{
							Assert.AreEqual("T0-0-1", t001.Name);
							t001.Rollback();
						}
						t00.Rollback();
					}
					using (var t01 = new TransactionScope())
					{
						Assert.AreEqual("T0-1", t01.Name);
						using (var t010 = new TransactionScope())
						{
							Assert.AreEqual("T0-1-0", t010.Name);
						}
						using (var t011 = new TransactionScope())
						{
							Assert.AreEqual("T0-1-1", t011.Name);
						}
					}
					t0.Rollback();
				}
				using (var t0 = new TransactionScope())
				{
					Assert.AreEqual("T0", t0.Name);
				}
			}
		}

		[TestMethod]
		public void get_Session__ReturnParentSession()
		{
			using (var session = new SessionScope())
			{
				using (var t0 = new TransactionScope())
				{
					Assert.AreSame(session, t0.Session);
					using (var t00 = new TransactionScope())
					{
						Assert.AreSame(session, t00.Session);
					}
					using (var t01 = new TransactionScope())
					{
						Assert.AreSame(session, t01.Session);
					}
				}
				using (var t0 = new TransactionScope())
				{
					Assert.AreSame(session, t0.Session);
				}
			}
		}
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


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

Comments and Discussions