1 // ***********************************************************************
2 // Copyright (c) 2009 Charlie Poole
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
30 using System.Collections;
31 using NUnit.Framework.Constraints;
33 namespace NUnit.Framework
36 /// Helper class with properties and methods that supply
37 /// a number of constraints used in Asserts.
44 /// Returns a ConstraintExpression that negates any
45 /// following constraint.
47 public static ConstraintExpression No
49 get { return new ConstraintExpression().Not; }
57 /// Returns a ConstraintExpression, which will apply
58 /// the following constraint to all members of a collection,
59 /// succeeding if all of them succeed.
61 public static ConstraintExpression All
63 get { return new ConstraintExpression().All; }
71 /// Returns a ConstraintExpression, which will apply
72 /// the following constraint to all members of a collection,
73 /// succeeding if at least one of them succeeds.
75 public static ConstraintExpression Some
77 get { return new ConstraintExpression().Some; }
85 /// Returns a ConstraintExpression, which will apply
86 /// the following constraint to all members of a collection,
87 /// succeeding if all of them fail.
89 public static ConstraintExpression None
91 get { return new ConstraintExpression().None; }
99 /// Returns a ConstraintExpression, which will apply
100 /// the following constraint to all members of a collection,
101 /// succeeding only if a specified number of them succeed.
103 public static ConstraintExpression Exactly(int expectedCount)
105 return new ConstraintExpression().Exactly(expectedCount);
113 /// Returns a new PropertyConstraintExpression, which will either
114 /// test for the existence of the named property on the object
115 /// being tested or apply any following constraint to that property.
117 public static ResolvableConstraintExpression Property(string name)
119 return new ConstraintExpression().Property(name);
127 /// Returns a new ConstraintExpression, which will apply the following
128 /// constraint to the Length property of the object being tested.
130 public static ResolvableConstraintExpression Length
132 get { return Property("Length"); }
140 /// Returns a new ConstraintExpression, which will apply the following
141 /// constraint to the Count property of the object being tested.
143 public static ResolvableConstraintExpression Count
145 get { return Property("Count"); }
153 /// Returns a new ConstraintExpression, which will apply the following
154 /// constraint to the Message property of the object being tested.
156 public static ResolvableConstraintExpression Message
158 get { return Property("Message"); }
163 #region InnerException
166 /// Returns a new ConstraintExpression, which will apply the following
167 /// constraint to the InnerException property of the object being tested.
169 public static ResolvableConstraintExpression InnerException
171 get { return Property("InnerException"); }
179 /// Returns a new AttributeConstraint checking for the
180 /// presence of a particular attribute on an object.
182 public static ResolvableConstraintExpression Attribute(Type expectedType)
184 return new ConstraintExpression().Attribute(expectedType);
188 /// Returns a new AttributeConstraint checking for the
189 /// presence of a particular attribute on an object.
191 public static ResolvableConstraintExpression Attribute<T>()
193 return Attribute(typeof(T));
201 /// Returns a new CollectionContainsConstraint checking for the
202 /// presence of a particular object in the collection.
204 public static CollectionContainsConstraint Member(object expected)
206 return new CollectionContainsConstraint(expected);