Merge pull request #1336 from esdrubal/datatablereadxmlschema
[mono.git] / mcs / nunit24 / NUnitFramework / framework / SyntaxHelpers / Has.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 NUnit.Framework.Constraints;\r
9 \r
10 namespace NUnit.Framework.SyntaxHelpers\r
11 {\r
12         /// <summary>\r
13         /// Summary description for HasNoPrefixB.\r
14         /// </summary>\r
15         public class Has\r
16         {\r
17         /// <summary>\r
18         /// Nested class that allows us to restrict the number\r
19         /// of key words that may appear after Has.No.\r
20         /// </summary>\r
21                 public class HasNoPrefixBuilder\r
22                 {\r
23             /// <summary>\r
24             /// Return a ConstraintBuilder conditioned to apply\r
25             /// the following constraint to a property.\r
26             /// </summary>\r
27             /// <param name="name">The property name</param>\r
28             /// <returns>A ConstraintBuilder</returns>\r
29                         public ConstraintBuilder Property(string name)\r
30                         {\r
31                                 return new ConstraintBuilder().Not.Property(name);\r
32                         }\r
33 \r
34             /// <summary>\r
35             /// Return a Constraint that succeeds if the expected object is\r
36             /// not contained in a collection.\r
37             /// </summary>\r
38             /// <param name="expected">The expected object</param>\r
39             /// <returns>A Constraint</returns>\r
40             public Constraint Member(object expected)\r
41                         {\r
42                                 return new NotConstraint( new CollectionContainsConstraint(expected) ) ;\r
43                         }\r
44                 }\r
45 \r
46                 #region Prefix Operators\r
47                 /// <summary>\r
48                 /// Has.No returns a ConstraintBuilder that negates\r
49                 /// the constraint that follows it.\r
50                 /// </summary>\r
51                 public static HasNoPrefixBuilder No\r
52                 {\r
53                         get { return new HasNoPrefixBuilder(); }\r
54                 }\r
55 \r
56                 /// <summary>\r
57                 /// Has.AllItems returns a ConstraintBuilder, which will apply\r
58                 /// the following constraint to all members of a collection,\r
59                 /// succeeding if all of them succeed.\r
60                 /// </summary>\r
61                 public static ConstraintBuilder All\r
62                 {\r
63                         get { return new ConstraintBuilder().All; }\r
64                 }\r
65 \r
66                 /// <summary>\r
67                 /// Has.Some returns a ConstraintBuilder, which will apply\r
68                 /// the following constraint to all members of a collection,\r
69                 /// succeeding if any of them succeed. It is a synonym\r
70                 /// for Has.Item.\r
71                 /// </summary>\r
72                 public static ConstraintBuilder Some\r
73                 {\r
74                         get { return new ConstraintBuilder().Some; }\r
75                 }\r
76 \r
77                 /// <summary>\r
78                 /// Has.None returns a ConstraintBuilder, which will apply\r
79                 /// the following constraint to all members of a collection,\r
80                 /// succeeding only if none of them succeed.\r
81                 /// </summary>\r
82                 public static ConstraintBuilder None\r
83                 {\r
84                         get { return new ConstraintBuilder().None; }\r
85                 }\r
86 \r
87                 /// <summary>\r
88                 /// Returns a new ConstraintBuilder, which will apply the\r
89                 /// following constraint to a named property of the object\r
90                 /// being tested.\r
91                 /// </summary>\r
92                 /// <param name="name">The name of the property</param>\r
93                 public static ConstraintBuilder Property( string name )\r
94                 {\r
95                         return new ConstraintBuilder().Property(name);\r
96                 }\r
97                 #endregion\r
98 \r
99                 #region Property Constraints\r
100                 /// <summary>\r
101                 /// Returns a new PropertyConstraint checking for the\r
102                 /// existence of a particular property value.\r
103                 /// </summary>\r
104                 /// <param name="name">The name of the property to look for</param>\r
105                 /// <param name="expected">The expected value of the property</param>\r
106                 public static Constraint Property( string name, object expected )\r
107                 {\r
108                         return new PropertyConstraint( name, new EqualConstraint( expected ) );\r
109                 }\r
110 \r
111         /// <summary>\r
112         /// Returns a new PropertyConstraint for the Length property\r
113         /// </summary>\r
114         /// <param name="length"></param>\r
115         /// <returns></returns>\r
116                 public static Constraint Length( int length )\r
117                 {\r
118                         return Property( "Length", length );\r
119                 }\r
120 \r
121                 /// <summary>\r
122                 /// Returns a new PropertyConstraint or the Count property\r
123                 /// </summary>\r
124                 /// <param name="count"></param>\r
125                 /// <returns></returns>\r
126                 public static Constraint Count( int count )\r
127                 {\r
128                         return Property( "Count", count );\r
129                 }\r
130                 #endregion\r
131 \r
132                 #region Member Constraint\r
133                 /// <summary>\r
134                 /// Returns a new CollectionContainsConstraint checking for the\r
135                 /// presence of a particular object in the collection.\r
136                 /// </summary>\r
137                 /// <param name="expected">The expected object</param>\r
138                 public static Constraint Member( object expected )\r
139                 {\r
140                         return new CollectionContainsConstraint( expected );\r
141                 }\r
142                 #endregion\r
143         }\r
144 }\r