Ejemplo n.º 1
0
        /// <summary>
        /// Break out results for a single test and raise event
        /// </summary>
        /// <param name="xmlResult">source of result data</param>
        private void ProcessTest(System.Xml.XmlNode xmlResult)
        {
            TestResult testResult = new TestResult();

            testResult.Location = GetAttribute(xmlResult, "name");
            string rawResult = string.Empty;

            switch (GetAttribute(xmlResult, "result"))
            {
            case "Fail":
                rawResult = xmlResult.InnerText;

                testResult.Status                   = TestStatus.Failed;
                testResult.Duration                 = GetAttribute(xmlResult, "time");
                testResult.Failure.Expected         = GetExpected(rawResult);
                testResult.Failure.Actual           = GetActual(rawResult);
                testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, GetLineNumber(rawResult));
                testResult.Failure.ActualDiffersAt  = GetPosition(rawResult);
                break;

            case "Pass":
                testResult.Status   = TestStatus.Passed;
                testResult.Duration = GetAttribute(xmlResult, "time");
                break;

            case "Skip":
                testResult.Status = TestStatus.Skipped;
                break;
            }
            RaiseComplete(rawResult, testResult);
        }
Ejemplo n.º 2
0
        private static void ParseFailure(string testCase, TestResult result)
        {
            if (result.Status == TestStatus.Failed)
            {
                string kExpectedStartDelimiter = "Expected: ";
                string kActualStartDelimiter   = "But was:  ";
                int    expectedStart           = testCase.IndexOf(kExpectedStartDelimiter, testCase.IndexOf("<message"));
                if (expectedStart > 0)
                {
                    int actualStart = testCase.IndexOf(kActualStartDelimiter, expectedStart);
                    result.Failure.Expected = testCase.Substring(expectedStart + kExpectedStartDelimiter.Length, actualStart - expectedStart - kExpectedStartDelimiter.Length);

                    int actualEnd = testCase.IndexOf('\"', actualStart + kActualStartDelimiter.Length + 1) + 1;
                    if (actualEnd == 0)
                    {
                        actualEnd = testCase.IndexOf("]]", actualStart);
                    }
                    result.Failure.Actual = testCase.Substring(actualStart + kActualStartDelimiter.Length, actualEnd - actualStart - kActualStartDelimiter.Length);

                    if (testCase.Contains("CDATA[  String"))
                    {
                        int differStart = testCase.LastIndexOf(' ', expectedStart) + 1;
                        result.Failure.ActualDiffersAt = int.Parse(testCase.Substring(differStart, expectedStart - differStart - 1));
                    }

                    const string kLineStartDelimiter = ":line ";
                    int          lineStart           = testCase.LastIndexOf(kLineStartDelimiter) + kLineStartDelimiter.Length;
                    int          lineEnd             = testCase.IndexOf("]]", lineStart);
                    int          lineNumber          = int.Parse(testCase.Substring(lineStart, lineEnd - lineStart));
                    result.Failure.FailingStatement = DxCoreUtil.GetStatement(result.Location, lineNumber);
                }
            }
        }
Ejemplo n.º 3
0
 private void PlugIn1_TextChanged(TextChangedEventArgs ea)
 {
     if (_currentTestData != null && _currentTestData.Result.Status != TestStatus.Unknown)
     {
         _currentTestData.Result = new TestResult();
         DxCoreUtil.Invalidate(_currentTestData.Method);
     }
 }
Ejemplo n.º 4
0
 private void PlugIn1_OptionsChanged(OptionsChangedEventArgs ea)
 {
     if (ea.OptionsPages.Contains(typeof(OptRedGreenPlugIn)))
     {
         LoadSettings();
         DxCoreUtil.Invalidate(CodeRush.Source.ActiveClass);
     }
 }
Ejemplo n.º 5
0
 private void PlugIn1_LanguageElementActivated(LanguageElementActivatedEventArgs ea)
 {
     if (ea.Element.InsideMethod)
     {
         Method method = DxCoreUtil.GetMethod(ea.Element);
         _currentTestData = _Tests.Find(test => test.Method == method);
     }
 }
Ejemplo n.º 6
0
 public UnitTestDetail(string location, SmartTagProvider tagProvider)
     : this()
 {
     Location = location;
     try
     {
         _method = DxCoreUtil.GetMethod(location);
     }
     catch
     {// fail silently, try to get it later
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Attempt to locate the Test attribute for the given language element
 /// </summary>
 private static Attribute GetTestAttributeForLanguageElement(LanguageElement languageElement)
 {
     if (languageElement.ElementType == LanguageElementType.Attribute && RunnerFactory.IsTest((Attribute)languageElement))
     {
         return((Attribute)languageElement);
     }
     else if (languageElement.ElementType == LanguageElementType.MethodCall)
     {
         return(DxCoreUtil.GetFirstTestAttribute(languageElement));
     }
     return(null);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Handle the end of tests event
        /// </summary>
        private void runner_AllTestsComplete(object sender, AllTestsCompleteEventArgs args)
        {
            string overview = string.Format("\n{0} passed, {1} failed, {2} skipped, duration: {3} seconds\n",
                                            args.PassCount,
                                            args.FailCount,
                                            args.SkipCount,
                                            args.Duration);

            WriteToTestPane(overview);
            CodeRush.Windows.Active.DTE.StatusBar.Text = overview;

            CreateFailedTestList();
            DxCoreUtil.Invalidate(CodeRush.Source.ActiveClass);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Look for information about the the attribute. Create and add an information point if none exists and this is a test attribute
        /// </summary>
        private UnitTestDetail FindDataForTest(Attribute testAttribute)
        {
            UnitTestDetail testData = _Tests.Find(test => test.Method.RootNamespaceLocation == testAttribute.TargetNode.RootNamespaceLocation);

            if (testData == null)
            {
                if (RunnerFactory.IsTest(testAttribute))                  // probably not needed because we can't get here unless GetFirstTestAttribute already performed the test, but not a bad safeguard.
                {
                    testData = new UnitTestDetail(DxCoreUtil.GetMethod(testAttribute.TargetNode), testActions);
                    _Tests.Add(testData);
                }
                ;
            }
            return(testData);
        }
Ejemplo n.º 10
0
        public TestResult ParseTest(string rawResult)
        {
            int    statusEnd   = rawResult.IndexOf(' ');
            int    kindEnd     = rawResult.IndexOf(' ', statusEnd + 1);
            int    engineEnd   = rawResult.IndexOf(' ', kindEnd + 1);
            int    versionEnd  = rawResult.IndexOf('/', engineEnd + 1);
            int    locationEnd = rawResult.IndexOf('\n', versionEnd + 1);
            string status      = rawResult.Substring(1, statusEnd - 2);
            string kind        = rawResult.Substring(statusEnd + 1, kindEnd - statusEnd - 1);
            string engine      = rawResult.Substring(kindEnd + 1, engineEnd - kindEnd - 1);
            string location    = rawResult.Substring(versionEnd + 1, locationEnd - versionEnd - 1);

            TestResult testResult = new TestResult();

            if (kind == ResultKind.Test)
            {
                IGallioResultParser helper = _parserFactory.GetParser(engine);

                testResult.Location = helper.ReformatLocation(location);

                switch (status.ToLower())
                {
                case Status.Failed:
                case Status.Error:
                    testResult.Status   = TestStatus.Failed;
                    testResult.Duration = string.Empty;
                    string content = rawResult.Substring(locationEnd);
                    testResult.Failure.Expected         = helper.GetExpected(content);
                    testResult.Failure.Actual           = helper.GetActual(content);
                    testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, helper.GetLineNumber(content));
                    testResult.Failure.ActualDiffersAt  = helper.GetPosition(content, testResult.Failure.Expected, testResult.Failure.Actual);
                    break;

                case Status.Passed:
                    testResult.Status   = TestStatus.Passed;
                    testResult.Duration = string.Empty;
                    break;

                default:
                case Status.Skipped:
                case Status.Ignored:
                    testResult.Status = TestStatus.Skipped;
                    break;
                }
            }
            return(testResult);
        }
Ejemplo n.º 11
0
        public TestResult ParseTest(string rawResult)
        {
            string header   = rawResult.Substring(0, rawResult.IndexOf('\n'));
            string status   = Regex.Match(header, @"\w+").Value;
            string kind     = Regex.Match(header, @"\]\s\w+").Value.Substring(2);
            string location = header.Substring(header.LastIndexOf(' ') + 1);

            TestResult testResult = new TestResult();

            if (kind == ResultKind.Test)
            {
                //IGallioResultParser helper = _parserFactory.GetParser(engine);

                testResult.Location = location.Replace('/', '.');

                switch (status.ToLower())
                {
                case Status.Failed:
                case Status.Error:
                    testResult.Status   = TestStatus.Failed;
                    testResult.Duration = string.Empty;
                    string content = rawResult.Substring(rawResult.IndexOf('\n') + 1);
                    testResult.Failure.Expected         = GetExpected(content);
                    testResult.Failure.Actual           = GetActual(content);
                    testResult.Failure.FailingStatement = DxCoreUtil.GetStatement(testResult.Location, GetLineNumber(content));
                    testResult.Failure.ActualDiffersAt  = GetPosition(content, testResult.Failure.Expected, testResult.Failure.Actual);
                    break;

                case Status.Passed:
                    testResult.Status   = TestStatus.Passed;
                    testResult.Duration = string.Empty;
                    break;

                default:
                case Status.Skipped:
                case Status.Ignored:
                    testResult.Status = TestStatus.Skipped;
                    break;
                }
            }
            return(testResult);
        }
Ejemplo n.º 12
0
        private void actRunTests_Execute(ExecuteEventArgs ea)
        {
            ResetTestResults();

            string className = CodeRush.Source.ActiveClass.FullName;

            if (CodeRush.Source.ActiveMethod != null)
            {// Handle trigger in method
                string    methodName    = CodeRush.Source.ActiveMethod.Name;
                Attribute testAttribute = DxCoreUtil.GetFirstTestAttribute(CodeRush.Source.ActiveMethod);
                if (testAttribute != null)
                {
                    StandardRunTestBehavior(RunnerFactory.CreateRunnerFromTestAttribute(testAttribute.GetDeclaration().FullName),
                                            (run, assemblyPath, assemblyName) => run.RunTests(assemblyPath, assemblyName, className, methodName));
                }
            }
            else
            {// Handle trigger in class
                string fixtureAttribute = CodeRush.Source.ActiveClass.AttributeCount > 0 ? ((Attribute)CodeRush.Source.ActiveClass.Attributes[0]).GetDeclaration().FullName : string.Empty;
                StandardRunTestBehavior(RunnerFactory.CreateRunnerFromFixtureAttribute(fixtureAttribute),
                                        (run, assemblyPath, assemblyName) => run.RunTests(assemblyPath, assemblyName, className));
            }
        }