/// <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); }