Example #1
0
 public CTestResultEventArgs(CTestCase aTestCase,
                             IEnumerable <CTestResult> aTestResults)
 {
     this.TestCase    = aTestCase;
     this.TestResults = aTestResults;
 }
Example #2
0
        private void ParseControlFile(string testCaseNamePrefix, string controlFile, string[] filters, string defaultSection, XElement topNode, MyDict <string, object> masterList, IList xmlDriverParams)
        {
            // load the control file
            XDocument doc = LoadControlFile(controlFile);

            // parse test module top node
            XElement testModuleNode = doc.Element("TestModule");

            AddBuiltInAttributes(testModuleNode);
            XElement testModuleVirtualNode = (topNode == null) ? testModuleNode :
                                             BuildVirtualNode(new XElement(topNode), testModuleNode);
            string testModuleName        = SelectExistingAttributeValue(testModuleNode, "Name");
            string testModuleCreated     = SelectExistingAttributeValue(testModuleNode, "Created");
            string testModuleModified    = SelectExistingAttributeValue(testModuleNode, "Modified");
            string testModuleDescription = SelectDescription(testModuleNode);

            CXmlDriverParamRawNodes testModuleParam = new CXmlDriverParamRawNodes_TestModule(testModuleNode, testModuleVirtualNode, null);

            xmlDriverParams.Add(new CXmlDriverParam(testModuleParam, defaultSection));

            // process includes
            ProcessIncludes(filters, defaultSection, testModuleNode, masterList, xmlDriverParams);

            // filter xPath
            string filterXPath = CombineXPath(filters);

            // loop through all test cases
            foreach (XElement testCaseNode in testModuleNode.Elements("TestCase"))
            {
                string testCaseName = SelectExistingAttributeValue(testCaseNode, "Name");
                if (testCaseNamePrefix != null && testCaseNamePrefix != "")
                {
                    testCaseName = testCaseNamePrefix + "_" + testCaseName;
                }
                string testCaseDescription = SelectDescription(testCaseNode);

                XElement testCaseVirtualNode          = null;
                CXmlDriverParamRawNodes testCaseParam = new CXmlDriverParamRawNodes_TestCase(testCaseNode, testCaseVirtualNode, testModuleParam);

                // create a test case class
                CTestCase testCase = CreateTestCase(testCaseName, testCaseDescription, new CXmlDriverParam(testCaseParam, defaultSection));

                // loop through all variations
                int varCount    = 0;
                int actVarCount = 0;
                foreach (XElement varNode in testCaseNode.Elements("Variation"))
                {
                    varCount++;
                    string   varId          = SelectExistingAttributeValue(varNode, "Id");
                    string   varName        = SelectName(varNode);
                    string   varPri         = SelectPriority(varNode);
                    XElement varVirtualNode = null;

                    // check filter
                    CXmlDriverParamRawNodes varParam = new CXmlDriverParamRawNodes_Variation(varNode, varVirtualNode, testCaseParam);
                    if (!CheckFilter(varParam, filterXPath))
                    {
                        continue;
                    }

                    // create a new variation and add it to the current testCase
                    actVarCount++;
                    string varDescription   = SelectDescription(varNode);
                    CXmlDriverVariation var = new CXmlDriverVariation((CXmlDriverScenario)testCase,
                                                                      varName, varDescription, Int32.Parse(varId), Int32.Parse(varPri),
                                                                      new CXmlDriverParam(varParam, defaultSection));
                    testCase.AddVariation(var);
                }

                if (actVarCount == 0 && varCount > 0)
                {
                    // no 'implemented' variations satisfying the filter
                    testCase = new CXmlDriverEmptyTestCase(testCaseName, testCaseDescription,
                                                           " no variations with @Implemented='True' " +
                                                           (_requiredLanguage != null && _requiredLanguage.Length != 0 ? " and @Language='" + _requiredLanguage + "'" : "") +
                                                           (filterXPath == null ? "" : " and satisfying '" + filterXPath + "'"), _testModule);
                }

                // add test case
                _testModule.AddTestCase(testCase);
            }
        }
Example #3
0
        public void Run(CTestCase aTestCase)
        {
            var aReport       = this.Report;
            var aTestSequence = this.TestSequence;

            var aDir               = this.TestCasesDirectoryInfo;
            var aTestInterceptor   = this.TestInterceptor;
            var aInterceptTemplate = new Action <CTestResultEventArgs>(delegate(CTestResultEventArgs aArgs)
            {
                aTestInterceptor.Accepted = (bool)aArgs.TestResult.Dyn().Ok;
                aTestInterceptor.OnIntercept(aArgs);
                if (!aTestInterceptor.Accepted)
                {
                    throw new Exception("TestCase interceptur did not accept.");
                }
            });


            var aInModelFileInfo = new FileInfo(Path.Combine(aDir.FullName, aTestCase.Name + "-in.xdl"));
            var aOutTestFileInfo = new FileInfo(Path.Combine(aDir.FullName, aTestCase.Name + "-out-test.cs"));
            var aOutOkFileInfo   = new FileInfo(Path.Combine(aDir.FullName, aTestCase.Name + "-out-ok.cs"));

            System.Diagnostics.Debug.Print("Running Test: " + aTestCase.Name);

            if (aInModelFileInfo.Exists)
            {
                var aGenerator = new CCodeGenerator(new CGenModelInterpreter(),
                                                    new CGenTokens(),
                                                    new CCodeDomBuilder(),
                                                    aInModelFileInfo,
                                                    null,
                                                    aOutTestFileInfo,
                                                    null);
                var aTestCaseId   = aTestCase.Name;
                var aNamespace    = "Test" + aTestCaseId.Replace("-", "_");
                var aNamespaceRow = CRflRow.New(string.Empty, string.Empty, this.Tok.Mdl_G_A_Nsp_Nme, aNamespace);
                var aSchemaRow    = CRflRow.New(string.Empty, string.Empty, this.Tok.Mdl_G_A_ModelName, "Test");
                aGenerator.Exp.ChainedExpanders.Add(new CRowsExpander(aNamespaceRow, aSchemaRow));
                aGenerator.GenerateCode();

                var aOutTestLines = File.ReadAllLines(aOutTestFileInfo.FullName);
                if (!aOutTestFileInfo.Exists)
                {
                    System.Diagnostics.Debugger.Break(); // First Test detected. Continue to accept.
                    File.WriteAllLines(aOutTestFileInfo.FullName, aOutTestLines);
                }
                else if (!aOutOkFileInfo.Exists)
                {
                    System.Diagnostics.Debugger.Break(); // First Test-Validation detected. Continue to accept.
                    File.WriteAllLines(aOutOkFileInfo.FullName, aOutTestLines);
                }
                else
                {
                    try
                    {
                        Action aAcceptAction;
                        var    aTestResults = new List <CTestResult>();
                        var    aOkLines     = File.ReadAllLines(aOutOkFileInfo.FullName);
                        if (aOutTestLines.Length != aOkLines.Length)
                        {
                            aTestResults.Add(CTestResultBuilder.NewTestResult(aTestCase, false, default(int?), "Number of generated rows missmatch."));
                            aAcceptAction = new Action(delegate() { File.WriteAllLines(aOutOkFileInfo.FullName, aOutTestLines); });
                        }
                        else
                        {
                            var aLinePairs = from aIdx in Enumerable.Range(0, aOutTestLines.Length) select new Tuple <int, string, string>(aIdx, aOkLines[aIdx], aOutTestLines[aIdx]);
                            var aFirstDiff = (from aTest in aLinePairs
                                              where aTest.Item2 != aTest.Item3
                                              select aTest).FirstOrDefault();
                            if (aFirstDiff.IsNullRef())
                            {
                                var aTestMethods = new CGenTestMethods();
                                var aExcNullable = aTestMethods.RunTests(aTestCase);
                                aTestResults.AddRange(aTestMethods.TestResults);
                                aTestResults.Add(CTestResultBuilder.NewTestResult(aTestCase, aExcNullable.IsNullRef(), default, aExcNullable.IsNullRef() ? string.Empty : aExcNullable.Message));