/src/NUnit/interfaces/Filters/AndFilter.cs
C# | 82 lines | 40 code | 9 blank | 33 comment | 2 complexity | 3627f120e3bcb4c92258b4633061acd6 MD5 | raw file
1// **************************************************************** 2// Copyright 2007, Charlie Poole 3// This is free software licensed under the NUnit license. You may 4// obtain a copy of the license at http://nunit.org 5// **************************************************************** 6using System; 7using System.Collections; 8 9namespace NUnit.Core.Filters 10{ 11 /// <summary> 12 /// Combines multiple filters so that a test must pass all 13 /// of them in order to pass this filter. 14 /// </summary> 15 [Serializable] 16 public class AndFilter : TestFilter 17 { 18 private ArrayList filters = new ArrayList(); 19 20 /// <summary> 21 /// Constructs an empty AndFilter 22 /// </summary> 23 public AndFilter() { } 24 25 /// <summary> 26 /// Constructs an AndFilter from an array of filters 27 /// </summary> 28 /// <param name="filters"></param> 29 public AndFilter( params ITestFilter[] filters ) 30 { 31 this.filters.AddRange( filters ); 32 } 33 34 /// <summary> 35 /// Adds a filter to the list of filters 36 /// </summary> 37 /// <param name="filter">The filter to be added</param> 38 public void Add( ITestFilter filter ) 39 { 40 this.filters.Add( filter ); 41 } 42 43 /// <summary> 44 /// Return an array of the composing filters 45 /// </summary> 46 public ITestFilter[] Filters 47 { 48 get 49 { 50 return (ITestFilter[])filters.ToArray(typeof(ITestFilter)); 51 } 52 } 53 54 /// <summary> 55 /// Checks whether the AndFilter is matched by a test 56 /// </summary> 57 /// <param name="test">The test to be matched</param> 58 /// <returns>True if all the component filters pass, otherwise false</returns> 59 public override bool Pass( ITest test ) 60 { 61 foreach( ITestFilter filter in filters ) 62 if ( !filter.Pass( test ) ) 63 return false; 64 65 return true; 66 } 67 68 /// <summary> 69 /// Checks whether the AndFilter is matched by a test 70 /// </summary> 71 /// <param name="test">The test to be matched</param> 72 /// <returns>True if all the component filters match, otherwise false</returns> 73 public override bool Match( ITest test ) 74 { 75 foreach( ITestFilter filter in filters ) 76 if ( !filter.Match( test ) ) 77 return false; 78 79 return true; 80 } 81 } 82}