PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/framework/Constraints/EmptyConstraint.cs

#
C# | 53 lines | 29 code | 5 blank | 19 comment | 3 complexity | 26091de15c5c48b7375209f4b172f3fa 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.Framework.Constraints
  9. {
  10. /// <summary>
  11. /// EmptyConstraint tests a whether a string or collection is empty,
  12. /// postponing the decision about which test is applied until the
  13. /// type of the actual argument is known.
  14. /// </summary>
  15. public class EmptyConstraint : Constraint
  16. {
  17. private Constraint RealConstraint
  18. {
  19. get
  20. {
  21. if (actual is string)
  22. return new EmptyStringConstraint();
  23. else if (actual is System.IO.DirectoryInfo)
  24. return new EmptyDirectoryContraint();
  25. else
  26. return new EmptyCollectionConstraint();
  27. }
  28. }
  29. /// <summary>
  30. /// Test whether the constraint is satisfied by a given value
  31. /// </summary>
  32. /// <param name="actual">The value to be tested</param>
  33. /// <returns>True for success, false for failure</returns>
  34. public override bool Matches(object actual)
  35. {
  36. this.actual = actual;
  37. return this.RealConstraint.Matches( actual );
  38. }
  39. /// <summary>
  40. /// Write the constraint description to a MessageWriter
  41. /// </summary>
  42. /// <param name="writer">The writer on which the description is displayed</param>
  43. public override void WriteDescriptionTo(MessageWriter writer)
  44. {
  45. this.RealConstraint.WriteDescriptionTo( writer );
  46. }
  47. }
  48. }