private void PlugIn1_LanguageElementActivated(LanguageElementActivatedEventArgs ea) { if (ea.Element.InsideMethod) { Method method = DxCoreUtil.GetMethod(ea.Element); _currentTestData = _Tests.Find(test => test.Method == method); } }
/// <summary> /// Draw all the test attributes the same and put the status color in the background /// </summary> private void RedrawTestAttribute(EditorPaintEventArgs paintArgs, UnitTestDetail testData) { if (paintArgs.LineInView(testData.Attribute.StartLine) && testData.Result.Status != TestStatus.Unknown) { Point topLeft = paintArgs.TextView.GetPoint(testData.Attribute.StartLine, testData.Attribute.Parent.StartOffset); Point lowerRight = paintArgs.TextView.GetPoint(testData.Attribute.StartLine + 1, paintArgs.TextView.LengthOfLine(testData.Method.StartLine) + 1); Rectangle area = new Rectangle(topLeft.X, topLeft.Y, lowerRight.X - topLeft.X, lowerRight.Y - topLeft.Y); using (Brush b = new SolidBrush(GetBackgroundColor(testData.Result.Status))) { paintArgs.Graphics.FillRectangle(b, area); } } }
/// <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); }
/// <summary> /// Put up the action tile /// redraw the test attribute /// Draw the parsed error text if we can /// </summary> private void PlugIn1_EditorPaintLanguageElement(EditorPaintLanguageElementEventArgs ea) { Attribute testAttribute = GetTestAttributeForLanguageElement(ea.LanguageElement); if (testAttribute != null) { UnitTestDetail testData = FindDataForTest(testAttribute); if (testData != null) { if (ea.LanguageElement.ElementType == LanguageElementType.Attribute) { DrawTestRunnerIcon(ea.PaintArgs, testData); RedrawTestAttribute(ea.PaintArgs, testData); } else { DrawError(ea, testData.Result); } } } }
/// <summary> /// Handle the a test is complete event /// </summary> private void runner_TestComplete(object sender, TestCompleteEventArgs args) { WriteToTestPane(args.RawResult, true); if (args.Result != null && args.Result.Location != null) {// Only UnitTests have a result. // Trim off the parens if they exist, the will for Theory string location = args.Result.Location.EndsWith(")") == false ? args.Result.Location : args.Result.Location.Substring(0, args.Result.Location.LastIndexOf('(')); UnitTestDetail testData = _Tests.Find(test => test.Method.RootNamespaceLocation == location); if (testData == null) { testData = new UnitTestDetail(args.Result.Location, testActions); if (testData.Method != null) {// Don't lest bad data in _Tests.Add(testData); } } testData.Result = args.Result; } }
/// <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; }
/// <summary> /// Fetches the document name or the class name if the document name is not available. /// </summary> static string GetTestPath(UnitTestDetail test) { return test.Method.Document != null ? test.Method.Document.FullName : test.ClassName; }
/// <summary> /// Handle the a test is complete event /// </summary> private void runner_TestComplete(object sender, TestCompleteEventArgs args) { WriteToTestPane(args.RawResult, true); if (args.Result != null && args.Result.Location != null) {// Only UnitTests have a result. // Trim off the parens if they exist, the will for Theory string location = args.Result.Location.EndsWith(")") == false ? args.Result.Location : args.Result.Location.Substring(0, args.Result.Location.LastIndexOf('(')) ; UnitTestDetail testData = _Tests.Find(test => test.Method.RootNamespaceLocation == location); if (testData == null) { testData = new UnitTestDetail(args.Result.Location, testActions); if (testData.Method != null) {// Don't lest bad data in _Tests.Add(testData); } } testData.Result = args.Result; } }
/// <summary> /// Move the cursor to the next error and use a beacon to highlight the move /// </summary> private void MoveToNextFailure(object sender, System.EventArgs ea) { UnitTestDetail nextLocation = LocateNextTest(); MoveToTest(nextLocation.Method); }
/// <summary> /// Fetches the document name or the class name if the document name is not available. /// </summary> static string GetTestPath(UnitTestDetail test) { return(test.Method.Document != null ? test.Method.Document.FullName : test.ClassName); }