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 NUnit.Framework.Constraints;
\r
10 namespace NUnit.Framework.SyntaxHelpers
\r
13 /// Summary description for HasNoPrefixB.
\r
18 /// Nested class that allows us to restrict the number
\r
19 /// of key words that may appear after Has.No.
\r
21 public class HasNoPrefixBuilder
\r
24 /// Return a ConstraintBuilder conditioned to apply
\r
25 /// the following constraint to a property.
\r
27 /// <param name="name">The property name</param>
\r
28 /// <returns>A ConstraintBuilder</returns>
\r
29 public ConstraintBuilder Property(string name)
\r
31 return new ConstraintBuilder().Not.Property(name);
\r
35 /// Return a Constraint that succeeds if the expected object is
\r
36 /// not contained in a collection.
\r
38 /// <param name="expected">The expected object</param>
\r
39 /// <returns>A Constraint</returns>
\r
40 public Constraint Member(object expected)
\r
42 return new NotConstraint( new CollectionContainsConstraint(expected) ) ;
\r
46 #region Prefix Operators
\r
48 /// Has.No returns a ConstraintBuilder that negates
\r
49 /// the constraint that follows it.
\r
51 public static HasNoPrefixBuilder No
\r
53 get { return new HasNoPrefixBuilder(); }
\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
61 public static ConstraintBuilder All
\r
63 get { return new ConstraintBuilder().All; }
\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
72 public static ConstraintBuilder Some
\r
74 get { return new ConstraintBuilder().Some; }
\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
82 public static ConstraintBuilder None
\r
84 get { return new ConstraintBuilder().None; }
\r
88 /// Returns a new ConstraintBuilder, which will apply the
\r
89 /// following constraint to a named property of the object
\r
92 /// <param name="name">The name of the property</param>
\r
93 public static ConstraintBuilder Property( string name )
\r
95 return new ConstraintBuilder().Property(name);
\r
99 #region Property Constraints
\r
101 /// Returns a new PropertyConstraint checking for the
\r
102 /// existence of a particular property value.
\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
108 return new PropertyConstraint( name, new EqualConstraint( expected ) );
\r
112 /// Returns a new PropertyConstraint for the Length property
\r
114 /// <param name="length"></param>
\r
115 /// <returns></returns>
\r
116 public static Constraint Length( int length )
\r
118 return Property( "Length", length );
\r
122 /// Returns a new PropertyConstraint or the Count property
\r
124 /// <param name="count"></param>
\r
125 /// <returns></returns>
\r
126 public static Constraint Count( int count )
\r
128 return Property( "Count", count );
\r
132 #region Member Constraint
\r
134 /// Returns a new CollectionContainsConstraint checking for the
\r
135 /// presence of a particular object in the collection.
\r
137 /// <param name="expected">The expected object</param>
\r
138 public static Constraint Member( object expected )
\r
140 return new CollectionContainsConstraint( expected );
\r