public void NotAndNotFilterTests() { var filter = new NotFilter( new AndFilter( new NotFilter( new CategoryFilter("Dummy")), new MethodNameFilter("Test1"))); Assert.That(filter.Pass(_topLevelSuite)); Assert.That(filter.Match(_topLevelSuite)); Assert.That(filter.Pass(_fixtureWithMultipleTests)); Assert.That(filter.Match(_fixtureWithMultipleTests)); var test1 = _fixtureWithMultipleTests.Tests[0]; Assert.False(filter.Pass(test1)); Assert.False(filter.Match(test1)); var test2 = _fixtureWithMultipleTests.Tests[1]; Assert.That(filter.Pass(test2)); Assert.False(filter.IsExplicitMatch(test2)); Assert.That(filter.Match(test2)); }
public void MatchTest() { var filter = new NotFilter(new CategoryFilter("Dummy")); Assert.True(filter.Match(_topLevelSuite)); Assert.False(filter.Match(_dummyFixture)); Assert.True(filter.Match(_dummyFixture.Tests[0])); Assert.True(filter.Match(_anotherFixture)); }
public void PassTest() { var filter = new NotFilter(new CategoryFilter("Dummy")); Assert.True(filter.Pass(_topLevelSuite)); Assert.False(filter.Pass(_dummyFixture)); Assert.False(filter.Pass(_dummyFixture.Tests[0])); Assert.True(filter.Pass(_anotherFixture)); Assert.True(filter.Pass(_anotherFixture.Tests[0])); Assert.True(filter.Pass(_fixtureWithMultipleTests)); Assert.True(filter.Pass(_fixtureWithMultipleTests.Tests[0])); Assert.False(filter.Pass(_fixtureWithMultipleTests.Tests[1])); }
public void PassTest() { var filter = new NotFilter(new CategoryFilter("Dummy")); Assert.True(filter.Pass(_topLevelSuite)); Assert.False(filter.Pass(_dummyFixture)); Assert.False(filter.Pass(_dummyFixture.Tests[0])); Assert.True(filter.Pass(_anotherFixture)); Assert.True(filter.Pass(_anotherFixture.Tests[0])); Assert.True (filter.Pass (_fixtureWithMultipleTests)); Assert.True (filter.Pass (_fixtureWithMultipleTests.Tests[0])); Assert.False (filter.Pass (_fixtureWithMultipleTests.Tests[1])); }
public void TestNestedNotCategoryFilters() { var filter = new NotFilter(new CategoryFilter("NotDummy")); Assert.That(filter.Match(_dummyFixture)); Assert.False(filter.IsExplicitMatch(_dummyFixture)); Assert.That(filter.Match(_anotherFixture)); Assert.False(filter.IsExplicitMatch(_anotherFixture)); Assert.That(filter.Match(_yetAnotherFixture)); Assert.False(filter.IsExplicitMatch(_yetAnotherFixture)); Assert.That(filter.Match(_explicitFixture)); Assert.False(filter.IsExplicitMatch(_explicitFixture)); }
public void IsNotEmpty() { var filter = new NotFilter(new CategoryFilter("Dummy")); Assert.False(filter.IsEmpty); }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. Assembly callingAssembly = Assembly.GetCallingAssembly(); this.commandLineOptions = new CommandLineOptions(); commandLineOptions.Parse(args); if (commandLineOptions.OutFile != null) this.writer = new StreamWriter(commandLineOptions.OutFile); if (!commandLineOptions.NoHeader) WriteHeader(this.writer); if (commandLineOptions.ShowHelp) writer.Write(commandLineOptions.HelpText); else if (commandLineOptions.Error) { writer.WriteLine(commandLineOptions.ErrorMessage); writer.WriteLine(commandLineOptions.HelpText); } else { WriteRuntimeEnvironment(this.writer); if (commandLineOptions.Wait && commandLineOptions.OutFile != null) writer.WriteLine("Ignoring /wait option - only valid for Console"); // We only have one commandline option that has to be passed // to the runner, so we do it here for convenience. var runnerSettings = new Dictionary<string, object>(); Randomizer.InitialSeed = commandLineOptions.InitialSeed; TestFilter filter = commandLineOptions.TestCount > 0 ? new SimpleNameFilter(commandLineOptions.Tests) : TestFilter.Empty; try { foreach (string name in commandLineOptions.Parameters) assemblies.Add(Assembly.Load(name)); if (assemblies.Count == 0) assemblies.Add(callingAssembly); // TODO: For now, ignore all but first assembly Assembly assembly = assemblies[0]; //Randomizer.InitialSeed = commandLineOptions.InitialSeed; if (runner.Load(assembly, runnerSettings) == null) { var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (commandLineOptions.Explore) ExploreTests(); else { if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty) { TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter; if (filter.IsEmpty) filter = includeFilter; else filter = new AndFilter(filter, includeFilter); } if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty) { TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter); if (filter.IsEmpty) filter = excludeFilter; else if (filter is AndFilter) ((AndFilter)filter).Add(excludeFilter); else filter = new AndFilter(filter, excludeFilter); } RunTests(filter); } } catch (FileNotFoundException ex) { writer.WriteLine(ex.Message); } catch (Exception ex) { writer.WriteLine(ex.ToString()); } finally { if (commandLineOptions.OutFile == null) { if (commandLineOptions.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { writer.Close(); } } } }
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 NotFilter_Constructor() { var filter = new NotFilter(new CategoryFilter("Dummy")); Assert.False(filter.IsEmpty); Assert.False(filter.Match(dummyFixture)); Assert.True(filter.Match(anotherFixture)); }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public void Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. Assembly callingAssembly = Assembly.GetCallingAssembly(); this.commandLineOptions = new CommandLineOptions(); commandLineOptions.Parse(args); if (commandLineOptions.OutFile != null) this.writer = new StreamWriter(commandLineOptions.OutFile); if (!commandLineOptions.NoHeader) WriteHeader(this.writer); if (commandLineOptions.ShowHelp) writer.Write(commandLineOptions.HelpText); else if (commandLineOptions.Error) { writer.WriteLine(commandLineOptions.ErrorMessage); writer.WriteLine(commandLineOptions.HelpText); } else { WriteRuntimeEnvironment(this.writer); if (commandLineOptions.Wait && commandLineOptions.OutFile != null) writer.WriteLine("Ignoring /wait option - only valid for Console"); #if SILVERLIGHT IDictionary loadOptions = new System.Collections.Generic.Dictionary<string, string>(); #else IDictionary loadOptions = new Hashtable(); #endif //if (options.Load.Count > 0) // loadOptions["LOAD"] = options.Load; //IDictionary runOptions = new Hashtable(); //if (commandLineOptions.TestCount > 0) // runOptions["RUN"] = commandLineOptions.Tests; ITestFilter filter = commandLineOptions.TestCount > 0 ? new SimpleNameFilter(commandLineOptions.Tests) : TestFilter.Empty; try { foreach (string name in commandLineOptions.Parameters) assemblies.Add(Assembly.Load(name)); if (assemblies.Count == 0) assemblies.Add(callingAssembly); // TODO: For now, ignore all but first assembly Assembly assembly = assemblies[0] as Assembly; Randomizer.InitialSeed = commandLineOptions.InitialSeed; if (!runner.Load(assembly, loadOptions)) { AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (commandLineOptions.Explore) ExploreTests(); else { if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty) { TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter; if (filter.IsEmpty) filter = includeFilter; else filter = new AndFilter(filter, includeFilter); } if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty) { TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter); if (filter.IsEmpty) filter = excludeFilter; else if (filter is AndFilter) ((AndFilter)filter).Add(excludeFilter); else filter = new AndFilter(filter, excludeFilter); } RunTests(filter); } } catch (FileNotFoundException ex) { writer.WriteLine(ex.Message); } catch (Exception ex) { writer.WriteLine(ex.ToString()); } finally { if (commandLineOptions.OutFile == null) { if (commandLineOptions.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { writer.Close(); } } } }
public void NotFilter_Constructor_TopLevel() { var filter = new NotFilter(new CategoryFilter("Dummy")); filter.TopLevel = true; Assert.False(filter.IsEmpty); Assert.False(filter.Match(dummyFixture)); Assert.False(filter.Match(dummyFixture.Tests[0])); Assert.True(filter.Match(anotherFixture)); }