PageRenderTime 55ms CodeModel.GetById 48ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/interfaces/Filters/OrFilter.cs

#
C# | 82 lines | 40 code | 9 blank | 33 comment | 2 complexity | 957e363560a66ea099b6e61005e5338b 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 one 
13	/// of them in order to pass this filter.
14	/// </summary>
15	[Serializable]
16	public class OrFilter : TestFilter
17	{
18		private ArrayList filters = new ArrayList();
19
20		/// <summary>
21		/// Constructs an empty OrFilter
22		/// </summary>
23		public OrFilter() { }
24
25		/// <summary>
26		/// Constructs an AndFilter from an array of filters
27		/// </summary>
28		/// <param name="filters"></param>
29		public OrFilter( 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 OrFilter is matched by a test
56		/// </summary>
57		/// <param name="test">The test to be matched</param>
58		/// <returns>True if any of 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 true;
64
65			return false;
66		}
67
68		/// <summary>
69		/// Checks whether the OrFilter is matched by a test
70		/// </summary>
71		/// <param name="test">The test to be matched</param>
72		/// <returns>True if any of 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 true;
78
79			return false;
80		}
81	}
82}