/// <summary> /// Apply tag filtering. /// </summary> /// <param name="classes">List of test classes.</param> /// <param name="instances">Test class instance dictionary.</param> protected override void FilterCustomTestClasses(IList <ITestClass> classes, TestClassInstanceDictionary instances) { if (string.IsNullOrEmpty(TagExpression)) { return; } // Temporarily apply to the methods as well. If the class has no // methods that were matched in the expression, then cut the // class from the run. List <ITestClass> emptyTests = new List <ITestClass>(); foreach (ITestClass test in classes) { object instance = instances.GetInstance(test.Type); ICollection <ITestMethod> methods = GetTestMethods(test, instance); TagManager tm = new TagManager(test.Type, methods); ApplyExpression(tm, methods); if (methods.Count == 0) { emptyTests.Add(test); } } if (emptyTests.Count > 0) { foreach (ITestClass test in emptyTests) { classes.Remove(test); } } if (!_hasLoggedWarning) { UnitTestHarness.LogWriter.Information(string.Format(CultureInfo.InvariantCulture, Properties.UnitTestMessage.TagTestRunFilter_TaggingInUse, TagExpression)); _hasLoggedWarning = true; } }
/// <summary> /// Apply tag filtering. /// </summary> /// <param name="classes">List of test classes.</param> /// <param name="instances">Test class instance dictionary.</param> protected override void FilterCustomTestClasses(IList<ITestClass> classes, TestClassInstanceDictionary instances) { if (string.IsNullOrEmpty(TagExpression)) { return; } // Temporarily apply to the methods as well. If the class has no // methods that were matched in the expression, then cut the // class from the run. List<ITestClass> emptyTests = new List<ITestClass>(); foreach (ITestClass test in classes) { object instance = instances.GetInstance(test.Type); ICollection<ITestMethod> methods = GetTestMethods(test, instance); TagManager tm = new TagManager(test.Type, methods); ApplyExpression(tm, methods); if (methods.Count == 0) { emptyTests.Add(test); } } if (emptyTests.Count > 0) { foreach (ITestClass test in emptyTests) { classes.Remove(test); } } if (!_hasLoggedWarning) { UnitTestHarness.LogWriter.Information(string.Format(CultureInfo.InvariantCulture, Properties.UnitTestMessage.TagTestRunFilter_TaggingInUse, TagExpression)); _hasLoggedWarning = true; } }
/// <summary> /// Apply the tag filtering. /// </summary> /// <param name="tagManager">The tag manager instance.</param> /// <param name="methods">Set of methods.</param> private void ApplyExpression(TagManager tagManager, ICollection<ITestMethod> methods) { List<ITestMethod> original = new List<ITestMethod>(methods); methods.Clear(); tagManager.EvaluateExpression(TagExpression); foreach (ITestMethod method in tagManager.EvaluateExpression(TagExpression)) { if (original.Contains(method)) { methods.Add(method); } } }
/// <summary> /// Apply tag filtering. /// </summary> /// <param name="methods">List of test methods.</param> protected override void FilterCustomTestMethods(IList<ITestMethod> methods) { if (methods == null || methods.Count == 0 || string.IsNullOrEmpty(TagExpression)) { return; } TagManager tm = new TagManager(methods[0].Method.ReflectedType, methods); ApplyExpression(tm, methods); }
/// <summary> /// Evaluate a tag expression. /// </summary> /// <param name="owner">The owner object.</param> /// <param name="tagExpression">Tag expression.</param> /// <returns>Test methods associated with the tag expression.</returns> public static IEnumerable<ITestMethod> Evaluate(TagManager owner, string tagExpression) { return new ExpressionEvaluator(owner, tagExpression).Evaluate(); }
/// <summary> /// Create an expression evaluator. /// </summary> /// <param name="owner">The owner object.</param> /// <param name="tagExpression">Expression object.</param> private ExpressionEvaluator(TagManager owner, string tagExpression) { if (tagExpression == null) { throw new ArgumentNullException("tagExpression"); } else if (tagExpression.Length == 0) { throw new ArgumentException(Properties.UnitTestMessage.TagManager_ExpressionEvaluator_EmptyTagExpression, "tagExpression"); } _owner = owner; _tagExpression = tagExpression; }
/// <summary> /// Evaluate a tag expression. /// </summary> /// <param name="owner">The owner object.</param> /// <param name="tagExpression">Tag expression.</param> /// <returns>Test methods associated with the tag expression.</returns> public static IEnumerable <ITestMethod> Evaluate(TagManager owner, string tagExpression) { return(new ExpressionEvaluator(owner, tagExpression).Evaluate()); }