Merge pull request #704 from jgagnon/master
[mono.git] / mcs / nunit24 / NUnitFramework / framework / Constraints / EmptyConstraint.cs
1 // ****************************************************************\r
2 // Copyright 2007, Charlie Poole\r
3 // This is free software licensed under the NUnit license. You may\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4\r
5 // ****************************************************************\r
6 \r
7 using System;\r
8 using System.Collections;\r
9 \r
10 namespace NUnit.Framework.Constraints\r
11 {\r
12         /// <summary>\r
13         /// EmptyConstraint tests a whether a string or collection is empty,\r
14         /// postponing the decision about which test is applied until the\r
15         /// type of the actual argument is known.\r
16         /// </summary>\r
17         public class EmptyConstraint : Constraint\r
18         {\r
19                 private Constraint RealConstraint\r
20                 {\r
21                         get \r
22                         {\r
23                                 if ( actual is string )\r
24                                         return new EmptyStringConstraint();\r
25                                 else\r
26                                         return new EmptyCollectionConstraint();\r
27                         }\r
28                 }\r
29                 \r
30                 /// <summary>\r
31         /// Test whether the constraint is satisfied by a given value\r
32         /// </summary>\r
33         /// <param name="actual">The value to be tested</param>\r
34         /// <returns>True for success, false for failure</returns>\r
35                 public override bool Matches(object actual)\r
36                 {\r
37                         this.actual = actual;\r
38 \r
39                         return this.RealConstraint.Matches( actual );\r
40                 }\r
41 \r
42         /// <summary>\r
43         /// Write the constraint description to a MessageWriter\r
44         /// </summary>\r
45         /// <param name="writer">The writer on which the description is displayed</param>\r
46                 public override void WriteDescriptionTo(MessageWriter writer)\r
47                 {\r
48                         this.RealConstraint.WriteDescriptionTo( writer );\r
49                 }\r
50         }\r
51 }\r