[Adapdev-commits] Adapdev/src/Adapdev.UnitTest Adapdev.UnitTest.csproj,1.7,1.8 Assert.cs,1.3,1.4 Ass
Status: Beta
Brought to you by:
intesar66
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.UnitTest Added Files: Adapdev.UnitTest.csproj Assert.cs Assertion.cs AssertionException.cs AssertionFailureMessage.cs ExpectedExceptionAttribute.cs IgnoreAttribute.cs IgnoreException.cs MaxKMemoryAttribute.cs MinOperationsPerSecondAttribute.cs RepeatAttribute.cs RollbackTransaction.cs RollbackTransactionAttribute.cs SetUpAttribute.cs TearDownAttribute.cs TestAttribute.cs TestContext.cs TestFixtureAttribute.cs TestFixtureSetUpAttribute.cs TestFixtureTearDownAttribute.cs TestSetUpAttribute.cs TestTearDownAttribute.cs TestType.cs Transaction.cs TransactionAttribute.cs Log Message: --- NEW FILE: RollbackTransactionAttribute.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for RollbackTransaction. /// </summary> /// [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class RollbackTransactionAttribute : Attribute { } } --- NEW FILE: TestContext.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for TestContext. /// </summary> public class TestContext { public TestContext() { // // TODO: Add constructor logic here // } } } --- NEW FILE: TransactionAttribute.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for Transaction. /// </summary> /// [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class TransactionAttribute : Attribute { } } --- NEW FILE: RollbackTransaction.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for RollbackTransaction. /// </summary> /// [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class RollbackTransaction : Attribute { } } --- NEW FILE: TestSetUpAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies a place for code that should be run prior to a Test /// /// Unless a Test name is specified, this will run prior to each Test. /// </summary> /// <example> /// [TestSetUp] /// public void SetUp(){ /// // this will run for each test /// } /// /// [TestSetUp(Test="SomeTest")] /// public void SetUpForSomeTest(){ /// // this will run only for SomeTest /// } /// /// [Test] /// public void SomeTest(){ /// // code /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class TestSetUpAttribute : Attribute { private string _test = ""; /// <summary> /// Constructor /// </summary> public TestSetUpAttribute() : base() { } /// <summary> /// Constructor /// </summary> /// <param name="test">The name of the Test that this should run for.</param> public TestSetUpAttribute(string test) { this._test = test; } public string Test { get { return this._test; } set { this._test = value; } } } } --- NEW FILE: IgnoreException.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: TestAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// A Test that will be run. The result is either a Pass or Fail, unless /// the Test is being Ignored /// </summary> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class TestAttribute : Attribute { private string _category = ""; private string _description = ""; private TestType _testType = TestType.Unit; /// <summary> /// A category that the Test will be associated with /// </summary> public string Category { get { return this._category; } set { this._category = value; } } /// <summary> /// Gets or sets the description. /// </summary> /// <value></value> public string Description { get{ return this._description;} set{ this._description = value;} } /// <summary> /// Gets or sets the test type /// </summary> public TestType TestType { get{return this._testType;} set{this._testType = value;} } } } --- NEW FILE: IgnoreAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Signifies that this Test should be ignored. /// /// The Zanebug engine will ignore this Test by default each time the /// engine starts up, but it can be overriden at run-time /// </summary> /// <example> /// [Test] /// [Ignore] /// public void Ignore(){ /// // this Test will be ignored /// } /// /// [Test] /// [Ignore] /// public void IgnoreWithReason(){ /// // this Test will be ignored and provides a reason why /// } /// </example> [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple=false, Inherited=true)] public sealed class IgnoreAttribute : Attribute { private string reason = ""; /// <summary> /// Constructor /// </summary> public IgnoreAttribute() { } /// <summary> /// Constructor /// </summary> /// <param name="reason">The reason the Test is being ignored</param> public IgnoreAttribute(string reason) { this.reason = reason; } /// <summary> /// The reason the Test is being ignored /// </summary> public string Reason { get { return reason; } } } } --- NEW FILE: TestFixtureAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies a TestFixture, which is a designation for a class that contains /// one or more Tests. /// /// If a class contains Tests, but is not marked with the TestFixture attribute then /// the class will be ignored by the test engine. /// </summary> /// <example> /// using System; /// using Adapdev.UnitTest; /// /// namespace Tests /// { /// [TestFixture] /// public class SomeTest /// { /// [Test] /// public void Test1(){...} /// /// [Test] /// public void Test2(){...} /// } /// } /// </example> [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)] public sealed class TestFixtureAttribute : Attribute { private bool _multiThreaded = false; public bool IsMultiThreaded { get { return _multiThreaded; } set { _multiThreaded = value; } } } } --- NEW FILE: SetUpAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies a place for code that should be run prior to a Test /// /// Unless a Test name is specified, this will run prior to each Test. /// </summary> /// <remarks> /// This is a deprecated attribute that was created for backwards compatability with NUnit. /// New tests should use TestTearDown, since the name better communicates the scope. /// </remarks> /// <example> /// [SetUp] /// public void SetUp(){ /// // this will run for each test /// } /// /// [SetUp(Test="SomeTest")] /// public void SetUpForSomeTest(){ /// // this will run only for SomeTest /// } /// /// [Test] /// public void SomeTest(){ /// // code /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class SetUpAttribute : TestSetUpAttribute { } } --- NEW FILE: Assertion.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Adapdev.UnitTest.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{D450E7B3-CF48-421E-8B5E-9526E77E24C6}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Adapdev.UnitTest" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Adapdev.UnitTest" 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 = "log4net" AssemblyName = "log4net" HintPath = "..\..\lib\log4net.dll" /> </References> </Build> <Files> <Include> <File RelPath = "AdapdevAssemblyInfo.cs" Link = "..\AdapdevAssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Assert.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Assertion.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AssertionException.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "AssertionFailureMessage.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ExpectedExceptionAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "IgnoreAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "IgnoreException.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MaxKMemoryAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MinOperationsPerSecondAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "RepeatAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "RollbackTransaction.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SetUpAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TearDownAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestContext.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestFixtureAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestFixtureSetUpAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestFixtureTearDownAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestSetUpAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestTearDownAttribute.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "TestType.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Transaction.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: MaxKMemoryAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies the maximum amount of memory that a Test can use. /// /// If the memory used by the tests exceeds this value, then the Test /// will fail. /// </summary> /// <remarks> /// The Zanebug memory measurement feature is currently buggy, and /// should not be relied upon for accurate measurements /// </remarks> /// <example> /// [Test] /// [MaxKMemory(200)] /// public void MaxKMemory() /// { /// // this test will fail if the memory usage /// // exceeds 200kb /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class MaxKMemoryAttribute : Attribute { private int maxK; /// <summary> /// The maximum amount of memory that should be used (in kb) /// </summary> public int MaxK { get { return maxK; } } /// <summary> /// Constructor /// </summary> /// <param name="n">The maximum amount of memory that should be used (in kb)</param> public MaxKMemoryAttribute(int n) { maxK = n; } } } --- NEW FILE: RepeatAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies how many times a Test or TestFixture should be repeated /// </summary> /// <example> /// [Test] /// [Repeat(5)] /// public void Repeat(){ /// // this test will be run 5 times in a row /// } /// /// [Test] /// [Repeat(5,3000)] /// public void Repeat(){ /// // this test will be run 5 times in a row /// // with a 3 second delay between each run /// } /// </example> [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple=false, Inherited=true)] public sealed class RepeatAttribute : Attribute { private int repCount = 1; private int delayBetweenReps = 0; //ms /// <summary> /// The number of times the Test or TestFixture should be repeated /// </summary> public int RepeatCount { get { return repCount; } } /// <summary> /// The number of milliseconds that the engine should wait /// before repeating the Test /// </summary> public int RepeatDelay { get { return delayBetweenReps; } } /// <summary> /// Constructor /// </summary> /// <param name="count">The number of times the Test or TestFixture should be repeated</param> public RepeatAttribute(int count) { repCount = count; delayBetweenReps = 0; } /// <summary> /// Constructor /// </summary> /// <param name="count">The number of times the Test or TestFixture should be repeated</param> /// <param name="delay">The number of milliseconds that the engine should wait /// before repeating the Test</param> public RepeatAttribute(int count, int delay) { repCount = count; delayBetweenReps = delay; } } } --- NEW FILE: MinOperationsPerSecondAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies the minimum number of times a Test should be able /// to run within 1 second. /// </summary> /// <remarks> /// The MinOps/s value is derived by dividing 1 by the Test duration: /// /// 1/(test duration) = MinOps/s /// </remarks> /// <example> /// [Test] /// [MinOperationsPerSecond(10)] /// public void MinOpsPerSecond(){ /// // this test will fail if it can't be run /// // 10 times in 1 second /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class MinOperationsPerSecondAttribute : Attribute { private int minOpsPerSecond; /// <summary> /// The minimum number of times a Test should run /// within a second /// </summary> public int MinOps { get { return minOpsPerSecond; } } /// <summary> /// Constructor /// </summary> /// <param name="n"> /// The minimum number of times a Test should run /// within a second /// </param> public MinOperationsPerSecondAttribute(int n) { minOpsPerSecond = n; } } } --- NEW FILE: Transaction.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for Transaction. /// </summary> /// [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class Transaction : Attribute { } } --- NEW FILE: AssertionFailureMessage.cs --- #region Original Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig, Douglas de la Torre /************************************************************************************ ' ' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole ' Copyright 2000-2002 Philip A. Craig ' Copyright 2001 Douglas de la Torre ' ' This software is provided 'as-is', without any express or implied warranty. In no ' event will the authors be held liable for any damages arising from the use of this ' software. ' ' Permission is granted to anyone to use this software for any purpose, including ' commercial applications, and to alter it and redistribute it freely, subject to the ' following restrictions: ' ' 1. The origin of this software must not be misrepresented; you must not claim that ' you wrote the original software. If you use this software in a product, an ' acknowledgment (see the following) in the product documentation is required. ' ' Portions Copyright 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov ' Copyright 2000-2002 Philip A. Craig, or Copyright 2001 Douglas de la Torre ' ' 2. Altered source versions must be plainly marked as such, and must not be ' misrepresented as being the original software. ' ' 3. This notice may not be removed or altered from any source distribution. ' '***********************************************************************************/ #endregion #region Modified Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change SMM 091004 Changed namespace to Adapdev.UnitTest */ #endregion namespace Adapdev.UnitTest { using System; using System.Text; /// <summary> /// Summary description for AssertionFailureMessage. /// </summary> public class AssertionFailureMessage { /// <summary> /// Protected constructor, used since this class is only used via /// static methods /// </summary> protected AssertionFailureMessage() {} /// <summary> /// Number of characters before a highlighted position before /// clipping will occur. Clipped text is replaced with an /// elipses "..." /// </summary> static protected int PreClipLength { get { return 35; } } /// <summary> /// Number of characters after a highlighted position before /// clipping will occur. Clipped text is replaced with an /// elipses "..." /// </summary> static protected int PostClipLength { get { return 35; } } /// <summary> /// Called to test if the position will cause clipping /// to occur in the early part of a string. /// </summary> /// <param name="iPosition"></param> /// <returns></returns> static private bool IsPreClipped( int iPosition ) { if( iPosition > PreClipLength ) { return true; } return false; } /// <summary> /// Called to test if the position will cause clipping /// to occur in the later part of a string past the /// specified position. /// </summary> /// <param name="sString"></param> /// <param name="iPosition"></param> /// <returns></returns> static private bool IsPostClipped( string sString, int iPosition ) { if( sString.Length - iPosition > PostClipLength ) { return true; } return false; } /// <summary> /// Property called to insert newline characters into a string /// </summary> static private string NewLine { get { return "\r\n\t"; } } /// <summary> /// Renders up to M characters before, and up to N characters after /// the specified index position. If leading or trailing text is /// clipped, and elipses "..." is added where the missing text would /// be. /// /// Clips strings to limit previous or post newline characters, /// since these mess up the comparison /// </summary> /// <param name="sString"></param> /// <param name="iPosition"></param> /// <returns></returns> static protected string ClipAroundPosition( string sString, int iPosition ) { if( null == sString || 0 == sString.Length ) { return ""; } return BuildBefore( sString, iPosition ) + BuildAfter( sString, iPosition ); } /// <summary> /// Clips the string before the specified position, and appends /// ellipses (...) to show that clipping has occurred /// </summary> /// <param name="sString"></param> /// <param name="iPosition"></param> /// <returns></returns> static protected string PreClip( string sString, int iPosition ) { return "..." + sString.Substring( iPosition - PreClipLength, PreClipLength ); } /// <summary> /// Clips the string after the specified position, and appends /// ellipses (...) to show that clipping has occurred /// </summary> /// <param name="sString"></param> /// <param name="iPosition"></param> /// <returns></returns> static protected string PostClip( string sString, int iPosition ) { return sString.Substring( iPosition, PostClipLength ) + "..."; } /// <summary> /// Builds the first half of a string, limiting the number of /// characters before the position, and removing newline /// characters. If the leading string is truncated, the /// ellipses (...) characters are appened. /// </summary> /// <param name="sString"></param> /// <param name="iPosition"></param> /// <returns></returns> static private string BuildBefore( string sString, int iPosition ) { if( IsPreClipped(iPosition) ) { return PreClip( sString, iPosition ); } return sString.Substring( 0, iPosition ); } /// <summary> /// Builds the last half of a string, limiting the number of /// characters after the position, and removing newline /// characters. If the string is truncated, the /// ellipses (...) characters are appened. /// </summary> /// <param name="sString"></param> /// <param name="iPosition"></param> /// <returns></returns> static private string BuildAfter( string sString, int iPosition ) { if( IsPostClipped(sString, iPosition) ) { return PostClip( sString, iPosition ); } return sString.Substring( iPosition ); } /// <summary> /// Text that is rendered for the expected value /// </summary> /// <returns></returns> static protected string ExpectedText() { return "expected:<"; } /// <summary> /// Text rendered for the actual value. This text should /// be the same length as the Expected text, so leading /// spaces should pad this string to ensure they match. /// </summary> /// <returns></returns> static protected string ButWasText() { return " but was:<"; } /// <summary> /// Raw line that communicates the expected value, and the actual value /// </summary> /// <param name="sbOutput"></param> /// <param name="expected"></param> /// <param name="actual"></param> static protected void AppendExpectedAndActual( StringBuilder sbOutput, Object expected, Object actual ) { sbOutput.Append( NewLine ); sbOutput.Append( ExpectedText() ); sbOutput.Append( DisplayString( expected ) ); sbOutput.Append( ">" ); sbOutput.Append( NewLine ); sbOutput.Append( ButWasText() ); sbOutput.Append( DisplayString( actual ) ); sbOutput.Append( ">" ); } /// <summary> /// Display an object as a string /// </summary> /// <param name="obj"></param> /// <returns></returns> static protected string DisplayString( object obj ) { if ( obj == null ) return "(null)"; else if ( obj is string ) return Quoted( (string)obj ); else return obj.ToString(); } /// <summary> /// Quote a string /// </summary> /// <param name="text"></param> /// <returns></returns> static protected string Quoted( string text ) { return string.Format( "\"{0}\"", text ); } /// <summary> /// Draws a marker under the expected/actual strings that highlights /// where in the string a mismatch occurred. /// </summary> /// <param name="sbOutput"></param> /// <param name="iPosition"></param> static protected void AppendPositionMarker( StringBuilder sbOutput, int iPosition ) { sbOutput.Append( new String( '-', ButWasText().Length + 1 ) ); if( iPosition > 0 ) { sbOutput.Append( new string( '-', iPosition ) ); } sbOutput.Append( "^" ); } /// <summary> /// Tests two objects to determine if they are strings. /// </summary> /// <param name="expected"></param> /// <param name="actual"></param> /// <returns></returns> static protected bool InputsAreStrings( Object expected, Object actual ) { if( null != expected && null != actual && expected is string && actual is string ) { return true; } return false; } /// <summary> /// Tests if two strings are different lengths. /// </summary> /// <param name="sExpected"></param> /// <param name="sActual"></param> /// <returns>True if string lengths are different</returns> static protected bool LengthsDifferent( string sExpected, string sActual ) { if( sExpected.Length != sActual.Length ) { return true; } return false; } /// <summary> /// Tests if two arrays are different lengths. /// </summary> /// <param name="sExpected"></param> /// <param name="sActual"></param> /// <returns>True if array lengths are different</returns> static protected bool LengthsDifferent( object[] expected, object[] actual ) { if( expected.Length != actual.Length ) { return true; } return false; } /// <summary> /// Used to construct a message when the lengths of two strings are /// different. Also includes the strings themselves, to allow them /// to be compared visually. /// </summary> /// <param name="sbOutput"></param> /// <param name="sExpected"></param> /// <param name="sActual"></param> static protected void BuildLengthsDifferentMessage( StringBuilder sbOutput, string sExpected, string sActual ) { BuildContentDifferentMessage( sbOutput, sExpected, sActual ); } /// <summary> /// Reports the length of two strings that are different lengths /// </summary> /// <param name="sbOutput"></param> /// <param name="sExpected"></param> /// <param name="sActual"></param> static protected void BuildStringLengthDifferentReport( StringBuilder sbOutput, string sExpected, string sActual ) { sbOutput.Append( "String lengths differ. Expected length=" ); sbOutput.Append( sExpected.Length ); sbOutput.Append( ", but was length=" ); sbOutput.Append( sActual.Length ); sbOutput.Append( "." ); sbOutput.Append( NewLine ); } /// <summary> /// Reports the length of two strings that are the same length /// </summary> /// <param name="sbOutput"></param> /// <param name="sExpected"></param> /// <param name="sActual"></param> static protected void BuildStringLengthSameReport( StringBuilder sbOutput, string sExpected, string sActual ) { sbOutput.Append( "String lengths are both " ); sbOutput.Append( sExpected.Length ); sbOutput.Append( "." ); sbOutput.Append( NewLine ); } /// <summary> /// Reports whether the string lengths are the same or different, and /// what the string lengths are. /// </summary> /// <param name="sbOutput"></param> /// <param name="sExpected"></param> /// <param name="sActual"></param> static protected void BuildStringLengthReport( StringBuilder sbOutput, string sExpected, string sActual ) { if( sExpected.Length != sActual.Length ) { BuildStringLengthDifferentReport( sbOutput, sExpected, sActual ); } else { BuildStringLengthSameReport( sbOutput, sExpected, sActual ); } } /// <summary> /// Reports the length of two arrays that are different lengths /// </summary> /// <param name="sbOutput"></param> /// <param name="expected"></param> /// <param name="actual"></param> static protected void BuildArrayLengthDifferentReport( StringBuilder sbOutput, Array expected, Array actual ) { sbOutput.Append( "Array lengths differ. Expected length=" ); sbOutput.Append( expected.Length ); sbOutput.Append( ", but was length=" ); sbOutput.Append( actual.Length ); sbOutput.Append( "." ); sbOutput.Append( NewLine ); } /// <summary> /// Reports the length of two arrays that are the same length /// </summary> /// <param name="sbOutput"></param> /// <param name="expected"></param> /// <param name="actual"></param> static protected void BuildArrayLengthSameReport( StringBuilder sbOutput, Array expected, Array actual ) { sbOutput.Append( "Array lengths are both " ); sbOutput.Append( expected.Length ); sbOutput.Append( "." ); sbOutput.Append( NewLine ); } /// <summary> /// Reports whether the array lengths are the same or different, and /// what the array lengths are. /// </summary> /// <param name="sbOutput"></param> /// <param name="expected"></param> /// <param name="actual"></param> static protected void BuildArrayLengthReport( StringBuilder sbOutput, Array expected, Array actual ) { if( expected.Length != actual.Length ) { BuildArrayLengthDifferentReport( sbOutput, expected, actual ); } else { BuildArrayLengthSameReport( sbOutput, expected, actual ); } } /// <summary> /// /// </summary> /// <param name="sbOutput"></param> /// <param name="sExpected"></param> /// <param name="sActual"></param> /// <param name="iPosition"></param> static private void BuildContentDifferentAtPosition( StringBuilder sbOutput, string sExpected, string sActual, int iPosition ) { BuildStringLengthReport( sbOutput, sExpected, sActual ); sbOutput.Append( "Strings differ at index " ); sbOutput.Append( iPosition ); sbOutput.Append( "." ); sbOutput.Append( NewLine ); // // Clips the strings, then turns any hidden whitespace into visible // characters // string sClippedExpected = ConvertWhitespace(ClipAroundPosition( sExpected, iPosition )); string sClippedActual = ConvertWhitespace(ClipAroundPosition( sActual, iPosition )); AppendExpectedAndActual( sbOutput, sClippedExpected, sClippedActual ); sbOutput.Append( NewLine ); // Add a line showing where they differ. If the string lengths are // different, they start differing just past the length of the // shorter string AppendPositionMarker( sbOutput, FindMismatchPosition( sClippedExpected, sClippedActual, 0 ) ); sbOutput.Append( NewLine ); } /// <summary> /// Turns CR, LF, or TAB into visual indicator to preserve visual marker /// position. This is done by replacing the '\r' into '\\' and 'r' /// characters, and the '\n' into '\\' and 'n' characters, and '\t' into /// '\\' and 't' characters. /// /// Thus the single character becomes two characters for display. /// </summary> /// <param name="sInput"></param> /// <returns></returns> static protected string ConvertWhitespace( string sInput ) { if( null != sInput ) { sInput = sInput.Replace( "\r", "\\r" ); sInput = sInput.Replace( "\n", "\\n" ); sInput = sInput.Replace( "\t", "\\t" ); } return sInput; } /// <summary> /// Shows the position two strings start to differ. Comparison /// starts at the start index. /// </summary> /// <param name="sExpected"></param> /// <param name="sActual"></param> /// <param name="iStart"></param> /// <returns>-1 if no mismatch found, or the index where mismatch found</returns> static private int FindMismatchPosition( string sExpected, string sActual, int iStart ) { int iLength = Math.Min( sExpected.Length, sActual.Length ); for( int i=iStart; i<iLength; i++ ) { // // If they mismatch at a specified position, report the // difference. // if( sExpected[i] != sActual[i] ) { return i; } } // // Strings have same content up to the length of the shorter string. // Mismatch occurs because string lengths are different, so show // that they start differing where the shortest string ends // if( sExpected.Length != sActual.Length ) { return iLength; } // // Same strings // Assert.IsTrue( sExpected.Equals( sActual ) ); return -1; } /// <summary> /// Constructs a message that can be displayed when the content of two /// strings are different, but the string lengths are the same. The /// message will clip the strings to a reasonable length, centered /// around the first position where they are mismatched, and draw /// a line marking the position of the difference to make comparison /// quicker. /// </summary> /// <param name="sbOutput"></param> /// <param name="sExpected"></param> /// <param name="sActual"></param> static protected void BuildContentDifferentMessage( StringBuilder sbOutput, string sExpected, string sActual ) { // // If they mismatch at a specified position, report the // difference. // int iMismatch = FindMismatchPosition( sExpected, sActual, 0 ); if( -1 != iMismatch ) { BuildContentDifferentAtPosition( sbOutput, sExpected, sActual, iMismatch ); return; } // // If the lengths differ, but they match up to the length, // show the difference just past the length of the shorter // string // if( sExpected.Length != sActual.Length ) { BuildContentDifferentAtPosition( sbOutput, sExpected, sActual, Math.Min(sExpected.Length, sActual.Length) ); } } /// <summary> /// Called to append a message when the input strings are different. /// A different message is rendered when the lengths are mismatched, /// and when the lengths match but content is mismatched. /// </summary> /// <param name="sbOutput"></param> /// <param name="expected"></param> /// <param name="actual"></param> static private void BuildStringsDifferentMessage( StringBuilder sbOutput, string expected, string actual ) { sbOutput.Append( NewLine ); if( LengthsDifferent( expected, actual ) ) { BuildLengthsDifferentMessage( sbOutput, expected, actual ); } else { BuildContentDifferentMessage( sbOutput, expected, actual ); } } /// <summary> /// Called to append a message when the input arrays are different. /// A different message is rendered when the lengths are mismatched, /// and when the lengths match but content is mismatched. /// </summary> /// <param name="sbOutput"></param> /// <param name="expected"></param> /// <param name="actual"></param> static private void BuildArraysDifferentMessage( StringBuilder sbOutput, int index, Array expected, Array actual ) { sbOutput.Append( NewLine ); BuildArrayLengthReport( sbOutput, expected, actual ); sbOutput.Append( "Arrays differ at index " ); sbOutput.Append( index ); sbOutput.Append( "." ); sbOutput.Append( NewLine ); if ( index < expected.Length && index < actual.Length ) { if( InputsAreStrings( expected.GetValue(index), actual.GetValue(index) ) ) { BuildStringsDifferentMessage( sbOutput, (string)expected.GetValue(index), (string)actual.GetValue(index) ); } else { AppendExpectedAndActual( sbOutput, expected.GetValue(index), actual.GetValue(index) ); } } else if( expected.Length < actual.Length ) { sbOutput.Append( NewLine ); sbOutput.Append( " extra:<" ); DisplayElements( sbOutput, actual, index, 3 ); sbOutput.Append( ">" ); } else { sbOutput.Append( NewLine ); sbOutput.Append( " missing:<" ); DisplayElements( sbOutput, expected, index, 3 ); sbOutput.Append( ">" ); } return; } static private void DisplayElements( StringBuilder sbOutput, Array array, int index, int max ) { for( int i = 0; i < max; i++ ) { sbOutput.Append( DisplayString( array.GetValue(index++) ) ); if ( index >= array.Length ) return; sbOutput.Append( "," ); } sbOutput.Append( "..." ); } /// <summary> /// Used to create a StringBuilder that is used for constructing /// the output message when text is different. Handles initialization /// when a message is provided. If message is null, an empty /// StringBuilder is returned. /// </summary> /// <param name="message"></param> /// <returns></returns> static protected StringBuilder CreateStringBuilder( string message, params object[] args ) { StringBuilder sbOutput; if (message != null) { if ( args != null && args.Length > 0 ) sbOutput = new StringBuilder( string.Format( message, args ) ); else sbOutput = new StringBuilder( message ); } else { sbOutput = new StringBuilder(); } return sbOutput; } /// <summary> /// Called to create a message when two objects have been found to /// be unequal. If the inputs are strings, a special message is /// rendered that can help track down where the strings are different, /// based on differences in length, or differences in content. /// /// If the inputs are not strings, the ToString method of the objects /// is used to show what is different about them. /// </summary> /// <param name="expected"></param> /// <param name="actual"></param> /// <param name="message"></param> /// <param name="args"></param> /// <returns></returns> static public string FormatMessageForFailNotEquals(Object expected, Object actual, string message, params object[] args) { StringBuilder sbOutput = CreateStringBuilder( message, args ); if( null != message ) { if( message.Length > 0 ) { sbOutput.Append( " " ); } } if( InputsAreStrings( expected, actual ) ) { BuildStringsDifferentMessage( sbOutput, (string)expected, (string)actual ); } else { AppendExpectedAndActual( sbOutput, expected, actual ); } return sbOutput.ToString(); } /// <summary> /// Called to create a message when two arrays are not equal. /// </summary> /// <param name="message"></param> /// <param name="expected"></param> /// <param name="actual"></param> /// <returns></returns> static public string FormatMessageForFailArraysNotEqual(int index, Array expected, Array actual, string message, params object[] args) { StringBuilder sbOutput = CreateStringBuilder( message, args ); if( null != message ) { if( message.Length > 0 ) { sbOutput.Append( " " ); } } BuildArraysDifferentMessage( sbOutput, index, expected, actual ); return sbOutput.ToString(); } } } --- NEW FILE: TestFixtureSetUpAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies a place for code that should be run at the beginning of the TestFixture /// </summary> /// <remarks> /// Any initialization code should be done here, instead of within the class constructor. /// /// This is because the constructor is only run ONCE, at the start of the test engine, whereas /// the TestFixtureSetUp will be run at the beginning of each TestFixture iteration. /// </remarks> /// <example> /// [TestFixtureSetUp] /// public void TestFixtureSetUp(){ /// // this will run at the beginning of the TestFixture /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class TestFixtureSetUpAttribute : Attribute { } } --- NEW FILE: TestFixtureTearDownAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies a place for code that should be run at the end of the TestFixture /// </summary> /// <remarks> /// Any finalization code should be done here, instead of within the class destructor. /// /// This is because the destructor is only run ONCE, when the test engine shuts down, whereas /// the TestFixtureTearDown will be run at the end of each TestFixture iteration. /// </remarks> /// <example> /// [TestFixtureTearDown] /// public void TestFixtureTearDown(){ /// // this will run at the end of the TestFixture /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class TestFixtureTearDownAttribute : Attribute { } } --- NEW FILE: TestTearDownAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies a place for code that should be run after a Test /// /// Unless a Test name is specified, this will run after each Test. /// </summary> /// <example> /// [TestTearDown] /// public void TestTearDown(){ /// // this will run for each test /// } /// /// [TestTearDown(Test="SomeTest")] /// public void TestTearDownForSomeTest(){ /// // this will run only for SomeTest /// } /// /// [Test] /// public void SomeTest(){ /// // code /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class TestTearDownAttribute : Attribute { private string _test = ""; /// <summary> /// Constructor /// </summary> public TestTearDownAttribute() : base() { } /// <summary> /// Constructor /// </summary> /// <param name="test">The name of the Test that this should run for.</param> public TestTearDownAttribute(string test) { this._test = test; } /// <summary> /// The name of the Test that this should run for. /// </summary> public string Test { get { return this._test; } set { this._test = value; } } } } --- NEW FILE: AssertionException.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ExpectedExceptionAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies an Exception type that is expected to be thrown. /// /// If that Exception type, or one of its children, is thrown then /// the Test will pass. /// /// If the Exception type, or one of its children, is not thrown then /// the Test will fail. /// </summary> /// <example> /// [Test] /// [ExpectedException(typeof(DivideByZeroException))] /// public void ExpectedDivideByZeroException() /// { /// Console.WriteLine("ExpectedException"); /// throw new DivideByZeroException("This Exception is expected."); /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class ExpectedExceptionAttribute : Attribute { private string expectedException = String.Empty; private string message = String.Empty; /// <summary> /// The ExceptionType that is expected to be thrown. /// </summary> public string ExceptionType { get { return expectedException; } } public string Message { get { return this.message;} set { this.message = value;} } /// <summary> /// Constructor /// </summary> /// <param name="exception">The ExceptionType that is expected to be thrown.</param> public ExpectedExceptionAttribute(Type exception) { expectedException = exception.FullName; } public ExpectedExceptionAttribute(Type exception, string message) { this.expectedException = exception.FullName; this.message = message; } } } --- NEW FILE: TearDownAttribute.cs --- #region Copyright / License Information /* Copyright 2004 - 2005 Adapdev Technologies, LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ============================ Author Log ============================ III Full Name SMM Sean McCormack (Adapdev) ============================ Change Log ============================ III MMDDYY Change */ #endregion namespace Adapdev.UnitTest { using System; /// <summary> /// Specifies a place for code that should be run after a Test /// /// Unless a Test name is specified, this will run after each Test. /// </summary> /// <remarks> /// This is a deprecated attribute that was created for backwards compatability with NUnit. /// New tests should use TestTearDown, since the name better communicates the scope. /// </remarks> /// <example> /// [TearDown] /// public void TearDown(){ /// // this will run for each test /// } /// /// [TearDown(Test="SomeTest")] /// public void TearDownForSomeTest(){ /// // this will run only for SomeTest /// } /// /// [Test] /// public void SomeTest(){ /// // code /// } /// </example> [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public sealed class TearDownAttribute : TestTearDownAttribute { } } --- NEW FILE: TestType.cs --- using System; namespace Adapdev.UnitTest { /// <summary> /// Summary description for TestType. /// </summary> /// [Serializable] [Flags] public enum TestType : int { /// <summary> /// /// </summary> Unit = 1, /// <summary> /// /// </summary> Integration = 2, /// <summary> /// /// </summary> System = 4, /// <summary> /// /// </summary> Database = 8, /// <summary> /// Function testing of the target-of-test should focus on any requirements for test that can be traced directly to use cases or business functions and business rules. The goals of these tests are to verify proper data acceptance, processing, and retrieval, and the appropriate implementation of the business rules. This type of testing is based upon black box techniques; that is verifying the application and its internal processes by interacting with the application via the Graphical User Interface (GUI) and analyzing the output or results. /// </summary> Functional = 16, /// <summary> /// Business Cycle Testing should emulate the activities performed over time. A period should be identified, such as one year,... [truncated message content] |