[Adapdev-commits] Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests Adapdev.UnitTest.Core.AdapdevTests.
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 07:02:02
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core.AdapdevTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.UnitTest.Core.AdapdevTests Added Files: Adapdev.UnitTest.Core.AdapdevTests.csproj AdapdevAttributes.cs AssemblyInfo.cs MultiThreadedRepeatTest.cs MultiThreadedTest.cs RollbackTransactionTest.cs SomeTest.cs TransactionTest.cs Log Message: --- NEW FILE: AdapdevAttributes.cs --- using System; using System.Threading; using Adapdev.UnitTest; namespace Adapdev.UnitTest.Core.AdapdevTests { [TestFixture] public class AdapdevAttributes { // Runs only once, when the test assembly is dynamically loaded public AdapdevAttributes(){} // Runs once at the beginning of each TestFixture iteration [TestFixtureSetUp] public void TestFixtureSetUp() { Console.WriteLine("TestFixtureSetUp"); } // Runs once at the beginning of each Test iteration [TestSetUp] public void TestSetUp() { Console.WriteLine("TestSetUp"); } // Runs once at the beginning of each Test iteration [SetUp] public void SetUp() { Console.WriteLine("SetUp"); } // Runs once at the beginning of SimpleTest only [TestSetUp("SimpleTest")] public void SpecificTestSetUp() { Console.WriteLine("SpecificTestSetUp runs only for SimpleTest"); } // A Test [Test(Description="Basic test")] public void SimpleTest() { Console.WriteLine("SimpleTest"); } // Runs once at the end of SimpleTest only [TestTearDown("SimpleTest")] public void SpecificTestTearDown() { Console.WriteLine("SpecificTestTearDown runs only for SimpleTest"); } // A Test with a Category [Test(Category="Some Category", Description="Demonstrates a Test that's assigned to a category")] public void TestWithCategory() { Console.WriteLine("Test with category"); } // A Test with a Description [Test(Description="Demonstrates a Test that has a description")] public void TestWithDescription() { Console.WriteLine("Test with description"); Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); } // A Test that is expecting a specific Exception // type to be thrown or any child class [Test(Description="A Test that expects an Exception to be thrown.")] [ExpectedException(typeof(Exception))] public void ExpectedException() { Console.WriteLine("ExpectedException"); throw new Exception("This Exception is expected"); } // A Test that is expecting a specific Exception // type to be thrown with a specific message [Test(Description="A Test that expects an Exception to be thrown with a specific message.")] [ExpectedException(typeof(Exception), "This Exception is expected")] public void ExpectedExceptionWithMessage() { Console.WriteLine("ExpectedException"); throw new Exception("This Exception is expected"); } // A Test that is expecting a specific Exception // type to be thrown with a specific message and fails [Test(Description="A Test that expects an Exception to be thrown with a specific message and receives the wrong one.")] [ExpectedException(typeof(Exception), "This Exception is expected")] public void FailExpectedExceptionWithMessage() { Console.WriteLine("ExpectedException"); throw new Exception("This Exception is not expected"); } // A Test that is expecting a specific DivideByZeroException // type to be thrown or any child class [Test] [ExpectedException(typeof(Exception))] public void ExpectedDivideByZeroException() { Console.WriteLine("ExpectedException"); throw new DivideByZeroException("This Exception is expected."); } // A Test that will fail because the ExpectedException is not thrown [Test(Description="A Test that expects an Exception to be thrown, but fails because one isn't.")] [ExpectedException(typeof(Exception))] public void FailExpectedException() { Console.WriteLine("ExpectedException"); } // A Test that will be ignored (not run) by default [Test(Description="A Test that is ignored, with no reason provided.")] [Ignore] public void Ignore() { Console.WriteLine("Ignore"); } // A Test that will be ignored (not run) by default // and provides a reason [Test(Description="A Test that is ignored, with a reason provided.")] [Ignore("Some reason")] public void IgnoreWithReason() { Console.WriteLine("Ignore with reason"); } // A Test that specifies the maximum amount of memory // that the Test can consume [Test(Description="A Test who's total memory consumption should not exceed 200K")] [MaxKMemory(200)] public void MaxKMemory() { Console.WriteLine("MaxKMemory"); } // A Test that will fail if it can't be repeated // the min number of times in a second [Test(Description="A Test that should be able to run at least 10X per second.")] [MinOperationsPerSecond(10)] public void MinOperationsPerSecond() { Console.WriteLine("MinOperationsPerSecond"); } // A Test that is repeated a set number of times [Test(Description="A Test that is repeated 5X")] [Repeat(5)] public void Repeat() { Console.WriteLine("Repeat"); Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); } // A Test that is repeated a set number of times // with a 3 second delay in between [Test(Description="A Test that is repeated 5X, with a 3 second delay between each run.")] [Ignore] [Repeat(5,3000)] public void RepeatWithDelay() { Console.WriteLine("Repeat with delay"); Console.WriteLine("Thread: " + AppDomain.GetCurrentThreadId()); } // Runs once at the end of each Test iteration [TearDown] public void TearDown() { Console.WriteLine("TearDown"); } // Runs once at the end of each Test iteration [TestTearDown] public void TestTearDown() { Console.WriteLine("TestTearDown"); } // Runs once at the end of the TestFixture iteration [TestFixtureTearDown] public void TestFixtureTearDown() { Console.WriteLine("TestFixtureTearDown"); } } } --- NEW FILE: RollbackTransactionTest.cs --- using System; using System.EnterpriseServices; namespace Adapdev.UnitTest.Core.AdapdevTests { /// <summary> /// Summary description for RollbackTransactionTest. /// </summary> /// // [TestFixture] public class RollbackTransactionTest { [Test] // [RollbackTransaction] public void Transaction() { // Assert.IsTrue(ContextUtil.IsInTransaction, "Should be in a transaction."); Console.WriteLine("TransactionId: " + ContextUtil.TransactionId); } [Test] public void NoTransaction() { Assert.IsFalse(ContextUtil.IsInTransaction); } } } --- NEW FILE: TransactionTest.cs --- using System; using System.EnterpriseServices; using Adapdev.UnitTest; namespace Adapdev.UnitTest.Core.AdapdevTests { /// <summary> /// Summary description for AutoCommitTest. /// </summary> /// [TestFixture] public class TransactionTest { [Test] [Transaction] public void Transaction() { Assert.IsTrue(ContextUtil.IsInTransaction, "Should be in a transaction."); Console.WriteLine("TransactionId: " + ContextUtil.TransactionId); } [Test] public void NoTransaction() { Assert.IsFalse(ContextUtil.IsInTransaction); } } } --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; using System.Runtime.CompilerServices; // // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. // [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")] // // In order to sign your assembly you must specify a key to use. Refer to the // Microsoft .NET Framework documentation for more information on assembly signing. // // Use the attributes below to control which key is used for signing. // // Notes: // (*) If no key is specified, the assembly is not signed. // (*) KeyName refers to a key that has been installed in the Crypto Service // Provider (CSP) on your machine. KeyFile refers to a file which contains // a key. // (*) If the KeyFile and the KeyName values are both specified, the // following processing occurs: // (1) If the KeyName can be found in the CSP, that key is used. // (2) If the KeyName does not exist and the KeyFile does exist, the key // in the KeyFile is installed into the CSP and used. // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the project output directory which is // %Project Directory%\obj\<configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework // documentation for more information on this. // [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] --- NEW FILE: Adapdev.UnitTest.Core.AdapdevTests.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{3085922A-8F7B-4C5F-8C31-41BD7CCC0D05}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Adapdev.UnitTest.Core.AdapdevTests" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Adapdev.UnitTest.Core.AdapdevTests" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "Adapdev.UnitTest" Project = "{D450E7B3-CF48-421E-8B5E-9526E77E24C6}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> </References> </Build> <Files> <Include> <File RelPath = "AdapdevAttributes.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MultiThreadedRepeatTest.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MultiThreadedTest.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: MultiThreadedRepeatTest.cs --- using System; using System.Threading; using Adapdev.UnitTest; namespace Adapdev.UnitTest.Core.AdapdevTests { /// <summary> /// Summary description for MultiThreadedTest. /// </summary> /// [TestFixture(IsMultiThreaded=true)] public class MultiThreadedRepeatTest { int i = 0; [Test, Repeat(5)] public void ThreadedRepeat() { i = 0; int a = 0; while(a <= 10) { i += 1; Thread.Sleep(5); a++; Console.WriteLine("Thread {0}: {1}", AppDomain.GetCurrentThreadId(), i); } Assert.IsFalse(i==10, "i equals 10, which means it was not interrupted by other Threads."); } } } --- NEW FILE: SomeTest.cs --- using System; namespace Adapdev.UnitTest.Core.AdapdevTests { /// <summary> /// Summary description for SomeTest. /// </summary> /// [TestFixture] public class SomeTest { [Test] public void TestA(){} [Test] public void TestB(){} [Test] public void TestC(){} } } --- NEW FILE: MultiThreadedTest.cs --- using System; using System.Threading; using Adapdev.UnitTest; namespace Adapdev.UnitTest.Core.AdapdevTests { /// <summary> /// Summary description for MultiThreadedTest. /// </summary> /// [TestFixture(IsMultiThreaded=true)] public class MultiThreadedTest { int i = 0; [Test] public void Thread1() { i = 0; int a = 0; while(a <= 10) { i += 4; Console.WriteLine("Thread1: " + i.ToString()); Thread.Sleep(5); a++; } Console.WriteLine("Thread1: " + i.ToString()); Assert.IsFalse(i==44, "i equals 44, which means it was not interrupted by Thread2."); } [Test] public void Thread2() { i = 0; int a = 0; while(a <= 10) { i += 10; Console.WriteLine("Thread2: " + i.ToString()); Thread.Sleep(5); a++; } Console.WriteLine("Thread2: " + i.ToString()); Assert.IsFalse(i==110, "i equals 110, which means it was not interrupted by Thread1."); } } } |