PageRenderTime 39ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/interfaces/Filters/NotFilter.cs

#
C# | 78 lines | 40 code | 9 blank | 29 comment | 11 complexity | 922b689b80e71bc2542f2d34633f3153 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. namespace NUnit.Core.Filters
  8. {
  9. /// <summary>
  10. /// NotFilter negates the operation of another filter
  11. /// </summary>
  12. [Serializable]
  13. public class NotFilter : TestFilter
  14. {
  15. ITestFilter baseFilter;
  16. bool topLevel = false;
  17. /// <summary>
  18. /// Construct a not filter on another filter
  19. /// </summary>
  20. /// <param name="baseFilter">The filter to be negated</param>
  21. public NotFilter( ITestFilter baseFilter)
  22. {
  23. this.baseFilter = baseFilter;
  24. }
  25. /// <summary>
  26. /// Indicates whether this is a top-level NotFilter,
  27. /// requiring special handling of Explicit
  28. /// </summary>
  29. public bool TopLevel
  30. {
  31. get { return topLevel; }
  32. set { topLevel = value; }
  33. }
  34. /// <summary>
  35. /// Gets the base filter
  36. /// </summary>
  37. public ITestFilter BaseFilter
  38. {
  39. get { return baseFilter; }
  40. }
  41. /// <summary>
  42. /// Check whether the filter matches a test
  43. /// </summary>
  44. /// <param name="test">The test to be matched</param>
  45. /// <returns>True if it matches, otherwise false</returns>
  46. public override bool Match( ITest test )
  47. {
  48. if (topLevel && test.RunState == RunState.Explicit)
  49. return false;
  50. return !baseFilter.Pass( test );
  51. }
  52. /// <summary>
  53. /// Determine whether any descendant of the test matches the filter criteria.
  54. /// </summary>
  55. /// <param name="test">The test to be matched</param>
  56. /// <returns>True if at least one descendant matches the filter criteria</returns>
  57. protected override bool MatchDescendant(ITest test)
  58. {
  59. if (!test.IsSuite || test.Tests == null || topLevel && test.RunState == RunState.Explicit)
  60. return false;
  61. foreach (ITest child in test.Tests)
  62. {
  63. if (Match(child) || MatchDescendant(child))
  64. return true;
  65. }
  66. return false;
  67. }
  68. }
  69. }