Click here to Skip to main content
15,886,422 members
Articles / Programming Languages / C#

Some Useful Concurrency Classes and A Small Testbench

Rate me:
Please Sign up or sign in to vote.
4.92/5 (37 votes)
15 Jan 2007CPOL70 min read 102.8K   1K   140  
Useful concurrency classes and small test bench in C#
///<file>
///</file>
//#define NUNIT_IN_USE

using System;
// You will need this if you use the "ConditionalAttribute" attribute.
//using System.Diagnostics;

// Right now we are configured to use NUnit. Version 2.2 does most of the
// things we need.
//using NUnit.Framework;

using MPFramework.AppCore.PlatformUtilities;

namespace MPFramework.AppCore.QualityAssurance
{
	/// <summary>
	/// <para>
	/// This class contains basic utilities and templates that we use for
	/// Quality Assurance (QA) tests. The current preferred platform is Nunit.
	/// We are not using our own testing mechanism anymore, but we still tend to
	/// maintain the old QATester structure and that is illustrated here.
	/// </para>
	/// <para>
	/// The class demonstrates how we partition tests according to "level" and
	/// "letter" and also explains our philosophy for the variegation.
	/// </para>
	/// </summary>
	/// <remarks>
	/// The bulk of this has been moved to the QATester_QAUtils_0, QATester_QAUtils_1,
	/// and QATester_QAUtils_2 demo classes so that we can demo the QA tests under
	/// Nunit (or whatever we are using). Please see those demo classes which have been
	/// moved to the testing assembly.
	/// </remarks>
	public class QAUtils
	{
		#region Class Fields
		// This is a set of strings that represent different categories of tests. Const
		// because we need it at compile time. Now is textual, since that is what
		// NUnit wants...... The basic idea is that tests need to be turned on or
		// off based on a "level". Level 0 tests are simple and run fast, level 1
		// are a bit more time-consuming and take a little longer, etc.
		/// <summary>
		/// Use this string for test level 0.
		/// </summary>
		public const System.String TestLevel0Name = "Test Level 0";
		/// <summary>
		/// Use this string for test level 1.
		/// </summary>
		public const System.String TestLevel1Name = "Test Level 1";
		/// <summary>
		/// Use this string for test level 2.
		/// </summary>
		public const System.String TestLevel2Name = "Test Level 2";
		/// <summary>
		/// Use this string for test level 3.
		/// </summary>
		public const System.String TestLevel3Name = "Test Level 3";
		/// <summary>
		/// Use this string for test level 4.
		/// </summary>
		public const System.String TestLevel4Name = "Test Level 4";
		/// <summary>
		/// Use this string for test level 5.
		/// </summary>
		public const System.String TestLevel5Name = "Test Level 5";
		/// <summary>
		/// Use this string for test level 6.
		/// </summary>
		public const System.String TestLevel6Name = "Test Level 6";
		/// <summary>
		/// Use this string for test level 7.
		/// </summary>
		public const System.String TestLevel7Name = "Test Level 7";
		/// <summary>
		/// Use this string for test level 8.
		/// </summary>
		public const System.String TestLevel8Name = "Test Level 8";
		/// <summary>
		/// Use this string for test level 9.
		/// </summary>
		public const System.String TestLevel9Name = "Test Level 9";
		#endregion
	}
}
//// The following may be defined as a compiler constant or in code.
#if !NUNIT_IN_USE
#region NUnitFramework Stub
namespace NUnit.Framework
{
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
	public sealed class TestFixtureAttribute : Attribute
	{
		private string description;

		/// <summary>
		/// Descriptive text for this fixture
		/// </summary>
		public string Description
		{
			get { return description; }
			set { description = value; }
		}
	}
	[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
	public class TestFixtureSetUpAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
	public class TestFixtureTearDownAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
	public sealed class TestAttribute : Attribute
	{
		private string description;

		/// <summary>
		/// Descriptive text for this test
		/// </summary>
		public string Description
		{
			get { return description; }
			set { description = value; }
		}
	}

	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
	public sealed class CategoryAttribute : Attribute
	{
		private string name;

		/// <summary>
		/// Construct attribute for a given category
		/// </summary>
		/// <param name="name">The name of the category</param>
		public CategoryAttribute(string name)
		{
			this.name = name;
		}

		/// <summary>
		/// The name of the category
		/// </summary>
		public string Name
		{
			get { return name; }
		}
	}
	/// <summary>
	/// Stub for Assert. Just a few replacements for the ones we use.
	/// </summary>
	public class Assert
	{
		static public void IsTrue(bool condition, string message)
		{
			if(!condition)
				throw new ApplicationException("message");
		}
		static public void IsFalse(bool condition, string message)
		{
			if(condition)
				throw new ApplicationException("message");
		}
		static public void AreEqual(int condition1, int condition2, string message)
		{
			if(condition1 != condition2)
				throw new ApplicationException("message");
		}
		static public void AreNotEqual(bool condition1, bool condition2, string message)
		{
			if(condition1 == condition2)
				throw new ApplicationException("message");
		}
		static public void Fail(string message)
		{
			throw new ApplicationException("message");
		}
	}
}
#endregion // NUnitFramework Stub
#endif

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
Web Developer
United States United States
Kurt R. Matis received the B.S degree in Applied Mathemetics from Empire State College in 1981 and the PhD. degree in Electrical Engineering from Rensselaer Polytechnic Institute in 1984. He has been involved in several companies over the past 30 years, but has been most recently involved with the Macher-Plander Software Engineering Consortium, of which he is a co-founder. The Consortium is involved with education in .Net technologies and Software Quality Management topics.

Dr. Matis is a member of IEEE and the American Historical Truck Society. Kurt lives happily in Troy, NY with his beautiful wife, two beautiful daughters and his beautiful trucks.

Dr. Matis is interested in working with companies who wish assistance in porting legacy applications of all types to .Net. He can be reached at krogerma@aol.com.




Comments and Discussions