[Adapdev-commits] Adapdev/src/Adapdev.UnitTest.Core RunTestIterationCommand.cs,1.7,1.8 TestSuiteBuil
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-30 05:08:59
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3980/src/Adapdev.UnitTest.Core Modified Files: RunTestIterationCommand.cs TestSuiteBuilder.cs TypeHelper.cs Log Message: Added reflection caching improvements for TestSuiteBuilder Index: TestSuiteBuilder.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TestSuiteBuilder.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** TestSuiteBuilder.cs 26 Nov 2005 08:09:23 -0000 1.15 --- TestSuiteBuilder.cs 30 Nov 2005 05:08:47 -0000 1.16 *************** *** 1,2 **** --- 1,3 ---- + using System.Collections.Specialized; using System.Diagnostics; *************** *** 85,91 **** string orig = Environment.CurrentDirectory; Environment.CurrentDirectory = fi.DirectoryName; ! log.Debug("Building assembly: " + assemblyName); ! log.Debug("Environment Directory: " + orig); ! log.Debug("Assembly Directory: " + fi.DirectoryName); // add the assembly to the AssemblyCache --- 86,92 ---- string orig = Environment.CurrentDirectory; Environment.CurrentDirectory = fi.DirectoryName; ! //Console.WriteLine("Building assembly: " + assemblyName); ! //Console.WriteLine("Environment Directory: " + orig); ! //Console.WriteLine("Assembly Directory: " + fi.DirectoryName); // add the assembly to the AssemblyCache *************** *** 114,118 **** // restore the original environment Environment.CurrentDirectory = orig; ! if(log.IsDebugEnabled) log.Debug(ta.ToString()); } catch (Exception e) --- 115,119 ---- // restore the original environment Environment.CurrentDirectory = orig; ! //Console.WriteLine(ta.ToString()); } catch (Exception e) *************** *** 125,136 **** public TestFixture BuildTestFixture(Type t, TestAssembly ta, Assembly a) { Adapdev.UnitTest.Core.TestFixture tf = null; ! if (TypeHelper.HasCustomAttribute(t, typeof (Adapdev.UnitTest.TestFixtureAttribute)) ! || TypeHelper.HasCustomAttribute(t, typeof (NUnit.Framework.TestFixtureAttribute)) ! ) ! { try { ! if(log.IsDebugEnabled) log.Debug("Building TestFixture " + t.FullName); // Build the TestFixture tf = new Adapdev.UnitTest.Core.TestFixture(); --- 126,136 ---- public TestFixture BuildTestFixture(Type t, TestAssembly ta, Assembly a) { + HybridDictionary fd = TypeHelper.PopulateAttributes(t); Adapdev.UnitTest.Core.TestFixture tf = null; ! if(fd.Contains("Adapdev.UnitTest.TestFixtureAttribute") || fd.Contains("NUnit.Framework.TestFixtureAttribute")){ try { ! //Console.WriteLine("Building TestFixture " + t.FullName); ! // Build the TestFixture tf = new Adapdev.UnitTest.Core.TestFixture(); *************** *** 141,145 **** tf.FullName = t.FullName; ! if (TypeHelper.HasCustomAttribute(t, typeof (Adapdev.UnitTest.TestFixtureAttribute))) { Adapdev.UnitTest.TestFixtureAttribute tfa = (Adapdev.UnitTest.TestFixtureAttribute) TypeHelper.GetFirstCustomAttribute(t, typeof (Adapdev.UnitTest.TestFixtureAttribute)); --- 141,145 ---- tf.FullName = t.FullName; ! if (fd.Contains("Adapdev.UnitTest.TestFixtureAttribute")) { Adapdev.UnitTest.TestFixtureAttribute tfa = (Adapdev.UnitTest.TestFixtureAttribute) TypeHelper.GetFirstCustomAttribute(t, typeof (Adapdev.UnitTest.TestFixtureAttribute)); *************** *** 148,191 **** ! this.ProcessCommonAttributes(t, tf); foreach (MethodInfo mi in t.GetMethods()) { ! if (TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TestAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (NUnit.Framework.TestAttribute))) { ! if(log.IsDebugEnabled) log.Debug("Building Test " + mi.Name); tf.AddTest(this.BuildTest(mi, tf)); } ! else if (TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TestFixtureSetUpAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (NUnit.Framework.TestFixtureSetUpAttribute))) { ! if(log.IsDebugEnabled) log.Debug("Building TestFixtureSetUp " + mi.Name); tf.AddFixtureSetUp(this.BuildBaseTestHelper(mi, tf)); } ! else if (TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TestFixtureTearDownAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (NUnit.Framework.TestFixtureTearDownAttribute))) { ! if(log.IsDebugEnabled) log.Debug("Building TestFixtureTearDown " + mi.Name); tf.AddFixtureTearDown(this.BuildBaseTestHelper(mi, tf)); } ! else if (TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TestSetUpAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.SetUpAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (NUnit.Framework.SetUpAttribute)) ) { ! if(log.IsDebugEnabled) log.Debug("Building TestSetUp " + mi.Name); ! tf.AddTestSetUp(this.BuildTestHelper(mi, tf)); } ! else if (TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TestTearDownAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TearDownAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (NUnit.Framework.TearDownAttribute)) ) { ! if(log.IsDebugEnabled) log.Debug("Building TestTearDown " + mi.Name); ! tf.AddTestTearDown(this.BuildTestHelper(mi, tf)); } } ! if(log.IsDebugEnabled) log.Debug(tf.ToString()); } catch(Exception ex) --- 148,192 ---- ! this.ProcessCommonAttributes(fd, t, tf); foreach (MethodInfo mi in t.GetMethods()) { ! HybridDictionary md = TypeHelper.PopulateAttributes(mi); ! if (md.Contains("Adapdev.UnitTest.TestAttribute") ! || md.Contains("NUnit.Framework.TestAttribute")) { ! //Console.WriteLine("Building Test " + mi.Name); tf.AddTest(this.BuildTest(mi, tf)); } ! else if (md.Contains("Adapdev.UnitTest.TestFixtureSetUpAttribute") ! || md.Contains("NUnit.Framework.TestFixtureSetUpAttribute")) { ! //Console.WriteLine("Building TestFixtureSetUp " + mi.Name); tf.AddFixtureSetUp(this.BuildBaseTestHelper(mi, tf)); } ! else if (md.Contains("Adapdev.UnitTest.TestFixtureTearDownAttribute") ! || md.Contains("NUnit.Framework.TestFixtureTearDownAttribute")) { ! //Console.WriteLine("Building TestFixtureTearDown " + mi.Name); tf.AddFixtureTearDown(this.BuildBaseTestHelper(mi, tf)); } ! else if (md.Contains("Adapdev.UnitTest.TestSetUpAttribute") ! || md.Contains("Adapdev.UnitTest.SetUpAttribute") ! || md.Contains("NUnit.Framework.SetUpAttribute") ) { ! //Console.WriteLine("Building TestSetUp " + mi.Name); ! tf.AddTestSetUp(this.BuildTestHelper(md, mi, tf)); } ! else if (md.Contains("Adapdev.UnitTest.TestTearDownAttribute") ! || md.Contains("Adapdev.UnitTest.TearDownAttribute") ! || md.Contains("NUnit.Framework.TearDownAttribute") ) { ! //Console.WriteLine("Building TestTearDown " + mi.Name); ! tf.AddTestTearDown(this.BuildTestHelper(md, mi, tf)); } } ! //Console.WriteLine(tf.ToString()); } catch(Exception ex) *************** *** 205,217 **** t.Name = m.Name; t.FullName = tf.FullName + "." + m.Name; - this.ProcessTestAttribute(m, t); - this.ProcessCommonAttributes(m, t); - this.ProcessExpectedExceptionAttribute(m, t); - this.ProcessCategoryAttribute(m, t); - this.ProcessMaxKAttribute(m, t); - this.ProcessMinOperationsPerSecondAttribute(m, t); - this.ProcessTransactionAttribute(m, t); ! if(log.IsDebugEnabled) log.Debug("Test built: " + t.ToString()); return t; } --- 206,220 ---- t.Name = m.Name; t.FullName = tf.FullName + "." + m.Name; ! HybridDictionary md = TypeHelper.PopulateAttributes(m); ! this.ProcessTestAttribute(md, m, t); ! this.ProcessCommonAttributes(md, m, t); ! this.ProcessExpectedExceptionAttribute(md, m, t); ! this.ProcessCategoryAttribute(md, m, t); ! this.ProcessMaxKAttribute(md, m, t); ! this.ProcessMinOperationsPerSecondAttribute(md, m, t); ! this.ProcessTransactionAttribute(md, m, t); ! ! //Console.WriteLine("Test built: " + t.ToString()); return t; } *************** *** 225,247 **** } ! public TestHelper BuildTestHelper(MethodInfo m, TestFixture tf) { TestHelper th = new TestHelper(); th.Method = m.Name; th.Name = m.Name; ! this.ProcessTestSetUpAttribute(m, th); ! this.ProcessTestTearDownAttribute(m, th); return th; } ! public void ProcessCommonAttributes(ICustomAttributeProvider m, AbstractTest t) { ! this.ProcessIgnoreAttribute(m, t); ! this.ProcessRepeatAttribute(m, t); } ! public void ProcessIgnoreAttribute(ICustomAttributeProvider m, AbstractTest t) { ! if (TypeHelper.HasCustomAttribute(m, typeof (Adapdev.UnitTest.IgnoreAttribute))) { Adapdev.UnitTest.IgnoreAttribute ia = (Adapdev.UnitTest.IgnoreAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (Adapdev.UnitTest.IgnoreAttribute)); --- 228,250 ---- } ! public TestHelper BuildTestHelper(HybridDictionary md, MethodInfo m, TestFixture tf) { TestHelper th = new TestHelper(); th.Method = m.Name; th.Name = m.Name; ! this.ProcessTestSetUpAttribute(md, m, th); ! this.ProcessTestTearDownAttribute(md, m, th); return th; } ! public void ProcessCommonAttributes(HybridDictionary md, ICustomAttributeProvider m, AbstractTest t) { ! this.ProcessIgnoreAttribute(md, m, t); ! this.ProcessRepeatAttribute(md, m, t); } ! public void ProcessIgnoreAttribute(HybridDictionary md, ICustomAttributeProvider m, AbstractTest t) { ! if (md.Contains("Adapdev.UnitTest.IgnoreAttribute")) { Adapdev.UnitTest.IgnoreAttribute ia = (Adapdev.UnitTest.IgnoreAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (Adapdev.UnitTest.IgnoreAttribute)); *************** *** 249,253 **** t.IgnoreReason = ia.Reason; } ! else if (TypeHelper.HasCustomAttribute(m, typeof (NUnit.Framework.IgnoreAttribute))) { NUnit.Framework.IgnoreAttribute ia = (NUnit.Framework.IgnoreAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (NUnit.Framework.IgnoreAttribute)); --- 252,256 ---- t.IgnoreReason = ia.Reason; } ! else if (md.Contains("NUnit.Framework.IgnoreAttribute")) { NUnit.Framework.IgnoreAttribute ia = (NUnit.Framework.IgnoreAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (NUnit.Framework.IgnoreAttribute)); *************** *** 255,259 **** t.IgnoreReason = ia.Reason; } ! else if (TypeHelper.HasCustomAttribute(m, typeof(NUnit.Framework.ExplicitAttribute))) { t.Ignore = true; --- 258,262 ---- t.IgnoreReason = ia.Reason; } ! else if (md.Contains("NUnit.Framework.ExplicitAttribute")) { t.Ignore = true; *************** *** 262,268 **** } ! public void ProcessRepeatAttribute(ICustomAttributeProvider m, AbstractTest t) { ! if (TypeHelper.HasCustomAttribute(m, typeof (Adapdev.UnitTest.RepeatAttribute))) { Adapdev.UnitTest.RepeatAttribute a = (Adapdev.UnitTest.RepeatAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (Adapdev.UnitTest.RepeatAttribute)); --- 265,271 ---- } ! public void ProcessRepeatAttribute(HybridDictionary md, ICustomAttributeProvider m, AbstractTest t) { ! if (md.Contains("Adapdev.UnitTest.RepeatAttribute")) { Adapdev.UnitTest.RepeatAttribute a = (Adapdev.UnitTest.RepeatAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (Adapdev.UnitTest.RepeatAttribute)); *************** *** 274,280 **** } ! public void ProcessMaxKAttribute(ICustomAttributeProvider m, AbstractTest t) { ! if (TypeHelper.HasCustomAttribute(m, typeof (MaxKMemoryAttribute))) { MaxKMemoryAttribute a = (MaxKMemoryAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (MaxKMemoryAttribute)); --- 277,283 ---- } ! public void ProcessMaxKAttribute(HybridDictionary md, ICustomAttributeProvider m, AbstractTest t) { ! if (md.Contains("Adapdev.UnitTest.MaxKMemoryAttribute")) { MaxKMemoryAttribute a = (MaxKMemoryAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (MaxKMemoryAttribute)); *************** *** 284,290 **** } ! public void ProcessMinOperationsPerSecondAttribute(ICustomAttributeProvider m, AbstractTest t) { ! if (TypeHelper.HasCustomAttribute(m, typeof (MinOperationsPerSecondAttribute))) { MinOperationsPerSecondAttribute a = (MinOperationsPerSecondAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (MinOperationsPerSecondAttribute)); --- 287,293 ---- } ! public void ProcessMinOperationsPerSecondAttribute(HybridDictionary md, ICustomAttributeProvider m, AbstractTest t) { ! if (md.Contains("Adapdev.UnitTest.MinOperationsPerSecondAttribute")) { MinOperationsPerSecondAttribute a = (MinOperationsPerSecondAttribute) TypeHelper.GetFirstCustomAttribute(m, typeof (MinOperationsPerSecondAttribute)); *************** *** 294,300 **** } ! public void ProcessExpectedExceptionAttribute(ICustomAttributeProvider m, Test t) { ! if (TypeHelper.HasCustomAttribute(m, typeof (Adapdev.UnitTest.ExpectedExceptionAttribute))) { Adapdev.UnitTest.ExpectedExceptionAttribute a = --- 297,303 ---- } ! public void ProcessExpectedExceptionAttribute(HybridDictionary md, ICustomAttributeProvider m, Test t) { ! if (md.Contains("Adapdev.UnitTest.ExpectedExceptionAttribute")) { Adapdev.UnitTest.ExpectedExceptionAttribute a = *************** *** 304,308 **** t.ExpectedExceptionMessage = a.Message; } ! else if (TypeHelper.HasCustomAttribute(m, typeof (NUnit.Framework.ExpectedExceptionAttribute))) { NUnit.Framework.ExpectedExceptionAttribute a = --- 307,311 ---- t.ExpectedExceptionMessage = a.Message; } ! else if (md.Contains("NUnit.Framework.ExpectedExceptionAttribute")) { NUnit.Framework.ExpectedExceptionAttribute a = *************** *** 315,321 **** } ! public void ProcessTestAttribute(ICustomAttributeProvider m, Test t) { ! if (TypeHelper.HasCustomAttribute(m, typeof (Adapdev.UnitTest.TestAttribute))) { Adapdev.UnitTest.TestAttribute a = --- 318,324 ---- } ! public void ProcessTestAttribute(HybridDictionary md, ICustomAttributeProvider m, Test t) { ! if (md.Contains("Adapdev.UnitTest.TestAttribute")) { Adapdev.UnitTest.TestAttribute a = *************** *** 326,330 **** t.TestType = a.TestType; } ! else if (TypeHelper.HasCustomAttribute(m, typeof (NUnit.Framework.TestAttribute))) { NUnit.Framework.TestAttribute a = --- 329,333 ---- t.TestType = a.TestType; } ! else if (md.Contains("NUnit.Framework.TestAttribute")) { NUnit.Framework.TestAttribute a = *************** *** 336,343 **** } ! public void ProcessCategoryAttribute(ICustomAttributeProvider m, Test t) { // Check for NUnit Category attribute ! if (TypeHelper.HasCustomAttribute(m, typeof(NUnit.Framework.CategoryAttribute))) { NUnit.Framework.CategoryAttribute a = (NUnit.Framework.CategoryAttribute)TypeHelper.GetFirstCustomAttribute(m, typeof(NUnit.Framework.CategoryAttribute)); --- 339,346 ---- } ! public void ProcessCategoryAttribute(HybridDictionary md, ICustomAttributeProvider m, Test t) { // Check for NUnit Category attribute ! if (md.Contains("NUnit.Framework.CategoryAttribute")) { NUnit.Framework.CategoryAttribute a = (NUnit.Framework.CategoryAttribute)TypeHelper.GetFirstCustomAttribute(m, typeof(NUnit.Framework.CategoryAttribute)); *************** *** 346,356 **** } ! public void ProcessTransactionAttribute(ICustomAttributeProvider m, Test t) { ! if (TypeHelper.HasCustomAttribute(m, typeof(Adapdev.UnitTest.TransactionAttribute))) { t.TransactionType = TransactionType.AutoCommit; } ! else if (TypeHelper.HasCustomAttribute(m, typeof(Adapdev.UnitTest.RollbackTransactionAttribute))) { t.TransactionType = TransactionType.AutoRollback; --- 349,359 ---- } ! public void ProcessTransactionAttribute(HybridDictionary md, ICustomAttributeProvider m, Test t) { ! if (md.Contains("Adapdev.UnitTest.TransactionAttribute")) { t.TransactionType = TransactionType.AutoCommit; } ! else if (md.Contains("Adapdev.UnitTest.RollbackTransactionAttribute")) { t.TransactionType = TransactionType.AutoRollback; *************** *** 358,365 **** } ! public void ProcessTestSetUpAttribute(ICustomAttributeProvider mi, TestHelper t) { ! if (TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TestSetUpAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.SetUpAttribute)) ) { --- 361,368 ---- } ! public void ProcessTestSetUpAttribute(HybridDictionary md, ICustomAttributeProvider mi, TestHelper t) { ! if (md.Contains("Adapdev.UnitTest.TestSetUpAttribute") ! || md.Contains("Adapdev.UnitTest.SetUpAttribute") ) { *************** *** 372,379 **** } ! public void ProcessTestTearDownAttribute(ICustomAttributeProvider mi, TestHelper t) { ! if (TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TestTearDownAttribute)) ! || TypeHelper.HasCustomAttribute(mi, typeof (Adapdev.UnitTest.TearDownAttribute)) ) { --- 375,382 ---- } ! public void ProcessTestTearDownAttribute(HybridDictionary md, ICustomAttributeProvider mi, TestHelper t) { ! if (md.Contains("Adapdev.UnitTest.TestTearDownAttribute") ! || md.Contains("Adapdev.UnitTest.TearDownAttribute") ) { *************** *** 391,397 **** string lostAssemblyFilename = Path.Combine(Environment.CurrentDirectory, lostNamespace + ".dll"); ! log.Debug("Not found. Trying to resolve " + lostAssemblyFilename); Assembly a = Assembly.LoadFile(lostAssemblyFilename); ! if(a != null) log.Debug("Found. Loaded " + a.GetName().Name + " - " + a.GetName().Version + " - " + a.Location); return a; --- 394,400 ---- string lostAssemblyFilename = Path.Combine(Environment.CurrentDirectory, lostNamespace + ".dll"); ! //Console.WriteLine("Not found. Trying to resolve " + lostAssemblyFilename); Assembly a = Assembly.LoadFile(lostAssemblyFilename); ! //if(a != null) //Console.WriteLine("Found. Loaded " + a.GetName().Name + " - " + a.GetName().Version + " - " + a.Location); return a; *************** *** 401,405 **** { AssemblyName assemblyName = assembly.GetName(); ! log.Debug("Probing for: " + assemblyName); if (! dependencyList.Contains(assemblyName.FullName)) { --- 404,408 ---- { AssemblyName assemblyName = assembly.GetName(); ! //Console.WriteLine("Probing for: " + assemblyName); if (! dependencyList.Contains(assemblyName.FullName)) { *************** *** 415,419 **** public void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) { ! log.Debug("Loading: " + args.LoadedAssembly.FullName); } } --- 418,422 ---- public void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) { ! //Console.WriteLine("Loading: " + args.LoadedAssembly.FullName); } } Index: TypeHelper.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/TypeHelper.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TypeHelper.cs 16 Nov 2005 07:01:53 -0000 1.3 --- TypeHelper.cs 30 Nov 2005 05:08:47 -0000 1.4 *************** *** 1,2 **** --- 1,6 ---- + using System.Collections; + using System.Collections.Specialized; + using System.Diagnostics; + #region Copyright / License Information *************** *** 43,46 **** --- 47,52 ---- public class TypeHelper { + private static Hashtable attributeList = new Hashtable(); + public static bool HasCustomAttribute(ICustomAttributeProvider t, Type customAttributeType) { *************** *** 65,68 **** --- 71,93 ---- return attrs[0]; } + + public static HybridDictionary PopulateAttributes(ICustomAttributeProvider mi) + { + if(mi == null) + { + throw new ArgumentNullException("mi"); + } + + object[] attributes = mi.GetCustomAttributes(true); + System.Collections.Specialized.HybridDictionary attributeList = new HybridDictionary(attributes.Length); + + foreach(Attribute a in attributes) + { + attributeList[a.GetType().FullName] = null; + //Console.WriteLine(a.GetType().FullName); + } + + return attributeList; + } } } \ No newline at end of file Index: RunTestIterationCommand.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.UnitTest.Core/RunTestIterationCommand.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RunTestIterationCommand.cs 27 Nov 2005 06:32:43 -0000 1.7 --- RunTestIterationCommand.cs 30 Nov 2005 05:08:47 -0000 1.8 *************** *** 203,207 **** try { - // Console.WriteLine(t.Method); if (t.Test.Length < 1 || t.Test.ToLower().Equals(name.ToLower())) { --- 203,206 ---- |