public static IEnumerable <XamlTestInfoBlock> TestStrings(object suiteInstance, bool excludeKnownFailures) { Type testClass = suiteInstance.GetType(); foreach (FieldInfo field in testClass.GetFields(fieldBF)) { if (IsTestXamlString(field)) { var testKnownFailureAttr = GetTestKnownFailureAttribute(field); if (excludeKnownFailures && testKnownFailureAttr != null) { Console.WriteLine($"Excluding known failure: XamlString:{field.Name} Owner:{testKnownFailureAttr.Reason}"); continue; // Exclude Known Failures } string xamlString = field.GetValue(suiteInstance) as string; MethodInfo loadMethod, validateMethod; XamlStringParser loader = null; PostTreeValidator validator = null; Type expectedExceptionType; if (!HasAlternateXamlLoader(field, out loadMethod)) { loadMethod = TestFinder.StandardXamlLoadMethod(suiteInstance); } loader = Delegate.CreateDelegate(typeof(XamlStringParser), suiteInstance, loadMethod, true) as XamlStringParser; if (HasTreeValidator(field, out validateMethod)) { validator = Delegate.CreateDelegate(typeof(PostTreeValidator), suiteInstance, validateMethod, true) as PostTreeValidator; } expectedExceptionType = GetExpectedException(field); string name = String.Format("{0}.{1}", testClass.Name, field.Name); var testBlock = new XamlTestInfoBlock(name, xamlString, loader, validator, expectedExceptionType); if (testKnownFailureAttr != null) { testBlock.IsTestKnownFailure = true; testBlock.OwnerName = testKnownFailureAttr.Reason; } yield return(testBlock); } } }
public static IEnumerable <XamlTestInfoBlock> TestMethods(object suiteInstance, bool excludeKnownFailures) { Type testClass = suiteInstance.GetType(); SimpleTest setup = null; foreach (MethodInfo method in testClass.GetMethods(methodBF)) { if (IsSetupMethod(method)) { setup = (SimpleTest)Delegate.CreateDelegate(typeof(SimpleTest), suiteInstance, method, true); break; //take the first setup method it finds } } foreach (MethodInfo method in testClass.GetMethods(methodBF)) { if (IsTestMethod(method)) { var testKnownFailureAttr = GetTestKnownFailureAttribute(method); if (excludeKnownFailures && testKnownFailureAttr != null) { Console.WriteLine($"Excluding known failure: Method: {method.Name} Owner: {testKnownFailureAttr.Reason}"); continue; // Exclude Known Failures } SimpleTest test = (SimpleTest)Delegate.CreateDelegate(typeof(SimpleTest), suiteInstance, method, true); if (setup != null) { test = (SimpleTest)Delegate.Combine(setup, test); } string name = String.Format("{0}.{1}", testClass.Name, method.Name); Type expectedExceptionType = GetExpectedException(method); var testBlock = new XamlTestInfoBlock(name, test, expectedExceptionType); if (testKnownFailureAttr != null) { testBlock.IsTestKnownFailure = true; testBlock.OwnerName = testKnownFailureAttr.Reason; } yield return(testBlock); } } }