public XMLElementsNativeStruct(SearchCmdletBase cmdlet)
        {
            this.suitesNode = "suites";
            this.suiteNode = "suite";
            this.scenariosNode = "scenarios";
            this.scenarioNode = "scenario";
            this.testResultsNode = "testResults";
            this.testResultNode = "testResult";

            this.failedAttribute = "failed";

            this.timeSpentAttribute = "timeSpent";
            this.timeStampAttribute = "timestamp";
        }
        public XMLElementsJUnitStruct(SearchCmdletBase cmdlet)
        {
            this.suitesNode = "testsuites";
            this.suiteNode = "testsuite";
            this.scenariosNode = "testsuites";
            this.scenarioNode = "testsuite";
            this.testResultsNode = "testcases";
            this.testResultNode = "testcase";

            this.failedAttribute = "errors";

            this.timeSpentAttribute = "time";
            this.timeStampAttribute = "timestamp";
        }
        public void GatherCollections(SearchCmdletBase cmdlet)
        {
            cmdlet.WriteVerbose(cmdlet, "getting test suites");
            IOrderedEnumerable<TestSuite> suites =
                TMXHelper.SearchForSuites(cmdlet);
            this.TestSuites = suites;

            cmdlet.WriteVerbose(cmdlet, "getting test scenarios");
            IOrderedEnumerable<TestScenario> scenarios =
                TMXHelper.SearchForScenarios(cmdlet);
            this.TestScenarios = scenarios;

            cmdlet.WriteVerbose(cmdlet, "getting test results");
            IOrderedEnumerable<TestResult> testResults =
                TMXHelper.SearchForTestResults(cmdlet);
            this.TestResults = testResults;
        }
Example #4
0
 public static void ImportResultsFromJUnitXML(SearchCmdletBase cmdlet, string path)
 {
     throw new NotImplementedException();
 }
Example #5
0
        /// <summary>
        /// Performs parametrized search for all types of TMX objects and stores
        /// the findings by the path provided.
        /// </summary>
        /// <param name="cmdlet"></param>
        /// <param name="path"></param>
        public static void ExportResultsToXML(SearchCmdletBase cmdlet, string path)
        {
            try {

                GatherTestResultsCollections gathered =
                    new GatherTestResultsCollections();
                gathered.GatherCollections(cmdlet);

                cmdlet.WriteVerbose(cmdlet, "converting data to XML");
                XElement suitesElement =
                    TMXHelper.CreateSuitesXElementWithParameters(
                        gathered.TestSuites,
                        gathered.TestScenarios,
                        gathered.TestResults,
                        (new XMLElementsNativeStruct(cmdlet)));

                cmdlet.WriteVerbose(cmdlet, "creating an XML document");
                System.Xml.Linq.XDocument document =
                    new System.Xml.Linq.XDocument();
                cmdlet.WriteVerbose(cmdlet, "adding XML data to the document");
                document.Add(suitesElement);
                cmdlet.WriteVerbose(
                    cmdlet,
                    "saving XML to the file '" +
                    path +
                    "'.");
                document.Save(path);
                cmdlet.WriteVerbose(cmdlet, "the document is saved");
            }
            catch (Exception eCreateDocument) {
                cmdlet.WriteError(
                    cmdlet,
                    "Unable to save XML report to the file '" +
                    path +
                    "'. " +
                    eCreateDocument.Message,
                    "FailedToSaveReport",
                    ErrorCategory.InvalidOperation,
                    true);
            }
        }
Example #6
0
        public static void SearchForTestResultsPS(SearchCmdletBase cmdlet)
        {
            IOrderedEnumerable<TestResult> testResults =
                SearchForTestResults(cmdlet);

            if (testResults.Count<TMX.TestResult>() > 0) {
                cmdlet.WriteObject(testResults, true);
            } else {
                cmdlet.WriteObject(null);
            }
        }
Example #7
0
        /// <summary>
        /// Performs parametrized search for Test Results.
        /// </summary>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        public static IOrderedEnumerable<TestResult> SearchForTestResults(SearchCmdletBase cmdlet)
        {
            IOrderedEnumerable<TestResult> testResults = null;

            // Filtering results

            // default result
            Func<TestResult, bool> query = testResult => true;

            if (cmdlet.FilterNameContains != null && cmdlet.FilterNameContains.Length > 0) {
                query = testResult =>
                    {
                        if (testResult.Name != null) {
                            return testResult.Name.Contains(cmdlet.FilterNameContains);
                        }
                        return false;
                    };
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterIdContains != null && cmdlet.FilterIdContains.Length > 0) {
                query = testResult =>
                    {
                        if (testResult.Id != null) {
                            return testResult.Id.Contains(cmdlet.FilterIdContains);
                        }
                        return false;
                    };
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterDescriptionContains != null && cmdlet.FilterDescriptionContains.Length > 0) {
                query = testResult =>
                    {
                        if (testResult.Description != null) {
                            return testResult.Description.Contains(cmdlet.FilterDescriptionContains);
                        }
                        return false;
                    };
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterPassed) {
                query = testResult => testResult.enStatus == TestResultStatuses.Passed;
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterFailed) {
                query = testResult => testResult.enStatus == TestResultStatuses.Failed;
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterNotTested) {
                query = testResult => testResult.enStatus == TestResultStatuses.NotTested;
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterPassedWithBadSmell) {
                query = testResult => testResult.enStatus == TestResultStatuses.KnownIssue;
                cmdlet.FilterAll = false;
            } // 20130322
            else if (cmdlet.FilterOutAutomaticResults) {
                query = testResult => testResult.Origin != TestResultOrigins.Automatic;
                cmdlet.FilterAll = false;
            }
            // 20130626
            else if (cmdlet.FilterOutAutomaticAndTechnicalResults) {
                query = testResult => testResult.Origin != TestResultOrigins.Automatic && testResult.Origin != TestResultOrigins.Technical;
                cmdlet.FilterAll = false;
            }
            if (cmdlet.FilterAll) {
                query = testResult => true;
            }
            // 20121006
            if (cmdlet.FilterNone) {
                query = testResult => false;
            }

            // Ordering results

            // default result
            Func<TestResult, object> ordering = testResult => testResult.Id;

            if (cmdlet.OrderByTimeSpent) {
                ordering = testResult => testResult.TimeSpent;
            } else if (cmdlet.OrderByDateTime) {
                ordering = testResult => testResult.Timestamp;
            } else if (cmdlet.OrderByName) {
                ordering = testResult => testResult.Name;
            } else if (cmdlet.OrderById) {
                ordering = testResult => testResult.Id;
            }

            cmdlet.WriteVerbose(cmdlet, "query = " + query.ToString());
            cmdlet.WriteVerbose(cmdlet, "ordering = " + ordering.ToString());

            testResults =
                TMX.TestData.SearchTestResult(
                    query,
                    ordering,
                    cmdlet.Descending);

            return testResults;
        }
Example #8
0
        public static void SearchForSuitesPS(SearchCmdletBase cmdlet)
        {
            IOrderedEnumerable<TestSuite> suites =
                SearchForSuites(cmdlet);

            if (suites.Count<TMX.TestSuite>() > 0) {
                cmdlet.WriteObject(suites, true);
            } else {
                cmdlet.WriteObject(null);
            }
        }
Example #9
0
        /// <summary>
        /// Performs parametrized search for Test Suites.
        /// </summary>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        public static IOrderedEnumerable<TestSuite> SearchForSuites(SearchCmdletBase cmdlet)
        {
            IOrderedEnumerable<TestSuite> suites = null;
            //IQueryable<TestSuite> suites = null;

            // Filtering results

            // default result
            Func<TestSuite, bool> query = suite => true;

            // 20130203
            //            System.Collections.Generic.List<Func<TestSuite, bool>> queriesList =
            //                new List<Func<TestSuite, bool>>();
            //            queriesList.Add(query);

            if (cmdlet.FilterNameContains != null && cmdlet.FilterNameContains.Length > 0) {
                // 20130203
                query = suite => suite.Name.Contains(cmdlet.FilterNameContains);
                //queriesList.Add((suite => suite.Name.Contains(cmdlet.FilterNameContains)));
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterIdContains != null && cmdlet.FilterIdContains.Length > 0) {
                // 20130203
                query = suite => suite.Id.Contains(cmdlet.FilterIdContains);
                //queriesList.Add((suite => suite.Id.Contains(cmdlet.FilterIdContains)));
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterDescriptionContains != null && cmdlet.FilterDescriptionContains.Length > 0) {
                // 20130203
                query = suite =>
                    {
                        if (suite.Description != null) {
                            return suite.Description.Contains(cmdlet.FilterDescriptionContains);
                        }
                        return false;
                    };
            //                queriesList.Add((suite =>
            //                    {
            //                        if (suite.Description != null) {
            //                            return suite.Description.Contains(cmdlet.FilterDescriptionContains);
            //                        }
            //                        return false;
            //                    }));
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterPassed) {
                // 20130203
                query = suite => suite.enStatus == TestSuiteStatuses.Passed;
                //queriesList.Add((suite => suite.enStatus == TestSuiteStatuses.Passed));
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterFailed) {
                // 20130203
                query = suite => suite.enStatus == TestSuiteStatuses.Failed;
                //queriesList.Add((suite => suite.enStatus == TestSuiteStatuses.Failed));
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterNotTested) {
                // 20130203
                query = suite => suite.enStatus == TestSuiteStatuses.NotTested;
                //queriesList.Add((suite => suite.enStatus == TestSuiteStatuses.NotTested));
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterPassedWithBadSmell) {
                // 20130203
                query = suite => suite.enStatus == TestSuiteStatuses.KnownIssue;
                //queriesList.Add((suite => suite.enStatus == TestSuiteStatuses.KnownIssue));
                cmdlet.FilterAll = false;
            }
            if (cmdlet.FilterAll) {
                query = suite => true;
            }
            // 20121006
            if (cmdlet.FilterNone) {
                query = suite => false;
                // 20130203
                //queriesList.Clear();
                //queriesList.Add(query);
            }

            // Ordering results

            // default result
            Func<TestSuite, object> ordering = suite => suite.Id;

            if (cmdlet.OrderByTimeSpent) {
                ordering += suite => suite.Statistics.TimeSpent;
            }
            if (cmdlet.OrderByName) {
                ordering += suite => suite.Name;
            }
            if (cmdlet.OrderById) {
                ordering += suite => suite.Id;
            }
            if (cmdlet.OrderByPassRate) {
                ordering += suite =>
                    {
                        // 20130322
                        //TMX.TestData.RefreshSuiteStatistics(suite);
                        TMX.TestData.RefreshSuiteStatistics(suite, cmdlet.FilterOutAutomaticResults);
                        return (suite.Statistics.Passed / suite.Statistics.All);
                    };
            }
            if (cmdlet.OrderByFailRate) {
                ordering += suite =>
                    {
                        // 20130322
                        //TMX.TestData.RefreshSuiteStatistics(suite);
                        TMX.TestData.RefreshSuiteStatistics(suite, cmdlet.FilterOutAutomaticResults);
                        return (suite.Statistics.Failed / suite.Statistics.All);
                    };
            }

            cmdlet.WriteVerbose(cmdlet, "query = " + query.ToString());
            cmdlet.WriteVerbose(cmdlet, "ordering = " + ordering.ToString());

            suites =
                TMX.TestData.SearchTestSuite(
                    // 20130203
                    query,
                    //Combine<TestSuite, bool>((x, y) => x && y, queriesList.ToArray()),
                    ordering,
                    cmdlet.Descending);

            return suites;
        }
Example #10
0
        public static void SearchForScenariosPS(SearchCmdletBase cmdlet)
        {
            IOrderedEnumerable<TestScenario> scenarios =
                SearchForScenarios(cmdlet);

            if (scenarios.Count<TMX.TestScenario>() > 0) {
                cmdlet.WriteObject(scenarios, true);
            } else {
                cmdlet.WriteObject(null);
            }
        }
Example #11
0
        //        public static Func<TInput, bool> Combine<TInput, Tout>
        //            (Func<bool, bool, bool> aggregator,
        //            params Func<TInput, bool>[] delegates) {
        //
        //            // delegates[0] provides the initial value
        //            return t => delegates.Skip(1).Aggregate(delegates[0](t), aggregator);
        //        }
        //
        ////        public static Func<T, bool> And<T>(params Func<T, bool>[] predicates) {
        ////            return Combine<T, bool>((x, y) => x && y, predicates);
        ////        }
        /// <summary>
        /// Performs parametrized search for Test Scenarios.
        /// </summary>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        public static IOrderedEnumerable<TestScenario> SearchForScenarios(SearchCmdletBase cmdlet)
        {
            IOrderedEnumerable<TestScenario> scenarios = null;

            // Filtering results

            // default result
            Func<TestScenario, bool> query = scenario => true;

            if (cmdlet.FilterNameContains != null && cmdlet.FilterNameContains.Length > 0) {
                query = scenario => scenario.Name.Contains(cmdlet.FilterNameContains);
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterIdContains != null && cmdlet.FilterIdContains.Length > 0) {
                query = scenario => scenario.Id.Contains(cmdlet.FilterIdContains);
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterDescriptionContains != null && cmdlet.FilterDescriptionContains.Length > 0) {
                query = scenario =>
                    {
                        if (scenario.Description != null) {
                            return scenario.Description.Contains(cmdlet.FilterDescriptionContains);
                        }
                        return false;
                    };
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterPassed) {
                query = scenario => scenario.enStatus == TestScenarioStatuses.Passed;
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterFailed) {
                query = scenario => scenario.enStatus == TestScenarioStatuses.Failed;
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterNotTested) {
                query = scenario => scenario.enStatus == TestScenarioStatuses.NotTested;
                cmdlet.FilterAll = false;
            } else if (cmdlet.FilterPassedWithBadSmell) {
                query = scenario => scenario.enStatus == TestScenarioStatuses.KnownIssue;
                cmdlet.FilterAll = false;
            }
            if (cmdlet.FilterAll) {
                query = scenario => true;
            }
            // 20121006
            if (cmdlet.FilterNone) {
                query = scenario => false;
            }

            // Ordering results

            // default result
            Func<TestScenario, object> ordering = scenario => scenario.Id;

            if (cmdlet.OrderByTimeSpent) {
                ordering = scenario => scenario.Statistics.TimeSpent;
            } else if (cmdlet.OrderByName) {
                ordering = scenario => scenario.Name;
            } else if (cmdlet.OrderById) {
                ordering = scenario => scenario.Id;
            } else if (cmdlet.OrderByPassRate) {
                ordering = scenario =>
                    scenario.Statistics.Passed /
                        (scenario.Statistics.Passed + scenario.Statistics.Failed +
                        scenario.Statistics.PassedButWithBadSmell + scenario.Statistics.NotTested);
            } else if (cmdlet.OrderByFailRate) {
                ordering = scenario =>
                    scenario.Statistics.Failed /
                        (scenario.Statistics.Passed + scenario.Statistics.Failed +
                        scenario.Statistics.PassedButWithBadSmell + scenario.Statistics.NotTested);
            }

            cmdlet.WriteVerbose(cmdlet, "query = " + query.ToString());
            cmdlet.WriteVerbose(cmdlet, "ordering = " + ordering.ToString());

            scenarios =
                TMX.TestData.SearchTestScenario(
                    query,
                    ordering,
                    cmdlet.Descending);

            return scenarios;
        }