public void Match_SingleCategory() { var filter = new CategoryFilter("Dummy"); Assert.That(filter.Match(_dummyFixture)); Assert.False(filter.Match(_anotherFixture)); }
public void Match_MultipleCategories() { var filter = new CategoryFilter(new string[] { "Dummy", "Another" }); Assert.That(filter.Match(_dummyFixture)); Assert.That(filter.Match(_anotherFixture)); Assert.False(filter.Match(_yetAnotherFixture)); }
public void CategoryFilterWithSpecialCharacters_ToXml_Regex() { TestFilter filter = new CategoryFilter("Special,Character-Fixture+!") { IsRegex = true }; Assert.That(filter.ToXml(false).OuterXml, Is.EqualTo("<cat re=\"1\">Special,Character-Fixture+!</cat>")); }
public void CategoryFilter_ToXml_Regex() { TestFilter filter = new CategoryFilter("CATEGORY") { IsRegex = true }; Assert.That(filter.ToXml(false).OuterXml, Is.EqualTo("<cat re=\"1\">CATEGORY</cat>")); }
public void ExplicitMatch_SingleCategory() { var filter = new CategoryFilter("Dummy"); Assert.That(filter.IsExplicitMatch(_topLevelSuite)); Assert.That(filter.IsExplicitMatch(_dummyFixture)); Assert.False(filter.IsExplicitMatch(_dummyFixture.Tests[0])); Assert.False(filter.IsExplicitMatch(_anotherFixture)); }
private CategoryFilter GetCategoryFilter() { CategoryFilter filter = new CategoryFilter(token); while (GetToken() == "," || token == ";") { filter.AddCategory(GetToken()); } return(filter); }
public void AddCategories() { var filter = new CategoryFilter(); filter.AddCategory("Dummy"); filter.AddCategory("Another"); Assert.That(filter.Match(_dummyFixture)); Assert.That(filter.Match(_anotherFixture)); Assert.False(filter.Match(_yetAnotherFixture)); }
public void ExplicitMatch_MultipleCategories() { var filter = new CategoryFilter(new string[] { "Dummy", "Another" }); Assert.That(filter.IsExplicitMatch(_topLevelSuite)); Assert.That(filter.IsExplicitMatch(_dummyFixture)); Assert.False(filter.IsExplicitMatch(_dummyFixture.Tests[0])); Assert.That(filter.IsExplicitMatch(_anotherFixture)); Assert.False(filter.IsExplicitMatch(_anotherFixture.Tests[0])); Assert.False(filter.IsExplicitMatch(_yetAnotherFixture)); }
public void IsNotEmpty() { var filter = new CategoryFilter("Dummy"); Assert.False(filter.IsEmpty); }
public static TestFilter FromXml(string xmlText) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlText); XmlNode topNode = doc.FirstChild; if (topNode.Name != "filter") throw new Exception("Expected filter element at top level"); // Initially, an empty filter TestFilter result = TestFilter.Empty; bool isEmptyResult = true; XmlNodeList testNodes = topNode.SelectNodes("tests/test"); XmlNodeList includeNodes = topNode.SelectNodes("include/category"); XmlNodeList excludeNodes = topNode.SelectNodes("exclude/category"); if (testNodes.Count > 0) { SimpleNameFilter nameFilter = new SimpleNameFilter(); foreach (XmlNode testNode in topNode.SelectNodes("tests/test")) nameFilter.Add(testNode.InnerText); result = nameFilter; isEmptyResult = false; } if (includeNodes.Count > 0) { //CategoryFilter includeFilter = new CategoryFilter(); //foreach (XmlNode includeNode in includeNodes) // includeFilter.AddCategory(includeNode.InnerText); // Temporarily just look at the first element XmlNode includeNode = includeNodes[0]; TestFilter includeFilter = new CategoryExpression(includeNode.InnerText).Filter; if (isEmptyResult) result = includeFilter; else result = new AndFilter(result, includeFilter); isEmptyResult = false; } if (excludeNodes.Count > 0) { CategoryFilter categoryFilter = new CategoryFilter(); foreach (XmlNode excludeNode in excludeNodes) categoryFilter.AddCategory(excludeNode.InnerText); TestFilter excludeFilter = new NotFilter(categoryFilter); if (isEmptyResult) result = excludeFilter; else result = new AndFilter(result, excludeFilter); isEmptyResult = false; } return result; }
public void CategoryFilter_ToXml() { TestFilter filter = new CategoryFilter("CATEGORY"); Assert.That(filter.ToXml(false).OuterXml, Is.EqualTo("<cat>CATEGORY</cat>")); }
public void CategoryFilter_AddCategories() { var filter = new CategoryFilter(); filter.AddCategory("Dummy"); filter.AddCategory("Another"); Assert.False(filter.IsEmpty); Assert.That(filter.Match(dummyFixture)); Assert.That(filter.Match(anotherFixture)); Assert.False(filter.Match(yetAnotherFixture)); }
private static TestFilter FromXml(TNode node) { switch (node.Name) { case "filter": case "and": var andFilter = new AndFilter(); foreach (var childNode in node.ChildNodes) andFilter.Add(FromXml(childNode)); return andFilter; case "or": var orFilter = new OrFilter(); foreach (var childNode in node.ChildNodes) orFilter.Add(FromXml(childNode)); return orFilter; case "not": return new NotFilter(FromXml(node.FirstChild)); case "id": var idFilter = new IdFilter(); if (node.Value != null) foreach (string id in node.Value.Split(COMMA)) idFilter.Add(id); return idFilter; case "tests": var testFilter = new SimpleNameFilter(); foreach (var childNode in node.SelectNodes("test")) testFilter.Add(childNode.Value); return testFilter; case "cat": var catFilter = new CategoryFilter(); if (node.Value != null) foreach (string cat in node.Value.Split(COMMA)) catFilter.AddCategory(cat); return catFilter; default: throw new ArgumentException("Invalid filter element: " + node.Name, "xmlNode"); } }
private static TestFilter FromXml(XmlNode xmlNode) { switch (xmlNode.Name) { case "filter": case "and": var andFilter = new AndFilter(); foreach (XmlNode childNode in xmlNode.ChildNodes) andFilter.Add(FromXml(childNode)); return andFilter; case "or": var orFilter = new OrFilter(); foreach (System.Xml.XmlNode childNode in xmlNode.ChildNodes) orFilter.Add(FromXml(childNode)); return orFilter; case "not": return new NotFilter(FromXml(xmlNode.FirstChild)); case "id": var idFilter = new IdFilter(); foreach (string id in xmlNode.InnerText.Split(COMMA)) idFilter.Add(int.Parse(id)); return idFilter; case "tests": var testFilter = new SimpleNameFilter(); foreach (XmlNode childNode in xmlNode.SelectNodes("test")) testFilter.Add(childNode.InnerText); return testFilter; case "cat": var catFilter = new CategoryFilter(); foreach (string cat in xmlNode.InnerText.Split(COMMA)) catFilter.AddCategory(cat); return catFilter; default: throw new ArgumentException("Invalid filter element: " + xmlNode.Name, "xmlNode"); } }
static void ChainCategoryFilter(IEnumerable <string> categories, bool negate, ref TestFilter chain) { bool gotCategories = false; if (categories != null) { var filter = new CategoryFilter (); foreach (string c in categories) { Log.Info (TAG, " {0}", c); filter.AddCategory (c); gotCategories = true; } chain = new AndFilter (chain, negate ? (TestFilter)new NotFilter (filter) : (TestFilter)filter); } if (!gotCategories) Log.Info (TAG, " none"); }
public void CategoryFilter_SingleCategoryConstructor() { var filter = new CategoryFilter("Dummy"); Assert.False(filter.IsEmpty); Assert.That(filter.Match(dummyFixture)); Assert.False(filter.Match(anotherFixture)); }
private CategoryFilter GetCategoryFilter() { CategoryFilter filter = new CategoryFilter( token ); while( GetToken() == "," || token == ";" ) filter.AddCategory( GetToken() ); return filter; }
public void SimpleCategoryFilter_MultipleCategoryConstructor() { var filter = new CategoryFilter(new string[] { "Dummy", "Another" }); Assert.False(filter.IsEmpty); Assert.That(filter.Match(dummyFixture)); Assert.That(filter.Match(anotherFixture)); Assert.False(filter.Match(yetAnotherFixture)); }