Example #1
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>");
        }