1
// ****************************************************************
2
// Copyright 2009, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
8
using System.Collections;
10
namespace NUnit.Framework.Constraints
13
/// ConstraintExpression represents a compound constraint in the
14
/// process of being constructed from a series of syntactic elements.
16
/// Individual elements are appended to the expression as they are
17
/// reognized. Once an actual Constraint is appended, the expression
18
/// returns a resolvable Constraint.
20
public class ConstraintExpression : ConstraintExpressionBase
23
/// Initializes a new instance of the <see cref="T:ConstraintExpression"/> class.
25
public ConstraintExpression() { }
28
/// Initializes a new instance of the <see cref="T:ConstraintExpression"/>
29
/// class passing in a ConstraintBuilder, which may be pre-populated.
31
/// <param name="builder">The builder.</param>
32
public ConstraintExpression(ConstraintBuilder builder)
38
/// Returns a ConstraintExpression that negates any
39
/// following constraint.
41
public ConstraintExpression Not
43
get { return this.Append(new NotOperator()); }
47
/// Returns a ConstraintExpression that negates any
48
/// following constraint.
50
public ConstraintExpression No
52
get { return this.Append(new NotOperator()); }
60
/// Returns a ConstraintExpression, which will apply
61
/// the following constraint to all members of a collection,
62
/// succeeding if all of them succeed.
64
public ConstraintExpression All
66
get { return this.Append(new AllOperator()); }
74
/// Returns a ConstraintExpression, which will apply
75
/// the following constraint to all members of a collection,
76
/// succeeding if at least one of them succeeds.
78
public ConstraintExpression Some
80
get { return this.Append(new SomeOperator()); }
88
/// Returns a ConstraintExpression, which will apply
89
/// the following constraint to all members of a collection,
90
/// succeeding if all of them fail.
92
public ConstraintExpression None
94
get { return this.Append(new NoneOperator()); }
102
/// Returns a ConstraintExpression, which will apply
103
/// the following constraint to all members of a collection,
104
/// succeeding only if a specified number of them succeed.
106
public ConstraintExpression Exactly(int expectedCount)
108
return this.Append(new ExactCountOperator(expectedCount));
116
/// Returns a new PropertyConstraintExpression, which will either
117
/// test for the existence of the named property on the object
118
/// being tested or apply any following constraint to that property.
120
public ResolvableConstraintExpression Property(string name)
122
return this.Append(new PropOperator(name));
130
/// Returns a new ConstraintExpression, which will apply the following
131
/// constraint to the Length property of the object being tested.
133
public ResolvableConstraintExpression Length
135
get { return Property("Length"); }
143
/// Returns a new ConstraintExpression, which will apply the following
144
/// constraint to the Count property of the object being tested.
146
public ResolvableConstraintExpression Count
148
get { return Property("Count"); }
156
/// Returns a new ConstraintExpression, which will apply the following
157
/// constraint to the Message property of the object being tested.
159
public ResolvableConstraintExpression Message
161
get { return Property("Message"); }
166
#region InnerException
169
/// Returns a new ConstraintExpression, which will apply the following
170
/// constraint to the InnerException property of the object being tested.
172
public ResolvableConstraintExpression InnerException
174
get { return Property("InnerException"); }
182
/// Returns a new AttributeConstraint checking for the
183
/// presence of a particular attribute on an object.
185
public ResolvableConstraintExpression Attribute(Type expectedType)
187
return this.Append(new AttributeOperator(expectedType));
190
#if CLR_2_0 || CLR_4_0
192
/// Returns a new AttributeConstraint checking for the
193
/// presence of a particular attribute on an object.
195
public ResolvableConstraintExpression Attribute<T>()
197
return Attribute(typeof(T));
206
/// With is currently a NOP - reserved for future use.
208
public ConstraintExpression With
210
get { return this.Append(new WithOperator()); }
218
/// Returns the constraint provided as an argument - used to allow custom
219
/// custom constraints to easily participate in the syntax.
221
public Constraint Matches(Constraint constraint)
223
return this.Append(constraint);
226
#if CLR_2_0 || CLR_4_0
228
/// Returns the constraint provided as an argument - used to allow custom
229
/// custom constraints to easily participate in the syntax.
231
public Constraint Matches<T>(Predicate<T> predicate)
233
return this.Append(new PredicateConstraint<T>(predicate));
242
/// Returns a constraint that tests for null
244
public NullConstraint Null
246
get { return (NullConstraint)this.Append(new NullConstraint()); }
254
/// Returns a constraint that tests for True
256
public TrueConstraint True
258
get { return (TrueConstraint)this.Append(new TrueConstraint()); }
266
/// Returns a constraint that tests for False
268
public FalseConstraint False
270
get { return (FalseConstraint)this.Append(new FalseConstraint()); }
278
/// Returns a constraint that tests for a positive value
280
public GreaterThanConstraint Positive
282
get { return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(0)); }
290
/// Returns a constraint that tests for a negative value
292
public LessThanConstraint Negative
294
get { return (LessThanConstraint)this.Append(new LessThanConstraint(0)); }
302
/// Returns a constraint that tests for NaN
304
public NaNConstraint NaN
306
get { return (NaNConstraint)this.Append(new NaNConstraint()); }
314
/// Returns a constraint that tests for empty
316
public EmptyConstraint Empty
318
get { return (EmptyConstraint)this.Append(new EmptyConstraint()); }
326
/// Returns a constraint that tests whether a collection
327
/// contains all unique items.
329
public UniqueItemsConstraint Unique
331
get { return (UniqueItemsConstraint)this.Append(new UniqueItemsConstraint()); }
336
#region BinarySerializable
339
/// Returns a constraint that tests whether an object graph is serializable in binary format.
341
public BinarySerializableConstraint BinarySerializable
343
get { return (BinarySerializableConstraint)this.Append(new BinarySerializableConstraint()); }
348
#region XmlSerializable
351
/// Returns a constraint that tests whether an object graph is serializable in xml format.
353
public XmlSerializableConstraint XmlSerializable
355
get { return (XmlSerializableConstraint)this.Append(new XmlSerializableConstraint()); }
363
/// Returns a constraint that tests two items for equality
365
public EqualConstraint EqualTo(object expected)
367
return (EqualConstraint)this.Append(new EqualConstraint(expected));
375
/// Returns a constraint that tests that two references are the same object
377
public SameAsConstraint SameAs(object expected)
379
return (SameAsConstraint)this.Append(new SameAsConstraint(expected));
387
/// Returns a constraint that tests whether the
388
/// actual value is greater than the suppled argument
390
public GreaterThanConstraint GreaterThan(object expected)
392
return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(expected));
397
#region GreaterThanOrEqualTo
400
/// Returns a constraint that tests whether the
401
/// actual value is greater than or equal to the suppled argument
403
public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
405
return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
409
/// Returns a constraint that tests whether the
410
/// actual value is greater than or equal to the suppled argument
412
public GreaterThanOrEqualConstraint AtLeast(object expected)
414
return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
422
/// Returns a constraint that tests whether the
423
/// actual value is less than the suppled argument
425
public LessThanConstraint LessThan(object expected)
427
return (LessThanConstraint)this.Append(new LessThanConstraint(expected));
432
#region LessThanOrEqualTo
435
/// Returns a constraint that tests whether the
436
/// actual value is less than or equal to the suppled argument
438
public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
440
return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
444
/// Returns a constraint that tests whether the
445
/// actual value is less than or equal to the suppled argument
447
public LessThanOrEqualConstraint AtMost(object expected)
449
return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
457
/// Returns a constraint that tests whether the actual
458
/// value is of the exact type supplied as an argument.
460
public ExactTypeConstraint TypeOf(Type expectedType)
462
return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(expectedType));
465
#if CLR_2_0 || CLR_4_0
467
/// Returns a constraint that tests whether the actual
468
/// value is of the exact type supplied as an argument.
470
public ExactTypeConstraint TypeOf<T>()
472
return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(typeof(T)));
481
/// Returns a constraint that tests whether the actual value
482
/// is of the type supplied as an argument or a derived type.
484
public InstanceOfTypeConstraint InstanceOf(Type expectedType)
486
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
489
#if CLR_2_0 || CLR_4_0
491
/// Returns a constraint that tests whether the actual value
492
/// is of the type supplied as an argument or a derived type.
494
public InstanceOfTypeConstraint InstanceOf<T>()
496
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
501
/// Returns a constraint that tests whether the actual value
502
/// is of the type supplied as an argument or a derived type.
504
[Obsolete("Use InstanceOf(expectedType)")]
505
public InstanceOfTypeConstraint InstanceOfType(Type expectedType)
507
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
510
#if CLR_2_0 || CLR_4_0
512
/// Returns a constraint that tests whether the actual value
513
/// is of the type supplied as an argument or a derived type.
515
[Obsolete("Use InstanceOf<T>()")]
516
public InstanceOfTypeConstraint InstanceOfType<T>()
518
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
524
#region AssignableFrom
527
/// Returns a constraint that tests whether the actual value
528
/// is assignable from the type supplied as an argument.
530
public AssignableFromConstraint AssignableFrom(Type expectedType)
532
return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(expectedType));
535
#if CLR_2_0 || CLR_4_0
537
/// Returns a constraint that tests whether the actual value
538
/// is assignable from the type supplied as an argument.
540
public AssignableFromConstraint AssignableFrom<T>()
542
return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(typeof(T)));
551
/// Returns a constraint that tests whether the actual value
552
/// is assignable from the type supplied as an argument.
554
public AssignableToConstraint AssignableTo(Type expectedType)
556
return (AssignableToConstraint)this.Append(new AssignableToConstraint(expectedType));
559
#if CLR_2_0 || CLR_4_0
561
/// Returns a constraint that tests whether the actual value
562
/// is assignable from the type supplied as an argument.
564
public AssignableToConstraint AssignableTo<T>()
566
return (AssignableToConstraint)this.Append(new AssignableToConstraint(typeof(T)));
575
/// Returns a constraint that tests whether the actual value
576
/// is a collection containing the same elements as the
577
/// collection supplied as an argument.
579
public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
581
return (CollectionEquivalentConstraint)this.Append(new CollectionEquivalentConstraint(expected));
589
/// Returns a constraint that tests whether the actual value
590
/// is a subset of the collection supplied as an argument.
592
public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
594
return (CollectionSubsetConstraint)this.Append(new CollectionSubsetConstraint(expected));
602
/// Returns a constraint that tests whether a collection is ordered
604
public CollectionOrderedConstraint Ordered
606
get { return (CollectionOrderedConstraint)this.Append(new CollectionOrderedConstraint()); }
614
/// Returns a new CollectionContainsConstraint checking for the
615
/// presence of a particular object in the collection.
617
public CollectionContainsConstraint Member(object expected)
619
return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
623
/// Returns a new CollectionContainsConstraint checking for the
624
/// presence of a particular object in the collection.
626
public CollectionContainsConstraint Contains(object expected)
628
return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
636
/// Returns a new ContainsConstraint. This constraint
637
/// will, in turn, make use of the appropriate second-level
638
/// constraint, depending on the type of the actual argument.
639
/// This overload is only used if the item sought is a string,
640
/// since any other type implies that we are looking for a
641
/// collection member.
643
public ContainsConstraint Contains(string expected)
645
return (ContainsConstraint)this.Append(new ContainsConstraint(expected));
650
#region StringContaining
653
/// Returns a constraint that succeeds if the actual
654
/// value contains the substring supplied as an argument.
656
public SubstringConstraint StringContaining(string expected)
658
return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
662
/// Returns a constraint that succeeds if the actual
663
/// value contains the substring supplied as an argument.
665
public SubstringConstraint ContainsSubstring(string expected)
667
return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
675
/// Returns a constraint that succeeds if the actual
676
/// value starts with the substring supplied as an argument.
678
public StartsWithConstraint StartsWith(string expected)
680
return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
684
/// Returns a constraint that succeeds if the actual
685
/// value starts with the substring supplied as an argument.
687
public StartsWithConstraint StringStarting(string expected)
689
return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
697
/// Returns a constraint that succeeds if the actual
698
/// value ends with the substring supplied as an argument.
700
public EndsWithConstraint EndsWith(string expected)
702
return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
706
/// Returns a constraint that succeeds if the actual
707
/// value ends with the substring supplied as an argument.
709
public EndsWithConstraint StringEnding(string expected)
711
return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
719
/// Returns a constraint that succeeds if the actual
720
/// value matches the Regex pattern supplied as an argument.
722
public RegexConstraint Matches(string pattern)
724
return (RegexConstraint)this.Append(new RegexConstraint(pattern));
728
/// Returns a constraint that succeeds if the actual
729
/// value matches the Regex pattern supplied as an argument.
731
public RegexConstraint StringMatching(string pattern)
733
return (RegexConstraint)this.Append(new RegexConstraint(pattern));
741
/// Returns a constraint that tests whether the path provided
742
/// is the same as an expected path after canonicalization.
744
public SamePathConstraint SamePath(string expected)
746
return (SamePathConstraint)this.Append(new SamePathConstraint(expected));
754
/// Returns a constraint that tests whether the path provided
755
/// is the same path or under an expected path after canonicalization.
757
public SubPathConstraint SubPath(string expected)
759
return (SubPathConstraint)this.Append(new SubPathConstraint(expected));
764
#region SamePathOrUnder
767
/// Returns a constraint that tests whether the path provided
768
/// is the same path or under an expected path after canonicalization.
770
public SamePathOrUnderConstraint SamePathOrUnder(string expected)
772
return (SamePathOrUnderConstraint)this.Append(new SamePathOrUnderConstraint(expected));
779
#if !CLR_2_0 && !CLR_4_0
781
/// Returns a constraint that tests whether the actual value falls
782
/// within a specified range.
784
public RangeConstraint InRange(IComparable from, IComparable to)
786
return (RangeConstraint)this.Append(new RangeConstraint(from, to));
794
#if CLR_2_0 || CLR_4_0
796
/// Returns a constraint that tests whether the actual value falls
797
/// within a specified range.
799
public RangeConstraint<T> InRange<T>(T from, T to) where T : IComparable<T>
801
return (RangeConstraint<T>)this.Append(new RangeConstraint<T>(from, to));
1
// ****************************************************************
2
// Copyright 2009, Charlie Poole
3
// This is free software licensed under the NUnit license. You may
4
// obtain a copy of the license at http://nunit.org
5
// ****************************************************************
8
using System.Collections;
10
namespace NUnit.Framework.Constraints
13
/// ConstraintExpression represents a compound constraint in the
14
/// process of being constructed from a series of syntactic elements.
16
/// Individual elements are appended to the expression as they are
17
/// reognized. Once an actual Constraint is appended, the expression
18
/// returns a resolvable Constraint.
20
public class ConstraintExpression : ConstraintExpressionBase
23
/// Initializes a new instance of the <see cref="T:ConstraintExpression"/> class.
25
public ConstraintExpression() { }
28
/// Initializes a new instance of the <see cref="T:ConstraintExpression"/>
29
/// class passing in a ConstraintBuilder, which may be pre-populated.
31
/// <param name="builder">The builder.</param>
32
public ConstraintExpression(ConstraintBuilder builder)
38
/// Returns a ConstraintExpression that negates any
39
/// following constraint.
41
public ConstraintExpression Not
43
get { return this.Append(new NotOperator()); }
47
/// Returns a ConstraintExpression that negates any
48
/// following constraint.
50
public ConstraintExpression No
52
get { return this.Append(new NotOperator()); }
60
/// Returns a ConstraintExpression, which will apply
61
/// the following constraint to all members of a collection,
62
/// succeeding if all of them succeed.
64
public ConstraintExpression All
66
get { return this.Append(new AllOperator()); }
74
/// Returns a ConstraintExpression, which will apply
75
/// the following constraint to all members of a collection,
76
/// succeeding if at least one of them succeeds.
78
public ConstraintExpression Some
80
get { return this.Append(new SomeOperator()); }
88
/// Returns a ConstraintExpression, which will apply
89
/// the following constraint to all members of a collection,
90
/// succeeding if all of them fail.
92
public ConstraintExpression None
94
get { return this.Append(new NoneOperator()); }
102
/// Returns a ConstraintExpression, which will apply
103
/// the following constraint to all members of a collection,
104
/// succeeding only if a specified number of them succeed.
106
public ConstraintExpression Exactly(int expectedCount)
108
return this.Append(new ExactCountOperator(expectedCount));
116
/// Returns a new PropertyConstraintExpression, which will either
117
/// test for the existence of the named property on the object
118
/// being tested or apply any following constraint to that property.
120
public ResolvableConstraintExpression Property(string name)
122
return this.Append(new PropOperator(name));
130
/// Returns a new ConstraintExpression, which will apply the following
131
/// constraint to the Length property of the object being tested.
133
public ResolvableConstraintExpression Length
135
get { return Property("Length"); }
143
/// Returns a new ConstraintExpression, which will apply the following
144
/// constraint to the Count property of the object being tested.
146
public ResolvableConstraintExpression Count
148
get { return Property("Count"); }
156
/// Returns a new ConstraintExpression, which will apply the following
157
/// constraint to the Message property of the object being tested.
159
public ResolvableConstraintExpression Message
161
get { return Property("Message"); }
166
#region InnerException
169
/// Returns a new ConstraintExpression, which will apply the following
170
/// constraint to the InnerException property of the object being tested.
172
public ResolvableConstraintExpression InnerException
174
get { return Property("InnerException"); }
182
/// Returns a new AttributeConstraint checking for the
183
/// presence of a particular attribute on an object.
185
public ResolvableConstraintExpression Attribute(Type expectedType)
187
return this.Append(new AttributeOperator(expectedType));
190
#if CLR_2_0 || CLR_4_0
192
/// Returns a new AttributeConstraint checking for the
193
/// presence of a particular attribute on an object.
195
public ResolvableConstraintExpression Attribute<T>()
197
return Attribute(typeof(T));
206
/// With is currently a NOP - reserved for future use.
208
public ConstraintExpression With
210
get { return this.Append(new WithOperator()); }
218
/// Returns the constraint provided as an argument - used to allow custom
219
/// custom constraints to easily participate in the syntax.
221
public Constraint Matches(Constraint constraint)
223
return this.Append(constraint);
226
#if CLR_2_0 || CLR_4_0
228
/// Returns the constraint provided as an argument - used to allow custom
229
/// custom constraints to easily participate in the syntax.
231
public Constraint Matches<T>(Predicate<T> predicate)
233
return this.Append(new PredicateConstraint<T>(predicate));
242
/// Returns a constraint that tests for null
244
public NullConstraint Null
246
get { return (NullConstraint)this.Append(new NullConstraint()); }
254
/// Returns a constraint that tests for True
256
public TrueConstraint True
258
get { return (TrueConstraint)this.Append(new TrueConstraint()); }
266
/// Returns a constraint that tests for False
268
public FalseConstraint False
270
get { return (FalseConstraint)this.Append(new FalseConstraint()); }
278
/// Returns a constraint that tests for a positive value
280
public GreaterThanConstraint Positive
282
get { return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(0)); }
290
/// Returns a constraint that tests for a negative value
292
public LessThanConstraint Negative
294
get { return (LessThanConstraint)this.Append(new LessThanConstraint(0)); }
302
/// Returns a constraint that tests for NaN
304
public NaNConstraint NaN
306
get { return (NaNConstraint)this.Append(new NaNConstraint()); }
314
/// Returns a constraint that tests for empty
316
public EmptyConstraint Empty
318
get { return (EmptyConstraint)this.Append(new EmptyConstraint()); }
326
/// Returns a constraint that tests whether a collection
327
/// contains all unique items.
329
public UniqueItemsConstraint Unique
331
get { return (UniqueItemsConstraint)this.Append(new UniqueItemsConstraint()); }
336
#region BinarySerializable
339
/// Returns a constraint that tests whether an object graph is serializable in binary format.
341
public BinarySerializableConstraint BinarySerializable
343
get { return (BinarySerializableConstraint)this.Append(new BinarySerializableConstraint()); }
348
#region XmlSerializable
351
/// Returns a constraint that tests whether an object graph is serializable in xml format.
353
public XmlSerializableConstraint XmlSerializable
355
get { return (XmlSerializableConstraint)this.Append(new XmlSerializableConstraint()); }
363
/// Returns a constraint that tests two items for equality
365
public EqualConstraint EqualTo(object expected)
367
return (EqualConstraint)this.Append(new EqualConstraint(expected));
375
/// Returns a constraint that tests that two references are the same object
377
public SameAsConstraint SameAs(object expected)
379
return (SameAsConstraint)this.Append(new SameAsConstraint(expected));
387
/// Returns a constraint that tests whether the
388
/// actual value is greater than the suppled argument
390
public GreaterThanConstraint GreaterThan(object expected)
392
return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(expected));
397
#region GreaterThanOrEqualTo
400
/// Returns a constraint that tests whether the
401
/// actual value is greater than or equal to the suppled argument
403
public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
405
return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
409
/// Returns a constraint that tests whether the
410
/// actual value is greater than or equal to the suppled argument
412
public GreaterThanOrEqualConstraint AtLeast(object expected)
414
return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
422
/// Returns a constraint that tests whether the
423
/// actual value is less than the suppled argument
425
public LessThanConstraint LessThan(object expected)
427
return (LessThanConstraint)this.Append(new LessThanConstraint(expected));
432
#region LessThanOrEqualTo
435
/// Returns a constraint that tests whether the
436
/// actual value is less than or equal to the suppled argument
438
public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
440
return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
444
/// Returns a constraint that tests whether the
445
/// actual value is less than or equal to the suppled argument
447
public LessThanOrEqualConstraint AtMost(object expected)
449
return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
457
/// Returns a constraint that tests whether the actual
458
/// value is of the exact type supplied as an argument.
460
public ExactTypeConstraint TypeOf(Type expectedType)
462
return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(expectedType));
465
#if CLR_2_0 || CLR_4_0
467
/// Returns a constraint that tests whether the actual
468
/// value is of the exact type supplied as an argument.
470
public ExactTypeConstraint TypeOf<T>()
472
return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(typeof(T)));
481
/// Returns a constraint that tests whether the actual value
482
/// is of the type supplied as an argument or a derived type.
484
public InstanceOfTypeConstraint InstanceOf(Type expectedType)
486
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
489
#if CLR_2_0 || CLR_4_0
491
/// Returns a constraint that tests whether the actual value
492
/// is of the type supplied as an argument or a derived type.
494
public InstanceOfTypeConstraint InstanceOf<T>()
496
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
501
/// Returns a constraint that tests whether the actual value
502
/// is of the type supplied as an argument or a derived type.
504
[Obsolete("Use InstanceOf(expectedType)")]
505
public InstanceOfTypeConstraint InstanceOfType(Type expectedType)
507
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
510
#if CLR_2_0 || CLR_4_0
512
/// Returns a constraint that tests whether the actual value
513
/// is of the type supplied as an argument or a derived type.
515
[Obsolete("Use InstanceOf<T>()")]
516
public InstanceOfTypeConstraint InstanceOfType<T>()
518
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
524
#region AssignableFrom
527
/// Returns a constraint that tests whether the actual value
528
/// is assignable from the type supplied as an argument.
530
public AssignableFromConstraint AssignableFrom(Type expectedType)
532
return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(expectedType));
535
#if CLR_2_0 || CLR_4_0
537
/// Returns a constraint that tests whether the actual value
538
/// is assignable from the type supplied as an argument.
540
public AssignableFromConstraint AssignableFrom<T>()
542
return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(typeof(T)));
551
/// Returns a constraint that tests whether the actual value
552
/// is assignable from the type supplied as an argument.
554
public AssignableToConstraint AssignableTo(Type expectedType)
556
return (AssignableToConstraint)this.Append(new AssignableToConstraint(expectedType));
559
#if CLR_2_0 || CLR_4_0
561
/// Returns a constraint that tests whether the actual value
562
/// is assignable from the type supplied as an argument.
564
public AssignableToConstraint AssignableTo<T>()
566
return (AssignableToConstraint)this.Append(new AssignableToConstraint(typeof(T)));
575
/// Returns a constraint that tests whether the actual value
576
/// is a collection containing the same elements as the
577
/// collection supplied as an argument.
579
public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
581
return (CollectionEquivalentConstraint)this.Append(new CollectionEquivalentConstraint(expected));
589
/// Returns a constraint that tests whether the actual value
590
/// is a subset of the collection supplied as an argument.
592
public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
594
return (CollectionSubsetConstraint)this.Append(new CollectionSubsetConstraint(expected));
602
/// Returns a constraint that tests whether a collection is ordered
604
public CollectionOrderedConstraint Ordered
606
get { return (CollectionOrderedConstraint)this.Append(new CollectionOrderedConstraint()); }
614
/// Returns a new CollectionContainsConstraint checking for the
615
/// presence of a particular object in the collection.
617
public CollectionContainsConstraint Member(object expected)
619
return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
623
/// Returns a new CollectionContainsConstraint checking for the
624
/// presence of a particular object in the collection.
626
public CollectionContainsConstraint Contains(object expected)
628
return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
636
/// Returns a new ContainsConstraint. This constraint
637
/// will, in turn, make use of the appropriate second-level
638
/// constraint, depending on the type of the actual argument.
639
/// This overload is only used if the item sought is a string,
640
/// since any other type implies that we are looking for a
641
/// collection member.
643
public ContainsConstraint Contains(string expected)
645
return (ContainsConstraint)this.Append(new ContainsConstraint(expected));
650
#region StringContaining
653
/// Returns a constraint that succeeds if the actual
654
/// value contains the substring supplied as an argument.
656
public SubstringConstraint StringContaining(string expected)
658
return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
662
/// Returns a constraint that succeeds if the actual
663
/// value contains the substring supplied as an argument.
665
public SubstringConstraint ContainsSubstring(string expected)
667
return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
675
/// Returns a constraint that succeeds if the actual
676
/// value starts with the substring supplied as an argument.
678
public StartsWithConstraint StartsWith(string expected)
680
return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
684
/// Returns a constraint that succeeds if the actual
685
/// value starts with the substring supplied as an argument.
687
public StartsWithConstraint StringStarting(string expected)
689
return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
697
/// Returns a constraint that succeeds if the actual
698
/// value ends with the substring supplied as an argument.
700
public EndsWithConstraint EndsWith(string expected)
702
return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
706
/// Returns a constraint that succeeds if the actual
707
/// value ends with the substring supplied as an argument.
709
public EndsWithConstraint StringEnding(string expected)
711
return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
719
/// Returns a constraint that succeeds if the actual
720
/// value matches the regular expression supplied as an argument.
722
public RegexConstraint Matches(string pattern)
724
return (RegexConstraint)this.Append(new RegexConstraint(pattern));
728
/// Returns a constraint that succeeds if the actual
729
/// value matches the regular expression supplied as an argument.
731
public RegexConstraint StringMatching(string pattern)
733
return (RegexConstraint)this.Append(new RegexConstraint(pattern));
741
/// Returns a constraint that tests whether the path provided
742
/// is the same as an expected path after canonicalization.
744
public SamePathConstraint SamePath(string expected)
746
return (SamePathConstraint)this.Append(new SamePathConstraint(expected));
754
/// Returns a constraint that tests whether the path provided
755
/// is the same path or under an expected path after canonicalization.
757
public SubPathConstraint SubPath(string expected)
759
return (SubPathConstraint)this.Append(new SubPathConstraint(expected));
764
#region SamePathOrUnder
767
/// Returns a constraint that tests whether the path provided
768
/// is the same path or under an expected path after canonicalization.
770
public SamePathOrUnderConstraint SamePathOrUnder(string expected)
772
return (SamePathOrUnderConstraint)this.Append(new SamePathOrUnderConstraint(expected));
779
#if CLR_2_0 || CLR_4_0
781
/// Returns a constraint that tests whether the actual value falls
782
/// within a specified range.
784
public RangeConstraint<T> InRange<T>(T from, T to) where T : IComparable<T>
786
return (RangeConstraint<T>)this.Append(new RangeConstraint<T>(from, to));
790
/// Returns a constraint that tests whether the actual value falls
791
/// within a specified range.
793
public RangeConstraint InRange(IComparable from, IComparable to)
795
return (RangeConstraint)this.Append(new RangeConstraint(from, to));