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
8 using System.Collections;
\r
9 using NUnit.Framework.Constraints;
\r
11 namespace NUnit.Framework.SyntaxHelpers
\r
14 /// The Is class is a helper class with properties and methods
\r
15 /// that supply a number of constraints used in Asserts.
\r
19 #region Prefix Operators
\r
21 /// Is.Not returns a ConstraintBuilder that negates
\r
22 /// the constraint that follows it.
\r
24 public static ConstraintBuilder Not
\r
26 get { return new ConstraintBuilder().Not; }
\r
30 /// Is.All returns a ConstraintBuilder, which will apply
\r
31 /// the following constraint to all members of a collection,
\r
32 /// succeeding if all of them succeed. This property is
\r
33 /// a synonym for Has.AllItems.
\r
35 public static ConstraintBuilder All
\r
37 get { return new ConstraintBuilder().All; }
\r
41 #region Constraints Without Arguments
\r
43 /// Is.Null returns a static constraint that tests for null
\r
45 public static readonly Constraint Null = new EqualConstraint( null );
\r
47 /// Is.True returns a static constraint that tests whether a value is true
\r
49 public static readonly Constraint True = new EqualConstraint(true);
\r
51 /// Is.False returns a static constraint that tests whether a value is false
\r
53 public static readonly Constraint False = new EqualConstraint(false);
\r
55 /// Is.NaN returns a static constraint that tests whether a value is an NaN
\r
57 public static readonly Constraint NaN = new EqualConstraint(double.NaN);
\r
59 /// Is.Empty returns a static constraint that tests whether a string or collection is empty
\r
61 public static readonly Constraint Empty = new EmptyConstraint();
\r
63 /// Is.Unique returns a static constraint that tests whether a collection contains all unque items.
\r
65 public static readonly Constraint Unique = new UniqueItemsConstraint();
\r
68 #region Constraints with an expected value
\r
70 #region Equality and Identity
\r
72 /// Is.EqualTo returns a constraint that tests whether the
\r
73 /// actual value equals the supplied argument
\r
75 /// <param name="expected"></param>
\r
76 /// <returns></returns>
\r
77 public static EqualConstraint EqualTo(object expected)
\r
79 return new EqualConstraint(expected);
\r
82 /// Is.SameAs returns a constraint that tests whether the
\r
83 /// actual value is the same object as the supplied argument.
\r
85 /// <param name="expected"></param>
\r
86 /// <returns></returns>
\r
87 public static Constraint SameAs(object expected)
\r
89 return new SameAsConstraint(expected);
\r
93 #region Comparison Constraints
\r
95 /// Is.GreaterThan returns a constraint that tests whether the
\r
96 /// actual value is greater than the suppled argument
\r
98 public static Constraint GreaterThan(IComparable expected)
\r
100 return new GreaterThanConstraint(expected);
\r
103 /// Is.GreaterThanOrEqualTo returns a constraint that tests whether the
\r
104 /// actual value is greater than or equal to the suppled argument
\r
106 public static Constraint GreaterThanOrEqualTo(IComparable expected)
\r
108 return new GreaterThanOrEqualConstraint(expected);
\r
112 /// Is.AtLeast is a synonym for Is.GreaterThanOrEqualTo
\r
114 public static Constraint AtLeast(IComparable expected)
\r
116 return GreaterThanOrEqualTo(expected);
\r
120 /// Is.LessThan returns a constraint that tests whether the
\r
121 /// actual value is less than the suppled argument
\r
123 public static Constraint LessThan(IComparable expected)
\r
125 return new LessThanConstraint(expected);
\r
129 /// Is.LessThanOrEqualTo returns a constraint that tests whether the
\r
130 /// actual value is less than or equal to the suppled argument
\r
132 public static Constraint LessThanOrEqualTo(IComparable expected)
\r
134 return new LessThanOrEqualConstraint(expected);
\r
138 /// Is.AtMost is a synonym for Is.LessThanOrEqualTo
\r
140 public static Constraint AtMost(IComparable expected)
\r
142 return LessThanOrEqualTo(expected);
\r
146 #region Type Constraints
\r
148 /// Is.TypeOf returns a constraint that tests whether the actual
\r
149 /// value is of the exact type supplied as an argument.
\r
151 public static Constraint TypeOf(Type expectedType)
\r
153 return new ExactTypeConstraint(expectedType);
\r
157 /// Is.InstanceOfType returns a constraint that tests whether
\r
158 /// the actual value is of the type supplied as an argument
\r
159 /// or a derived type.
\r
161 public static Constraint InstanceOfType(Type expectedType)
\r
163 return new InstanceOfTypeConstraint(expectedType);
\r
167 /// Is.AssignableFrom returns a constraint that tests whether
\r
168 /// the actual value is assignable from the type supplied as
\r
171 /// <param name="expectedType"></param>
\r
172 /// <returns></returns>
\r
173 public static Constraint AssignableFrom(Type expectedType)
\r
175 return new AssignableFromConstraint(expectedType);
\r
179 #region Collection Constraints
\r
181 /// Is.EquivalentTo returns a constraint that tests whether
\r
182 /// the actual value is a collection containing the same
\r
183 /// elements as the collection supplied as an arument
\r
185 public static Constraint EquivalentTo(ICollection expected)
\r
187 return new CollectionEquivalentConstraint(expected);
\r
191 /// Is.SubsetOf returns a constraint that tests whether
\r
192 /// the actual value is a subset of the collection
\r
193 /// supplied as an arument
\r
195 public static Constraint SubsetOf(ICollection expected)
\r
197 return new CollectionSubsetConstraint(expected);
\r
206 /// The Iz class is a synonym for Is intended for use in VB,
\r
207 /// which regards Is as a keyword.
\r
209 public class Iz : Is
\r