public ParsedResult ParseResults(List <TestResult> results)
        {
            ParsedResult parsedResult = new ParsedResult();

            parsedResult.Parse(results);
            return(parsedResult);
        }
 public ParsedResult ParseResults(List<TestResult> results)
 {
     ParsedResult parsedResult = new ParsedResult();
     parsedResult.Parse(results);
     return parsedResult;
 }
Beispiel #3
0
        /// <summary>
        /// Verify some rules as base test case
        /// </summary>
        /// <param name="verifyWithNegativeList">The verify and negative rule list for every request element</param>
        protected void VerifyRules_BaseTestCase(List <ValidationElement> verifyWithNegativeList)
        {
            if (verifyWithNegativeList == null || verifyWithNegativeList.Count < 1)
            {
                return;
            }

            #region Definition for params

            int           ruleCount                             = 0;
            string        url                                   = string.Empty;
            string        format                                = string.Empty;
            string        header                                = string.Empty;
            string        expectedResult                        = string.Empty;
            string        notInListTotal                        = string.Empty;
            Guid          jobID                                 = Guid.Empty;
            ParsedResult  parsedResult                          = null;
            List <string> verifyRules                           = null;
            List <string> failedRuleList                        = new List <string>();
            List <string> expectedTotalRuleList                 = new List <string>();
            List <string> actualTotalRuleList                   = new List <string>();
            List <string> negativeRuleList                      = new List <string>();
            List <ValidationService.TestResult> testResults     = null;
            Dictionary <List <string>, string>  negativeRuleDic = null;

            #endregion

            #region Create test result file

            string fileName             = string.Format("{0}_TestResult.txt", TestContext.TestName);
            string folderPath           = GetTestResultFolderPathByCurrentDirectory();
            System.IO.StreamWriter file = this.CreateTestResultFile(folderPath, fileName);
            string filePath             = string.Format("{0}\\{1}", folderPath, fileName);
            file.WriteLine(string.Format("------Start Test Case {0}------", TestContext.TestName));

            #endregion

            #region Verify the expected rule list

            foreach (var overify in verifyWithNegativeList)
            {
                url             = overify.RequestEle.RequestUrl;
                format          = overify.RequestEle.RequestFormat;
                header          = overify.RequestEle.RequestHeader;
                verifyRules     = overify.PassRuleList;
                negativeRuleDic = overify.NegativeRuleDic;

                if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(format) || string.IsNullOrEmpty(header) || verifyRules == null || verifyRules.Count < 1)
                {
                    continue;
                }

                jobID = this.adapter.SendRequest(url, format, null, header, null, isVerifyMetadata, null)[0];
                Site.Assert.IsTrue(jobID != Guid.Empty, "No JobGroup is generated.");

                if (this.adapter.IsJobCompleted(jobID, out ruleCount))
                {
                    testResults = this.adapter.GetTestResults(jobID);
                    Site.Assert.IsTrue(testResults.Count == ruleCount,
                                       string.Format("Job Verification Result - There should be {0} rules verified but actually get {1} rules.", ruleCount, testResults.Count));

                    parsedResult = this.adapter.ParseResults(testResults);
                }

                foreach (var rule in verifyRules)
                {
                    if (!expectedTotalRuleList.Contains(rule))
                    {
                        expectedTotalRuleList.Add(rule);
                    }

                    Site.Log.Add(LogEntryKind.Debug, "Verify " + rule);
                    if (!parsedResult.RuleNameAndResult.ContainsKey(rule))
                    {
                        file.WriteLine("{0}:\tNot in DB", rule);
                        continue;
                    }
                    if (ValidationResultConstants.Success != parsedResult.RuleNameAndResult[rule])
                    {
                        file.WriteLine("{0}:\t{1}", rule, parsedResult.RuleNameAndResult[rule] + '\t' + parsedResult.RuleNameAndDescription[rule]);
                        failedRuleList.Add(rule);
                        continue;
                    }
                    Site.CaptureRequirementIfAreEqual(
                        ValidationResultConstants.Success,
                        parsedResult.RuleNameAndResult[rule],
                        this.GetRuleTypeConstantsByRuleName(rule) + Int32.Parse(rule.Split('.')[2]),
                        parsedResult.RuleNameAndDescription[rule]);
                }

                foreach (var rule in parsedResult.RuleNameAndResult.Keys)
                {
                    if (!actualTotalRuleList.Contains(rule) && rule.Split('.')[2].StartsWith("4"))
                    {
                        actualTotalRuleList.Add(rule);
                    }
                }

                #region Verify negative rule list

                if (negativeRuleDic != null)
                {
                    foreach (var okey in negativeRuleDic)
                    {
                        if (okey.Key == null)
                        {
                            continue;
                        }

                        foreach (string rule in okey.Key)
                        {
                            expectedResult = okey.Value;
                            Site.Log.Add(LogEntryKind.Debug, "Verify " + rule);
                            Site.Assert.IsTrue(parsedResult.RuleNameAndResult.ContainsKey(rule),
                                               string.Format("The expected rule {0} does not exist in database.", rule));

                            Site.CaptureRequirementIfAreEqual(
                                expectedResult,
                                parsedResult.RuleNameAndResult[rule],
                                this.GetRuleTypeConstantsByRuleName(rule) + Int32.Parse(rule.Split('.')[2]),
                                parsedResult.RuleNameAndDescription[rule]);

                            if (!negativeRuleList.Contains(rule))
                            {
                                negativeRuleList.Add(rule);
                            }
                        }
                    }
                }

                #endregion
            }

            #endregion

            #region Summary the test result and output in file

            file.WriteLine();
            file.WriteLine("Summary:");
            file.WriteLine("Expected {0} rules executed, actually {1} rules executed, {3} negative rules not verified, fail Count {2}.",
                           expectedTotalRuleList.Count + negativeRuleList.Count, actualTotalRuleList.Count, failedRuleList.Count, negativeRuleList.Count);

            foreach (string act in actualTotalRuleList)
            {
                if (!expectedTotalRuleList.Contains(act) && !negativeRuleList.Contains(act))
                {
                    notInListTotal += act + " ";
                }
            }
            if (!string.IsNullOrEmpty(notInListTotal))
            {
                file.WriteLine();
                file.WriteLine("Not in rule LIST:\t {0}", notInListTotal);
            }
            file.Close();

            if (this.adapter.GetRulesCountByRequirementLevel(failedRuleList, filePath))
            {
                Site.Assert.Fail("There are {0} rules failed, for detail, please check the failure result from file:\n{1}.", failedRuleList.Count, filePath);
            }

            #endregion
        }