Example #1
0
        //-------------------------------------------------------------------------------------------
        public bool IsStagingOrProductionTest(System_Tests test)
        {
            string classPath = test.Path.Substring(0, test.Path.LastIndexOf("."));
               var matchingType = (from x in Assembly.GetExecutingAssembly().GetTypes()
                                   where x.FullName == classPath
                                        select x).FirstOrDefault();

               if (matchingType != null &&
                   LinqTestHelpers.HasAttribute(typeof(StagingTest), matchingType))
               {
                    return true;
               }

               return false;
        }
Example #2
0
        private void RunTest(System_Tests test)
        {
            //test.StartTime = DateTime.UtcNow;
               //Stopwatch sw = new Stopwatch();
               //sw.Start();
               test.EndDateTime = null;
               test.StartDateTime = DateTime.UtcNow;
               test.Status = "Running";

               string typePath = test.Path.Substring(0, test.Path.LastIndexOf("."));
               string methodName = test.Path.Substring(test.Path.LastIndexOf(".") + 1);

               var testType = (from x in TestingContext.TestAssembly.GetTypes()
                                where x.FullName == typePath
                                select x).FirstOrDefault();

               if (testType == null)
               {
                    test.Status = "Missing";
                    return;
               }

               MethodInfo testMethod = testType.GetMethods().Where(x => x.Name == methodName).FirstOrDefault();

               object activatedClass = (testType.IsAbstract) ? null : Activator.CreateInstance(testType);
               test.Log += " -> " + testMethod.Name + "()";
               try
               {
                    var SetUpMethods = LinqTestHelpers.GetMethodsForAttribute(testType, typeof(TestFixtureSetUpAttribute));
                    SetUpMethods.ToList().ForEach(matchedMethod => matchedMethod.Invoke(activatedClass, null));

                    testMethod.Invoke(activatedClass, null);

                    test.Status = "Passed";
               }
               catch (Exception ex)
               {
                    test.Status = "Failed";
                    test.WriteLog(" ---> " + System.Web.HttpUtility.HtmlEncode(ex.ToString()));
               }
               finally
               {
                    try
                    {
                         if (!bSkipCleanUp.Checked)
                         {
                              var TearDownMethods = LinqTestHelpers.GetMethodsForAttribute(testType, typeof(TestFixtureTearDownAttribute));
                              TearDownMethods.ToList().ForEach(matchedMethod => matchedMethod.Invoke(activatedClass, null));
                         }
                    }
                    catch { }
               }

               //sw.Stop();

               test.LastRunDateTime = DateTime.UtcNow;
               test.EndDateTime = DateTime.UtcNow;

               test.WriteLog("<span style='color:red'>-----<br />Test ended.</span>");
        }
Example #3
0
        //-------------------------------------------------------------------------------------------
        private void TestingHarness_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("about:blank");
               WebBrowserStreamWriter wsw = new WebBrowserStreamWriter(webBrowser1);
               Console.SetOut(wsw);

               dataGridView1.AutoGenerateColumns = false;

               if (TestingContext.Arguments["testlib"] != null)
               {
                    TestingContext.TestAssembly = Assembly.LoadFile(TestingContext.Arguments["testlib"]);
               }
               else
               {
                    TestingContext.TestAssembly = Assembly.GetExecutingAssembly();
               }

               var testTypes = (from x in TestingContext.TestAssembly.GetTypes()
                                where LinqTestHelpers.HasAttribute(typeof(StagingTest), x)
                                || LinqTestHelpers.HasAttribute(typeof(ManualTest), x)
                                select x);

               foreach (var type in testTypes)
               {
                    MethodInfo[] methods = type.GetMethods();
                    var matchedMethods = (from y in methods
                                          where y.GetCustomAttributes(typeof(StagingTest), true).Count() > 0
                                          || y.GetCustomAttributes(typeof(ManualTest), true).Count() > 0
                                          select y);

                    foreach (var method in matchedMethods)
                    {
                         var newTest = new System_Tests();
                         newTest.Status = "Untested";
                         newTest.Path = type.FullName + "." + method.Name;
                         newTest.IsStagingTest = (method.GetCustomAttributes(typeof(StagingTest), true).Count() > 0);
                         TestingContext.Tests.Add(newTest);
                    }
               }

               BindData();

               tbSearch.Focus();

               if (TestingContext.Arguments["runtests"] == "true")
               {
                    Console.WriteLine("Running tests..");
                    ThreadPool.QueueUserWorkItem(o => RunTests());
               }
        }
Example #4
0
 //-------------------------------------------------------------------------------------------
 private void QueueTestRun(System_Tests test)
 {
     ThreadPool.QueueUserWorkItem(o => RunTest(test));
 }