Esempio n. 1
0
//        public static void CloseTestResultAsIs()
//        {
//
//            if (TestData.TestSuites.Count == 0) {
//                TestData.InitTestData();
//            }
//
//            if (null != TestData.CurrentTestResult) {
//                TestData.CurrentTestScenario.TestResults.Add(TestData.CurrentTestResult);
//            }
//
//            TestData.CurrentTestResult =
//                new TestResult(
//                    TestData.CurrentTestScenario.Id,
//                    TestData.CurrentTestSuite.Id);
//
//        }

        public static void CloseTestResult(
            string testResultName,
            string testResultId,
            bool testResult,
            bool isKnownIssue,
            // 20160116
            // InvocationInfo myInvocation,
            // 20160116
            // ErrorRecord error,
            Exception error,
            string description,
            TestResultOrigins origin,
            bool skipAutomatic)
        {
            // 20121224
            //bool result = false;

//            if (TestData.TestSuites.Count == 0) {
//                TestData.InitTestData();
//            }

            TestData.AddTestResult(
                testResultName,
                testResultId,
                testResult,
                isKnownIssue,
                true,
                // 20160116
                // myInvocation,
                error,
                description,
                origin,
                skipAutomatic);
        }
Esempio n. 2
0
 public virtual void SetOrigin(TestResultOrigins origin)
 {
     if (TestResultOrigins.Logical == Origin)
     {
         // don't change the origin - it already was logical
     }
     else
     {
         Origin = origin;
     }
 }
Esempio n. 3
0
 public virtual void SetOrigin(TestResultOrigins origin)
 {
     if (TestResultOrigins.Logical == this.Origin) {
         
         // don't change the origin - it already was logical
     } else {
         
         this.Origin = origin;
     }
 }
Esempio n. 4
0
        //        public static void CloseTestResultAsIs()
        //        {
        //
        //            if (TestData.TestSuites.Count == 0) {
        //                TestData.InitTestData();
        //            }
        //            
        //            if (null != TestData.CurrentTestResult) {
        //                TestData.CurrentTestScenario.TestResults.Add(TestData.CurrentTestResult);
        //            }
        //            
        //            TestData.CurrentTestResult =
        //                new TestResult(
        //                    TestData.CurrentTestScenario.Id,
        //                    TestData.CurrentTestSuite.Id);
        //
        //        }
        // 20121224
        //public static bool CloseTestResult(
        public static void CloseTestResult(
            string testResultName, 
            string testResultId, 
            bool testResult,
            bool isKnownIssue,
            InvocationInfo myInvocation,
            ErrorRecord error,
            string description,
            // 20130322
            //bool generated)
            //bool generated,
            TestResultOrigins origin,
            bool skipAutomatic)
        {
            // 20121224
            //bool result = false;

            //            if (TestData.TestSuites.Count == 0) {
            //                TestData.InitTestData();
            //            }

            TMX.TestData.AddTestResult(
                testResultName,
                testResultId,
                testResult,
                isKnownIssue,
                true,
                myInvocation,
                error,
                description,
                // 20130322
                //generated);
                // 20130626
                //generated,
                origin,
                skipAutomatic);

            // 20121224
            //return result;
        }
Esempio n. 5
0
        // 20160116
        internal static void AddTestResult(string closingTestResultName, // previousTestResultName
                                           string closingTestResultId, // previousTestResultId
                                           bool? passed,
                                           bool isKnownIssue,
                                           bool generateNextResult,
                                           // 20160116
                                           // InvocationInfo myInvocation,
                                           // ErrorRecord error,
                                           Exception error,
                                           string testResultDescription,
                                           TestResultOrigins origin,
                                           bool skipAutomatic)
        {
            //TestData.InitCurrentTestScenario();
            
            bool generated = TestResultOrigins.Automatic == origin;
            
            ITestResult currentTestResult;
            if (null != TestData.CurrentTestResult) {
                currentTestResult = TestData.CurrentTestResult;
            } else {
                // 20141204
//                currentTestResult =
//                    new TestResult(
//                        TestData.CurrentTestScenario.Id,
//                        TestData.CurrentTestSuite.Id);
                currentTestResult =
                    new TestResult(
                        TestData.CurrentTestScenario.Id,
                        TestData.CurrentTestSuite.Id) {
                    SuiteUniqueId = TestData.CurrentTestSuite.UniqueId,
                    ScenarioUniqueId = TestData.CurrentTestScenario.UniqueId
                };
            }
            
            if (string.IsNullOrEmpty(currentTestResult.Name)) {
                
//                if (closingTestResultName != null &&
//                    closingTestResultName != string.Empty &&
//                    closingTestResultName.Length > 0 &&
//                    TestData.CurrentTestResult != null && 
//                     closingTestResultName != TestData.CurrentTestResult.Name) {

                if (!string.IsNullOrEmpty(closingTestResultName) &&
                    ((TestData.CurrentTestResult != null && 
                      closingTestResultName != TestData.CurrentTestResult.Name) ||
                      null == TestData.CurrentTestResult)) {
                    
                    currentTestResult.Name = closingTestResultName;
                } else {
                    currentTestResult.Name = "generated test result name";
                }
                
            } else {
                // the current test result is a result that was preset
                // nothing to do
            }

            // setting test result's origin
            if (generated)
                currentTestResult.SetOrigin(TestResultOrigins.Automatic);
            else
                currentTestResult.SetOrigin(origin);

            if (string.IsNullOrEmpty(currentTestResult.Id)) {
                
                if (!string.IsNullOrEmpty(closingTestResultId) &&
                    ((null != TestData.CurrentTestResult &&
                    closingTestResultId != TestData.CurrentTestResult.Id) ||
                    null == TestData.CurrentTestResult))
                    currentTestResult.Id = closingTestResultId;
                else
                    currentTestResult.Id = GetTestResultId();
            } else {
                // there already was the Id
                // nothing to do
            }
            
            if (passed != null) {
                if ((bool)passed) {
                    currentTestResult.enStatus = TestResultStatuses.Passed;
                } else {
                    currentTestResult.enStatus = TestResultStatuses.Failed;
                }

                if (isKnownIssue) {
                    currentTestResult.enStatus = TestResultStatuses.KnownIssue;
                }
            } else {
                //currentTestResult.enStatus = TestResultStatuses.NotTested;
                
                // if there were no errors during the test case execution
                // it is marked as passed
                bool noErrors = true;
                if (null == currentTestResult.Error &&
                    TestResultStatuses.Failed != currentTestResult.enStatus &&
                    TestResultStatuses.KnownIssue != currentTestResult.enStatus) {
                    
                    foreach (ITestResultDetail detail in currentTestResult.Details) {
                        if (null == ((TestResultDetail)detail).ErrorDetail) {
                            noErrors = false;
                            break;
                        }
                    }
                }
                
                if (noErrors && null != passed) {
                    currentTestResult.enStatus = TestResultStatuses.Passed;
                }

            }
            
            if (!string.IsNullOrEmpty(testResultDescription)) {
                currentTestResult.Description = testResultDescription;
            }
            
            if (generated)
                currentTestResult.SetGenerated();
            
            if (TmxHelper.TestCaseStarted == DateTime.MinValue)
                TmxHelper.TestCaseStarted = DateTime.Now;

            currentTestResult.SetNow();
            currentTestResult.SetTimeSpent(
                (currentTestResult.Timestamp - TmxHelper.TestCaseStarted).TotalSeconds);
            
            TestData.CurrentTestResult = currentTestResult;
            
            try {
                TestData.CurrentTestResult.PlatformUniqueId = TestData.CurrentTestScenario.PlatformUniqueId;
                CurrentTestResult.PlatformId = CurrentTestScenario.PlatformId;
                // 20141204
                CurrentTestResult.SuiteUniqueId = CurrentTestSuite.UniqueId;
                CurrentTestResult.ScenarioUniqueId = CurrentTestScenario.UniqueId;
            }
            catch {}
            
            if (null != TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] &&
                TestResultOrigins.Logical == TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Origin &&
                TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] != TestData.CurrentTestResult &&
                !string.IsNullOrEmpty(TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name)) {
                
                TmxHelper.TestCaseStarted = DateTime.Now;
                // 20141204
                // TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));
                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id) {
                                                                 SuiteUniqueId = TestData.CurrentTestSuite.UniqueId,
                                                                 ScenarioUniqueId = TestData.CurrentTestScenario.UniqueId
                                                             });
            }

            /*
            if (null != TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] &&
                TestResultOrigins.Logical == TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Origin &&
                TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] != TestData.CurrentTestResult &&
                null != TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name &&
                0 < TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name.Length) {
                
                TmxHelper.TestCaseStarted =
                    System.DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));
               
            }
            */

            TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] = 
                TestData.CurrentTestResult;
            
            #region Test Result's PowerShell data
            // 20160116
            /*
            if (myInvocation != null) {
                TestData.CurrentTestResult.SetScriptName(TmxHelper.GetScriptName(myInvocation));
                TestData.CurrentTestResult.SetLineNumber(TmxHelper.GetScriptLineNumber(myInvocation));
                TestData.CurrentTestResult.SetPosition(TmxHelper.GetPipelinePosition(myInvocation));
                // 20130329
                try {
                    
                    if (((bool)passed && Preferences.LogScriptName_Passed) || (!(bool)passed && Preferences.LogScriptName_Failed)) {
                        
                        TestData.CurrentTestResult.Code += 
                            "script name: " + 
                            TestData.CurrentTestResult.ScriptName;
    
                    }
                }
                catch {}
                try {
                    
                    if (((bool)passed && Preferences.LogLineNumber_Passed) || (!(bool)passed && Preferences.LogLineNumber_Failed)) {
                        
                        TestData.CurrentTestResult.Code +=
                            "\r\nline number: " +
                            TestData.CurrentTestResult.LineNumber.ToString();
    
                    }
                }
                catch {}
                try {
                    
                    if (((bool)passed && Preferences.LogCode_Passed) || (!(bool)passed && Preferences.LogCode_Failed)) {
                        
                        TestData.CurrentTestResult.Code +=
                            "\r\ncode:\r\n" +
                            myInvocation.Line;
    
                    }
                }
                catch {}
            }
            
            if (error != null) {
                // 20150116
                // TestData.CurrentTestResult.SetError(error);
                TestData.CurrentTestResult.SetError(error.Exception);
            }
            */
            #endregion Test Result's PowerShell data
            
            var sourceTestResult = TestData.CurrentTestResult;
            SetScenarioStatus(skipAutomatic);
            SetSuiteStatus(skipAutomatic);
            
            if (generateNextResult) {
                // write current time
                TmxHelper.TestCaseStarted = DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(
                    new TestResult(
                       TestData.CurrentTestScenario.Id,
                       TestData.CurrentTestScenario.SuiteId) { SuiteUniqueId = CurrentTestScenario.SuiteUniqueId, ScenarioUniqueId = CurrentTestScenario.UniqueId });
                TestData.CurrentTestResult = 
                    TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1];
            } else {
                // write zero time
                TmxHelper.TestCaseStarted = DateTime.MinValue;
                TestData.CurrentTestResult = null;
            }
            
            if (Preferences.Storage) {
                using (var session = StorageHelper.SessionFactory.OpenSession())
                {
                    session.Save(TestData.CurrentTestResult);
                }
            }

            OnTmxNewTestResultClosed(sourceTestResult, null);
        }
Esempio n. 6
0
        internal static void AddTestResult(string closingTestResultName, // previousTestResultName
                                           string closingTestResultId, // previousTestResultId
                                           bool? passed,
                                           bool isKnownIssue,
                                           bool generateNextResult,
                                           InvocationInfo myInvocation,
                                           ErrorRecord error,
                                           string testResultDescription,
                                           // 20130322
                                           //bool generated)
                                           // 20130626
                                           //bool generated,
                                           TestResultOrigins origin,
                                           bool skipAutomatic)
        {
            //TestData.InitCurrentTestScenario();

            // 20130626
            bool generated = false;
            if (TestResultOrigins.Automatic == origin) {
                generated = true;
            }

            // 20130429
            TMX.Logger.TMXLogger.Info("Test result: '" + closingTestResultName + "'\tPassed:" + passed.ToString() + "\tKnown issue:" + isKnownIssue.ToString());

            ITestResult currentTestResult;
            if (null != TestData.CurrentTestResult) {

            dumpTestStructure("AddTestResult #1");
                currentTestResult = TestData.CurrentTestResult;
            dumpTestStructure("AddTestResult #1b");
            } else {

            dumpTestStructure("AddTestResult #2");
                currentTestResult =
                    new TestResult(
                        TestData.CurrentTestScenario.Id,
                        TestData.CurrentTestSuite.Id);
            dumpTestStructure("AddTestResult #2b");
            }

            // 20130325
            if (null == currentTestResult.Name ||
                string.Empty == currentTestResult.Name ||
                0 == currentTestResult.Name.Length) {

            dumpTestStructure("AddTestResult #3");
                // 20130610
            //                if (closingTestResultName != null &&
            //                    closingTestResultName != string.Empty &&
            //                    closingTestResultName.Length > 0 &&
            //                    TMX.TestData.CurrentTestResult != null &&
            //                     closingTestResultName != TMX.TestData.CurrentTestResult.Name) {

                if (closingTestResultName != null &&
                    closingTestResultName != string.Empty &&
                    closingTestResultName.Length > 0 &&
                    ((TMX.TestData.CurrentTestResult != null &&
                      closingTestResultName != TMX.TestData.CurrentTestResult.Name) ||
                      null == TMX.TestData.CurrentTestResult)) {

            dumpTestStructure("AddTestResult #3b");
                    currentTestResult.Name = closingTestResultName;

                } else {

            dumpTestStructure("AddTestResult #4");
                    currentTestResult.Name = "generated test result name";
                }

            // 20130326
            } else {

            dumpTestStructure("AddTestResult #5");
                // the current test result is a result that was preset
                // nothing to do
            }

            // 20130322
            // setting test result's origin
            if (generated) {

            dumpTestStructure("AddTestResult #6");
                currentTestResult.SetOrigin(TestResultOrigins.Automatic);

            } else {

            dumpTestStructure("AddTestResult #7");
                // 20130627
                //currentTestResult.SetOrigin(TestResultOrigins.Logical);
                currentTestResult.SetOrigin(origin);

            }

            // 20130325
            if (null == currentTestResult.Id ||
                string.Empty == currentTestResult.Id ||
                0 == currentTestResult.Id.Length) {

            dumpTestStructure("AddTestResult #8");
                // 20130610
            //                if (closingTestResultId != null &&
            //                    closingTestResultId != string.Empty &&
            //                    closingTestResultId.Length > 0 &&
            //                    null != TMX.TestData.CurrentTestResult &&
            //                    closingTestResultId != TMX.TestData.CurrentTestResult.Id) {

                if (closingTestResultId != null &&
                    closingTestResultId != string.Empty &&
                    closingTestResultId.Length > 0 &&
                    ((null != TMX.TestData.CurrentTestResult &&
                      closingTestResultId != TMX.TestData.CurrentTestResult.Id) ||
                      null == TMX.TestData.CurrentTestResult)) {

            dumpTestStructure("AddTestResult #9");
                    currentTestResult.Id = closingTestResultId;

                } else {

            dumpTestStructure("AddTestResult #10");
                    currentTestResult.Id = GetTestResultId();

                }
            // 20130326
            } else {
            dumpTestStructure("AddTestResult #11");
                // there already was the Id
                // nothing to do
            }

            if (passed != null) {
            dumpTestStructure("AddTestResult #14");
                if ((bool)passed) {

                    currentTestResult.enStatus = TestResultStatuses.Passed;
                } else {

                    currentTestResult.enStatus = TestResultStatuses.Failed;
                }

                if (isKnownIssue) {

                    currentTestResult.enStatus = TestResultStatuses.KnownIssue;
                }
            } else {
            dumpTestStructure("AddTestResult #15");

                // 20130407
                //currentTestResult.enStatus = TestResultStatuses.NotTested;

                // 20130330
                // if there were no errors during the test case execution
                // it is marked as passed
                bool noErrors = true;
                if (null == currentTestResult.Error &&
                    TestResultStatuses.Failed != currentTestResult.enStatus &&
                    TestResultStatuses.KnownIssue != currentTestResult.enStatus) {
            dumpTestStructure("AddTestResult #16");
                    //foreach (ITestResultDetail detail in currentTestResult.Details) {
                    foreach (ITestResultDetail detail in currentTestResult.Details) {
            dumpTestStructure("AddTestResult #17");
                        if (null == ((TestResultDetail)detail).ErrorDetail) {
            dumpTestStructure("AddTestResult #18");
                            noErrors = false;
                            break;
                        }
                    }
                }
                // 20130407
                //if (noErrors) {
                if (noErrors && null != passed) {
            dumpTestStructure("AddTestResult #19");
                    currentTestResult.enStatus = TestResultStatuses.Passed;
                }

            }
            dumpTestStructure("AddTestResult #20");
            if (testResultDescription != null &&
                testResultDescription != string.Empty &&
                testResultDescription.Length > 0){
            dumpTestStructure("AddTestResult #21");
                currentTestResult.Description = testResultDescription;

            }

            if (generated) {
            dumpTestStructure("AddTestResult #23");
                currentTestResult.SetGenerated();

            }

            if (TMXHelper.TestCaseStarted == System.DateTime.MinValue) {
            dumpTestStructure("AddTestResult #25");
                TMXHelper.TestCaseStarted = System.DateTime.Now;
            }

            currentTestResult.SetNow();
            dumpTestStructure("AddTestResult #27");
            currentTestResult.SetTimeSpent(
                (currentTestResult.Timestamp - TMXHelper.TestCaseStarted).TotalSeconds);
            dumpTestStructure("AddTestResult #29");

            TestData.CurrentTestResult = currentTestResult;

            // 20130531
            try {
                TestData.CurrentTestResult.PlatformId =
                    // 20130612
                    //TestData.CurrentTestPlatform.Id;
                    TestData.CurrentTestScenario.PlatformId;
            }
            catch {}

            // 20130326
            if (null != TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] &&
                TestResultOrigins.Logical == TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Origin &&
                TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] != TestData.CurrentTestResult &&
                null != TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name &&
                0 < TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1].Name.Length) {
            dumpTestStructure("AddTestResult #30");

                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(new TestResult(TestData.CurrentTestScenario.Id, TestData.CurrentTestSuite.Id));

            }

            TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1] =
                TestData.CurrentTestResult;

            #region Test Result's PowerShell data
            if (myInvocation != null) {

                TestData.CurrentTestResult.SetScriptName(TMXHelper.GetScriptName(myInvocation));

                TestData.CurrentTestResult.SetLineNumber(TMXHelper.GetScriptLineNumber(myInvocation));

                TestData.CurrentTestResult.SetPosition(TMXHelper.GetPipelinePosition(myInvocation));

                // 20130329
                try {

                    if (((bool)passed && Preferences.LogScriptName_Passed) || (!(bool)passed && Preferences.LogScriptName_Failed)) {

                        TestData.CurrentTestResult.Code +=
                            "script name: " +
                            TestData.CurrentTestResult.ScriptName;

                    }
                }
                catch {}
                try {

                    if (((bool)passed && Preferences.LogLineNumber_Passed) || (!(bool)passed && Preferences.LogLineNumber_Failed)) {

                        TestData.CurrentTestResult.Code +=
                            "\r\nline number: " +
                            TestData.CurrentTestResult.LineNumber.ToString();

                    }
                }
                catch {}
                try {

                    if (((bool)passed && Preferences.LogCode_Passed) || (!(bool)passed && Preferences.LogCode_Failed)) {

                        TestData.CurrentTestResult.Code +=
                            "\r\ncode:\r\n" +
                            myInvocation.Line;

                    }
                }
                catch {}
            }

            if (error != null) {

                TestData.CurrentTestResult.SetError(error);

            }
            #endregion Test Result's PowerShell data

            var sourceTestResult = TestData.CurrentTestResult;

            // 20130322
            //SetScenarioStatus();
            SetScenarioStatus(skipAutomatic);

            // 20130322
            //SetSuiteStatus();
            SetSuiteStatus(skipAutomatic);

            if (generateNextResult) {
            dumpTestStructure("AddTestResult #40");
                // write current time
                TMXHelper.TestCaseStarted =
                    System.DateTime.Now;
                TestData.CurrentTestScenario.TestResults.Add(
                    new TestResult(
                       TestData.CurrentTestScenario.Id,
                       TestData.CurrentTestScenario.SuiteId));
                TestData.CurrentTestResult =
                    TestData.CurrentTestScenario.TestResults[TestData.CurrentTestScenario.TestResults.Count - 1];
            dumpTestStructure("AddTestResult #45");
            } else {
            dumpTestStructure("AddTestResult #46");
                // write zero time
                TMXHelper.TestCaseStarted =
                    System.DateTime.MinValue;
                TestData.CurrentTestResult = null;
            }

            if (TMX.Preferences.Storage) {
                // 20130527
                using (var session = StorageHelper.SessionFactory.OpenSession())
                {
                    session.Save(TestData.CurrentTestResult);
                }
            }

            OnTMXNewTestResultClosed(sourceTestResult, null);
        }
Esempio n. 7
0
//        public static void CloseTestResultAsIs()
//        {
//
//            if (TestData.TestSuites.Count == 0) {
//                TestData.InitTestData();
//            }
//            
//            if (null != TestData.CurrentTestResult) {
//                TestData.CurrentTestScenario.TestResults.Add(TestData.CurrentTestResult);
//            }
//            
//            TestData.CurrentTestResult =
//                new TestResult(
//                    TestData.CurrentTestScenario.Id,
//                    TestData.CurrentTestSuite.Id);
//
//        }
        
        public static void CloseTestResult(
            string testResultName, 
            string testResultId, 
            bool testResult,
            bool isKnownIssue,
            // 20160116
            // InvocationInfo myInvocation,
            // 20160116
            // ErrorRecord error,
            Exception error,
            string description,
            TestResultOrigins origin,
            bool skipAutomatic)
        {
            // 20121224
            //bool result = false;
            
//            if (TestData.TestSuites.Count == 0) {
//                TestData.InitTestData();
//            }

            TestData.AddTestResult(
                testResultName, 
                testResultId, 
                testResult, 
                isKnownIssue,
                true,
                // 20160116
                // myInvocation,
                error,
                description,
                origin,
                skipAutomatic);
        }