PageRenderTime 29ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 82 lines | 40 code | 9 blank | 33 comment | 2 complexity | 957e363560a66ea099b6e61005e5338b MD5 | raw file
Possible License(s): GPL-2.0
  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. // ****************************************************************
  6. using System;
  7. using System.Collections;
  8. namespace NUnit.Core.Filters
  9. {
  10. /// <summary>
  11. /// Combines multiple filters so that a test must pass one
  12. /// of them in order to pass this filter.
  13. /// </summary>
  14. [Serializable]
  15. public class OrFilter : TestFilter
  16. {
  17. private ArrayList filters = new ArrayList();
  18. /// <summary>
  19. /// Constructs an empty OrFilter
  20. /// </summary>
  21. public OrFilter() { }
  22. /// <summary>
  23. /// Constructs an AndFilter from an array of filters
  24. /// </summary>
  25. /// <param name="filters"></param>
  26. public OrFilter( params ITestFilter[] filters )
  27. {
  28. this.filters.AddRange( filters );
  29. }
  30. /// <summary>
  31. /// Adds a filter to the list of filters
  32. /// </summary>
  33. /// <param name="filter">The filter to be added</param>
  34. public void Add( ITestFilter filter )
  35. {
  36. this.filters.Add( filter );
  37. }
  38. /// <summary>
  39. /// Return an array of the composing filters
  40. /// </summary>
  41. public ITestFilter[] Filters
  42. {
  43. get
  44. {
  45. return (ITestFilter[])filters.ToArray(typeof(ITestFilter));
  46. }
  47. }
  48. /// <summary>
  49. /// Checks whether the OrFilter is matched by a test
  50. /// </summary>
  51. /// <param name="test">The test to be matched</param>
  52. /// <returns>True if any of the component filters pass, otherwise false</returns>
  53. public override bool Pass( ITest test )
  54. {
  55. foreach( ITestFilter filter in filters )
  56. if ( filter.Pass( test ) )
  57. return true;
  58. return false;
  59. }
  60. /// <summary>
  61. /// Checks whether the OrFilter is matched by a test
  62. /// </summary>
  63. /// <param name="test">The test to be matched</param>
  64. /// <returns>True if any of the component filters match, otherwise false</returns>
  65. public override bool Match( ITest test )
  66. {
  67. foreach( ITestFilter filter in filters )
  68. if ( filter.Match( test ) )
  69. return true;
  70. return false;
  71. }
  72. }
  73. }