/// <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); }
/// <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> /// Attempts to get the attribute attached the the parent method that is a test attribute /// </summary> public static Attribute GetFirstTestAttribute(LanguageElement element) { Method method = GetMethod(element); if (method != null && method.AttributeCount > 0) { foreach (Attribute attribute in method.Attributes) { if (RunnerFactory.IsTest(attribute)) { return(attribute); } } } return(null); }
/// <summary> /// Respond to a SmartTagMenuItem selection and run the appropriate set of tests /// </summary> private void PlugIn1_RunTest(object sender, System.EventArgs ea) { ResetTestResults(); string testAttributeName = ((UnitTestDetail)_hoveredTest).Attribute.GetDeclaration().FullName; BaseTestRunner runner = RunnerFactory.CreateRunnerFromTestAttribute(testAttributeName); switch (((SmartTagItem)sender).Caption) { case kRunAssemblyMenuItem: StandardRunTestBehavior(runner, (run, assemblyPath, assemblyName) => run.RunTests(assemblyPath, assemblyName)); break; case kRunClassMenuItem: StandardRunTestBehavior(runner, (run, assemblyPath, assemblyName) => run.RunTests(assemblyPath, assemblyName, _hoveredTest.ClassName)); break; case kRunTestMenuItem: StandardRunTestBehavior(runner, (run, assemblyPath, assemblyName) => run.RunTests(assemblyPath, assemblyName, _hoveredTest.ClassName, _hoveredTest.MethodName)); break; } }
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)); } }