~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/NUnitFramework/framework/Constraints/ConstraintExpression.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
// ****************************************************************
6
 
 
7
 
using System;
8
 
using System.Collections;
9
 
 
10
 
namespace NUnit.Framework.Constraints
11
 
{
12
 
    /// <summary>
13
 
    /// ConstraintExpression represents a compound constraint in the 
14
 
    /// process of being constructed from a series of syntactic elements.
15
 
    /// 
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.
19
 
    /// </summary>
20
 
    public class ConstraintExpression : ConstraintExpressionBase
21
 
    {
22
 
        /// <summary>
23
 
        /// Initializes a new instance of the <see cref="T:ConstraintExpression"/> class.
24
 
        /// </summary>
25
 
        public ConstraintExpression() { }
26
 
 
27
 
        /// <summary>
28
 
        /// Initializes a new instance of the <see cref="T:ConstraintExpression"/> 
29
 
        /// class passing in a ConstraintBuilder, which may be pre-populated.
30
 
        /// </summary>
31
 
        /// <param name="builder">The builder.</param>
32
 
        public ConstraintExpression(ConstraintBuilder builder)
33
 
            : base( builder ) { }
34
 
 
35
 
        #region Not
36
 
 
37
 
        /// <summary>
38
 
        /// Returns a ConstraintExpression that negates any
39
 
        /// following constraint.
40
 
        /// </summary>
41
 
        public ConstraintExpression Not
42
 
        {
43
 
            get { return this.Append(new NotOperator()); }
44
 
        }
45
 
 
46
 
        /// <summary>
47
 
        /// Returns a ConstraintExpression that negates any
48
 
        /// following constraint.
49
 
        /// </summary>
50
 
        public ConstraintExpression No
51
 
        {
52
 
            get { return this.Append(new NotOperator()); }
53
 
        }
54
 
 
55
 
        #endregion
56
 
 
57
 
        #region All
58
 
 
59
 
        /// <summary>
60
 
        /// Returns a ConstraintExpression, which will apply
61
 
        /// the following constraint to all members of a collection,
62
 
        /// succeeding if all of them succeed.
63
 
        /// </summary>
64
 
        public ConstraintExpression All
65
 
        {
66
 
            get { return this.Append(new AllOperator()); }
67
 
        }
68
 
 
69
 
        #endregion
70
 
 
71
 
        #region Some
72
 
 
73
 
        /// <summary>
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.
77
 
        /// </summary>
78
 
        public ConstraintExpression Some
79
 
        {
80
 
            get { return this.Append(new SomeOperator()); }
81
 
        }
82
 
 
83
 
        #endregion
84
 
 
85
 
        #region None
86
 
 
87
 
        /// <summary>
88
 
        /// Returns a ConstraintExpression, which will apply
89
 
        /// the following constraint to all members of a collection,
90
 
        /// succeeding if all of them fail.
91
 
        /// </summary>
92
 
        public ConstraintExpression None
93
 
        {
94
 
            get { return this.Append(new NoneOperator()); }
95
 
        }
96
 
 
97
 
        #endregion
98
 
 
99
 
        #region Exactly(n)
100
 
 
101
 
        /// <summary>
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.
105
 
        /// </summary>
106
 
        public ConstraintExpression Exactly(int expectedCount)
107
 
        {
108
 
            return this.Append(new ExactCountOperator(expectedCount));
109
 
        }
110
 
 
111
 
        #endregion
112
 
 
113
 
        #region Property
114
 
 
115
 
        /// <summary>
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.
119
 
        /// </summary>
120
 
        public ResolvableConstraintExpression Property(string name)
121
 
        {
122
 
            return this.Append(new PropOperator(name));
123
 
        }
124
 
 
125
 
        #endregion
126
 
 
127
 
        #region Length
128
 
 
129
 
        /// <summary>
130
 
        /// Returns a new ConstraintExpression, which will apply the following
131
 
        /// constraint to the Length property of the object being tested.
132
 
        /// </summary>
133
 
        public ResolvableConstraintExpression Length
134
 
        {
135
 
            get { return Property("Length"); }
136
 
        }
137
 
 
138
 
        #endregion
139
 
 
140
 
        #region Count
141
 
 
142
 
        /// <summary>
143
 
        /// Returns a new ConstraintExpression, which will apply the following
144
 
        /// constraint to the Count property of the object being tested.
145
 
        /// </summary>
146
 
        public ResolvableConstraintExpression Count
147
 
        {
148
 
            get { return Property("Count"); }
149
 
        }
150
 
 
151
 
        #endregion
152
 
 
153
 
        #region Message
154
 
 
155
 
        /// <summary>
156
 
        /// Returns a new ConstraintExpression, which will apply the following
157
 
        /// constraint to the Message property of the object being tested.
158
 
        /// </summary>
159
 
        public ResolvableConstraintExpression Message
160
 
        {
161
 
            get { return Property("Message"); }
162
 
        }
163
 
 
164
 
        #endregion
165
 
 
166
 
        #region InnerException
167
 
 
168
 
        /// <summary>
169
 
        /// Returns a new ConstraintExpression, which will apply the following
170
 
        /// constraint to the InnerException property of the object being tested.
171
 
        /// </summary>
172
 
        public ResolvableConstraintExpression InnerException
173
 
        {
174
 
            get { return Property("InnerException"); }
175
 
        }
176
 
 
177
 
        #endregion
178
 
 
179
 
        #region Attribute
180
 
 
181
 
        /// <summary>
182
 
        /// Returns a new AttributeConstraint checking for the
183
 
        /// presence of a particular attribute on an object.
184
 
        /// </summary>
185
 
        public ResolvableConstraintExpression Attribute(Type expectedType)
186
 
        {
187
 
            return this.Append(new AttributeOperator(expectedType));
188
 
        }
189
 
 
190
 
#if CLR_2_0 || CLR_4_0
191
 
        /// <summary>
192
 
        /// Returns a new AttributeConstraint checking for the
193
 
        /// presence of a particular attribute on an object.
194
 
        /// </summary>
195
 
        public ResolvableConstraintExpression Attribute<T>()
196
 
        {
197
 
            return Attribute(typeof(T));
198
 
        }
199
 
#endif
200
 
 
201
 
        #endregion
202
 
 
203
 
        #region With
204
 
 
205
 
        /// <summary>
206
 
        /// With is currently a NOP - reserved for future use.
207
 
        /// </summary>
208
 
        public ConstraintExpression With
209
 
        {
210
 
            get { return this.Append(new WithOperator()); }
211
 
        }
212
 
 
213
 
        #endregion
214
 
 
215
 
        #region Matches
216
 
 
217
 
        /// <summary>
218
 
        /// Returns the constraint provided as an argument - used to allow custom
219
 
        /// custom constraints to easily participate in the syntax.
220
 
        /// </summary>
221
 
        public Constraint Matches(Constraint constraint)
222
 
        {
223
 
            return this.Append(constraint);
224
 
        }
225
 
 
226
 
#if CLR_2_0 || CLR_4_0
227
 
        /// <summary>
228
 
        /// Returns the constraint provided as an argument - used to allow custom
229
 
        /// custom constraints to easily participate in the syntax.
230
 
        /// </summary>
231
 
        public Constraint Matches<T>(Predicate<T> predicate)
232
 
        {
233
 
            return this.Append(new PredicateConstraint<T>(predicate));
234
 
        }
235
 
#endif
236
 
 
237
 
        #endregion
238
 
 
239
 
        #region Null
240
 
 
241
 
        /// <summary>
242
 
        /// Returns a constraint that tests for null
243
 
        /// </summary>
244
 
        public NullConstraint Null
245
 
        {
246
 
            get { return (NullConstraint)this.Append(new NullConstraint()); }
247
 
        }
248
 
 
249
 
        #endregion
250
 
 
251
 
        #region True
252
 
 
253
 
        /// <summary>
254
 
        /// Returns a constraint that tests for True
255
 
        /// </summary>
256
 
        public TrueConstraint True
257
 
        {
258
 
            get { return (TrueConstraint)this.Append(new TrueConstraint()); }
259
 
        }
260
 
 
261
 
        #endregion
262
 
 
263
 
        #region False
264
 
 
265
 
        /// <summary>
266
 
        /// Returns a constraint that tests for False
267
 
        /// </summary>
268
 
        public FalseConstraint False
269
 
        {
270
 
            get { return (FalseConstraint)this.Append(new FalseConstraint()); }
271
 
        }
272
 
 
273
 
        #endregion
274
 
 
275
 
        #region Positive
276
 
 
277
 
        /// <summary>
278
 
        /// Returns a constraint that tests for a positive value
279
 
        /// </summary>
280
 
        public GreaterThanConstraint Positive
281
 
        {
282
 
            get { return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(0)); }
283
 
        }
284
 
 
285
 
        #endregion
286
 
 
287
 
        #region Negative
288
 
 
289
 
        /// <summary>
290
 
        /// Returns a constraint that tests for a negative value
291
 
        /// </summary>
292
 
        public LessThanConstraint Negative
293
 
        {
294
 
            get { return (LessThanConstraint)this.Append(new LessThanConstraint(0)); }
295
 
        }
296
 
 
297
 
        #endregion
298
 
 
299
 
        #region NaN
300
 
 
301
 
        /// <summary>
302
 
        /// Returns a constraint that tests for NaN
303
 
        /// </summary>
304
 
        public NaNConstraint NaN
305
 
        {
306
 
            get { return (NaNConstraint)this.Append(new NaNConstraint()); }
307
 
        }
308
 
 
309
 
        #endregion
310
 
 
311
 
        #region Empty
312
 
 
313
 
        /// <summary>
314
 
        /// Returns a constraint that tests for empty
315
 
        /// </summary>
316
 
        public EmptyConstraint Empty
317
 
        {
318
 
            get { return (EmptyConstraint)this.Append(new EmptyConstraint()); }
319
 
        }
320
 
 
321
 
        #endregion
322
 
 
323
 
        #region Unique
324
 
 
325
 
        /// <summary>
326
 
        /// Returns a constraint that tests whether a collection 
327
 
        /// contains all unique items.
328
 
        /// </summary>
329
 
        public UniqueItemsConstraint Unique
330
 
        {
331
 
            get { return (UniqueItemsConstraint)this.Append(new UniqueItemsConstraint()); }
332
 
        }
333
 
 
334
 
        #endregion
335
 
 
336
 
        #region BinarySerializable
337
 
 
338
 
        /// <summary>
339
 
        /// Returns a constraint that tests whether an object graph is serializable in binary format.
340
 
        /// </summary>
341
 
        public BinarySerializableConstraint BinarySerializable
342
 
        {
343
 
            get { return (BinarySerializableConstraint)this.Append(new BinarySerializableConstraint()); }
344
 
        }
345
 
 
346
 
        #endregion
347
 
 
348
 
        #region XmlSerializable
349
 
 
350
 
        /// <summary>
351
 
        /// Returns a constraint that tests whether an object graph is serializable in xml format.
352
 
        /// </summary>
353
 
        public XmlSerializableConstraint XmlSerializable
354
 
        {
355
 
            get { return (XmlSerializableConstraint)this.Append(new XmlSerializableConstraint()); }
356
 
        }
357
 
 
358
 
        #endregion
359
 
 
360
 
        #region EqualTo
361
 
 
362
 
        /// <summary>
363
 
        /// Returns a constraint that tests two items for equality
364
 
        /// </summary>
365
 
        public EqualConstraint EqualTo(object expected)
366
 
        {
367
 
            return (EqualConstraint)this.Append(new EqualConstraint(expected));
368
 
        }
369
 
 
370
 
        #endregion
371
 
 
372
 
        #region SameAs
373
 
 
374
 
        /// <summary>
375
 
        /// Returns a constraint that tests that two references are the same object
376
 
        /// </summary>
377
 
        public SameAsConstraint SameAs(object expected)
378
 
        {
379
 
            return (SameAsConstraint)this.Append(new SameAsConstraint(expected));
380
 
        }
381
 
 
382
 
        #endregion
383
 
 
384
 
        #region GreaterThan
385
 
 
386
 
        /// <summary>
387
 
        /// Returns a constraint that tests whether the
388
 
        /// actual value is greater than the suppled argument
389
 
        /// </summary>
390
 
        public GreaterThanConstraint GreaterThan(object expected)
391
 
        {
392
 
            return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(expected));
393
 
        }
394
 
 
395
 
        #endregion
396
 
 
397
 
        #region GreaterThanOrEqualTo
398
 
 
399
 
        /// <summary>
400
 
        /// Returns a constraint that tests whether the
401
 
        /// actual value is greater than or equal to the suppled argument
402
 
        /// </summary>
403
 
        public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
404
 
        {
405
 
            return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
406
 
        }
407
 
 
408
 
        /// <summary>
409
 
        /// Returns a constraint that tests whether the
410
 
        /// actual value is greater than or equal to the suppled argument
411
 
        /// </summary>
412
 
        public GreaterThanOrEqualConstraint AtLeast(object expected)
413
 
        {
414
 
            return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
415
 
        }
416
 
 
417
 
        #endregion
418
 
 
419
 
        #region LessThan
420
 
 
421
 
        /// <summary>
422
 
        /// Returns a constraint that tests whether the
423
 
        /// actual value is less than the suppled argument
424
 
        /// </summary>
425
 
        public LessThanConstraint LessThan(object expected)
426
 
        {
427
 
            return (LessThanConstraint)this.Append(new LessThanConstraint(expected));
428
 
        }
429
 
 
430
 
        #endregion
431
 
 
432
 
        #region LessThanOrEqualTo
433
 
 
434
 
        /// <summary>
435
 
        /// Returns a constraint that tests whether the
436
 
        /// actual value is less than or equal to the suppled argument
437
 
        /// </summary>
438
 
        public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
439
 
        {
440
 
            return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
441
 
        }
442
 
 
443
 
        /// <summary>
444
 
        /// Returns a constraint that tests whether the
445
 
        /// actual value is less than or equal to the suppled argument
446
 
        /// </summary>
447
 
        public LessThanOrEqualConstraint AtMost(object expected)
448
 
        {
449
 
            return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
450
 
        }
451
 
 
452
 
        #endregion
453
 
 
454
 
        #region TypeOf
455
 
 
456
 
        /// <summary>
457
 
        /// Returns a constraint that tests whether the actual
458
 
        /// value is of the exact type supplied as an argument.
459
 
        /// </summary>
460
 
        public ExactTypeConstraint TypeOf(Type expectedType)
461
 
        {
462
 
            return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(expectedType));
463
 
        }
464
 
 
465
 
#if CLR_2_0 || CLR_4_0
466
 
        /// <summary>
467
 
        /// Returns a constraint that tests whether the actual
468
 
        /// value is of the exact type supplied as an argument.
469
 
        /// </summary>
470
 
        public ExactTypeConstraint TypeOf<T>()
471
 
        {
472
 
            return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(typeof(T)));
473
 
        }
474
 
#endif
475
 
 
476
 
        #endregion
477
 
 
478
 
        #region InstanceOf
479
 
 
480
 
        /// <summary>
481
 
        /// Returns a constraint that tests whether the actual value
482
 
        /// is of the type supplied as an argument or a derived type.
483
 
        /// </summary>
484
 
        public InstanceOfTypeConstraint InstanceOf(Type expectedType)
485
 
        {
486
 
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
487
 
        }
488
 
 
489
 
#if CLR_2_0 || CLR_4_0
490
 
        /// <summary>
491
 
        /// Returns a constraint that tests whether the actual value
492
 
        /// is of the type supplied as an argument or a derived type.
493
 
        /// </summary>
494
 
        public InstanceOfTypeConstraint InstanceOf<T>()
495
 
        {
496
 
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
497
 
        }
498
 
#endif
499
 
 
500
 
        /// <summary>
501
 
        /// Returns a constraint that tests whether the actual value
502
 
        /// is of the type supplied as an argument or a derived type.
503
 
        /// </summary>
504
 
        [Obsolete("Use InstanceOf(expectedType)")]
505
 
        public InstanceOfTypeConstraint InstanceOfType(Type expectedType)
506
 
        {
507
 
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
508
 
        }
509
 
 
510
 
#if CLR_2_0 || CLR_4_0
511
 
        /// <summary>
512
 
        /// Returns a constraint that tests whether the actual value
513
 
        /// is of the type supplied as an argument or a derived type.
514
 
        /// </summary>
515
 
        [Obsolete("Use InstanceOf<T>()")]
516
 
        public InstanceOfTypeConstraint InstanceOfType<T>()
517
 
        {
518
 
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
519
 
        }
520
 
#endif
521
 
 
522
 
        #endregion
523
 
 
524
 
        #region AssignableFrom
525
 
 
526
 
        /// <summary>
527
 
        /// Returns a constraint that tests whether the actual value
528
 
        /// is assignable from the type supplied as an argument.
529
 
        /// </summary>
530
 
        public AssignableFromConstraint AssignableFrom(Type expectedType)
531
 
        {
532
 
            return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(expectedType));
533
 
        }
534
 
 
535
 
#if CLR_2_0 || CLR_4_0
536
 
        /// <summary>
537
 
        /// Returns a constraint that tests whether the actual value
538
 
        /// is assignable from the type supplied as an argument.
539
 
        /// </summary>
540
 
        public AssignableFromConstraint AssignableFrom<T>()
541
 
        {
542
 
            return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(typeof(T)));
543
 
        }
544
 
#endif
545
 
 
546
 
        #endregion
547
 
 
548
 
        #region AssignableTo
549
 
 
550
 
        /// <summary>
551
 
        /// Returns a constraint that tests whether the actual value
552
 
        /// is assignable from the type supplied as an argument.
553
 
        /// </summary>
554
 
        public AssignableToConstraint AssignableTo(Type expectedType)
555
 
        {
556
 
            return (AssignableToConstraint)this.Append(new AssignableToConstraint(expectedType));
557
 
        }
558
 
 
559
 
#if CLR_2_0 || CLR_4_0
560
 
        /// <summary>
561
 
        /// Returns a constraint that tests whether the actual value
562
 
        /// is assignable from the type supplied as an argument.
563
 
        /// </summary>
564
 
        public AssignableToConstraint AssignableTo<T>()
565
 
        {
566
 
            return (AssignableToConstraint)this.Append(new AssignableToConstraint(typeof(T)));
567
 
        }
568
 
#endif
569
 
 
570
 
        #endregion
571
 
 
572
 
        #region EquivalentTo
573
 
 
574
 
        /// <summary>
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.
578
 
        /// </summary>
579
 
        public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
580
 
        {
581
 
            return (CollectionEquivalentConstraint)this.Append(new CollectionEquivalentConstraint(expected));
582
 
        }
583
 
 
584
 
        #endregion
585
 
 
586
 
        #region SubsetOf
587
 
 
588
 
        /// <summary>
589
 
        /// Returns a constraint that tests whether the actual value
590
 
        /// is a subset of the collection supplied as an argument.
591
 
        /// </summary>
592
 
        public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
593
 
        {
594
 
            return (CollectionSubsetConstraint)this.Append(new CollectionSubsetConstraint(expected));
595
 
        }
596
 
 
597
 
        #endregion
598
 
 
599
 
        #region Ordered
600
 
 
601
 
        /// <summary>
602
 
        /// Returns a constraint that tests whether a collection is ordered
603
 
        /// </summary>
604
 
        public CollectionOrderedConstraint Ordered
605
 
        {
606
 
            get { return (CollectionOrderedConstraint)this.Append(new CollectionOrderedConstraint()); }
607
 
        }
608
 
 
609
 
        #endregion
610
 
 
611
 
        #region Member
612
 
 
613
 
        /// <summary>
614
 
        /// Returns a new CollectionContainsConstraint checking for the
615
 
        /// presence of a particular object in the collection.
616
 
        /// </summary>
617
 
        public CollectionContainsConstraint Member(object expected)
618
 
        {
619
 
            return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
620
 
        }
621
 
 
622
 
        /// <summary>
623
 
        /// Returns a new CollectionContainsConstraint checking for the
624
 
        /// presence of a particular object in the collection.
625
 
        /// </summary>
626
 
        public CollectionContainsConstraint Contains(object expected)
627
 
        {
628
 
            return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
629
 
        }
630
 
 
631
 
        #endregion
632
 
 
633
 
        #region Contains
634
 
 
635
 
        /// <summary>
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.
642
 
        /// </summary>
643
 
        public ContainsConstraint Contains(string expected)
644
 
        {
645
 
            return (ContainsConstraint)this.Append(new ContainsConstraint(expected));
646
 
        }
647
 
 
648
 
        #endregion
649
 
 
650
 
        #region StringContaining
651
 
 
652
 
        /// <summary>
653
 
        /// Returns a constraint that succeeds if the actual
654
 
        /// value contains the substring supplied as an argument.
655
 
        /// </summary>
656
 
        public SubstringConstraint StringContaining(string expected)
657
 
        {
658
 
            return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
659
 
        }
660
 
 
661
 
        /// <summary>
662
 
        /// Returns a constraint that succeeds if the actual
663
 
        /// value contains the substring supplied as an argument.
664
 
        /// </summary>
665
 
        public SubstringConstraint ContainsSubstring(string expected)
666
 
        {
667
 
            return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
668
 
        }
669
 
 
670
 
        #endregion
671
 
 
672
 
        #region StartsWith
673
 
 
674
 
        /// <summary>
675
 
        /// Returns a constraint that succeeds if the actual
676
 
        /// value starts with the substring supplied as an argument.
677
 
        /// </summary>
678
 
        public StartsWithConstraint StartsWith(string expected)
679
 
        {
680
 
            return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
681
 
        }
682
 
 
683
 
        /// <summary>
684
 
        /// Returns a constraint that succeeds if the actual
685
 
        /// value starts with the substring supplied as an argument.
686
 
        /// </summary>
687
 
        public StartsWithConstraint StringStarting(string expected)
688
 
        {
689
 
            return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
690
 
        }
691
 
 
692
 
        #endregion
693
 
 
694
 
        #region EndsWith
695
 
 
696
 
        /// <summary>
697
 
        /// Returns a constraint that succeeds if the actual
698
 
        /// value ends with the substring supplied as an argument.
699
 
        /// </summary>
700
 
        public EndsWithConstraint EndsWith(string expected)
701
 
        {
702
 
            return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
703
 
        }
704
 
 
705
 
        /// <summary>
706
 
        /// Returns a constraint that succeeds if the actual
707
 
        /// value ends with the substring supplied as an argument.
708
 
        /// </summary>
709
 
        public EndsWithConstraint StringEnding(string expected)
710
 
        {
711
 
            return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
712
 
        }
713
 
 
714
 
        #endregion
715
 
 
716
 
        #region Matches
717
 
 
718
 
        /// <summary>
719
 
        /// Returns a constraint that succeeds if the actual
720
 
        /// value matches the Regex pattern supplied as an argument.
721
 
        /// </summary>
722
 
        public RegexConstraint Matches(string pattern)
723
 
        {
724
 
            return (RegexConstraint)this.Append(new RegexConstraint(pattern));
725
 
        }
726
 
 
727
 
        /// <summary>
728
 
        /// Returns a constraint that succeeds if the actual
729
 
        /// value matches the Regex pattern supplied as an argument.
730
 
        /// </summary>
731
 
        public RegexConstraint StringMatching(string pattern)
732
 
        {
733
 
            return (RegexConstraint)this.Append(new RegexConstraint(pattern));
734
 
        }
735
 
 
736
 
        #endregion
737
 
 
738
 
        #region SamePath
739
 
 
740
 
        /// <summary>
741
 
        /// Returns a constraint that tests whether the path provided 
742
 
        /// is the same as an expected path after canonicalization.
743
 
        /// </summary>
744
 
        public SamePathConstraint SamePath(string expected)
745
 
        {
746
 
            return (SamePathConstraint)this.Append(new SamePathConstraint(expected));
747
 
        }
748
 
 
749
 
        #endregion
750
 
 
751
 
        #region SubPath
752
 
 
753
 
        /// <summary>
754
 
        /// Returns a constraint that tests whether the path provided 
755
 
        /// is the same path or under an expected path after canonicalization.
756
 
        /// </summary>
757
 
        public SubPathConstraint SubPath(string expected)
758
 
        {
759
 
            return (SubPathConstraint)this.Append(new SubPathConstraint(expected));
760
 
        }
761
 
 
762
 
        #endregion
763
 
 
764
 
        #region SamePathOrUnder
765
 
 
766
 
        /// <summary>
767
 
        /// Returns a constraint that tests whether the path provided 
768
 
        /// is the same path or under an expected path after canonicalization.
769
 
        /// </summary>
770
 
        public SamePathOrUnderConstraint SamePathOrUnder(string expected)
771
 
        {
772
 
            return (SamePathOrUnderConstraint)this.Append(new SamePathOrUnderConstraint(expected));
773
 
        }
774
 
 
775
 
        #endregion
776
 
 
777
 
        #region InRange
778
 
 
779
 
#if !CLR_2_0 && !CLR_4_0
780
 
        /// <summary>
781
 
        /// Returns a constraint that tests whether the actual value falls 
782
 
        /// within a specified range.
783
 
        /// </summary>
784
 
        public RangeConstraint InRange(IComparable from, IComparable to)
785
 
        {
786
 
            return (RangeConstraint)this.Append(new RangeConstraint(from, to));
787
 
        }
788
 
#endif
789
 
 
790
 
        #endregion
791
 
 
792
 
        #region InRange<T>
793
 
 
794
 
#if CLR_2_0 || CLR_4_0
795
 
        /// <summary>
796
 
        /// Returns a constraint that tests whether the actual value falls 
797
 
        /// within a specified range.
798
 
        /// </summary>
799
 
        public RangeConstraint<T> InRange<T>(T from, T to) where T : IComparable<T>
800
 
        {
801
 
            return (RangeConstraint<T>)this.Append(new RangeConstraint<T>(from, to));
802
 
        }
803
 
#endif
804
 
 
805
 
        #endregion
806
 
 
807
 
    }
808
 
}
 
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
// ****************************************************************
 
6
 
 
7
using System;
 
8
using System.Collections;
 
9
 
 
10
namespace NUnit.Framework.Constraints
 
11
{
 
12
    /// <summary>
 
13
    /// ConstraintExpression represents a compound constraint in the 
 
14
    /// process of being constructed from a series of syntactic elements.
 
15
    /// 
 
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.
 
19
    /// </summary>
 
20
    public class ConstraintExpression : ConstraintExpressionBase
 
21
    {
 
22
        /// <summary>
 
23
        /// Initializes a new instance of the <see cref="T:ConstraintExpression"/> class.
 
24
        /// </summary>
 
25
        public ConstraintExpression() { }
 
26
 
 
27
        /// <summary>
 
28
        /// Initializes a new instance of the <see cref="T:ConstraintExpression"/> 
 
29
        /// class passing in a ConstraintBuilder, which may be pre-populated.
 
30
        /// </summary>
 
31
        /// <param name="builder">The builder.</param>
 
32
        public ConstraintExpression(ConstraintBuilder builder)
 
33
            : base( builder ) { }
 
34
 
 
35
        #region Not
 
36
 
 
37
        /// <summary>
 
38
        /// Returns a ConstraintExpression that negates any
 
39
        /// following constraint.
 
40
        /// </summary>
 
41
        public ConstraintExpression Not
 
42
        {
 
43
            get { return this.Append(new NotOperator()); }
 
44
        }
 
45
 
 
46
        /// <summary>
 
47
        /// Returns a ConstraintExpression that negates any
 
48
        /// following constraint.
 
49
        /// </summary>
 
50
        public ConstraintExpression No
 
51
        {
 
52
            get { return this.Append(new NotOperator()); }
 
53
        }
 
54
 
 
55
        #endregion
 
56
 
 
57
        #region All
 
58
 
 
59
        /// <summary>
 
60
        /// Returns a ConstraintExpression, which will apply
 
61
        /// the following constraint to all members of a collection,
 
62
        /// succeeding if all of them succeed.
 
63
        /// </summary>
 
64
        public ConstraintExpression All
 
65
        {
 
66
            get { return this.Append(new AllOperator()); }
 
67
        }
 
68
 
 
69
        #endregion
 
70
 
 
71
        #region Some
 
72
 
 
73
        /// <summary>
 
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.
 
77
        /// </summary>
 
78
        public ConstraintExpression Some
 
79
        {
 
80
            get { return this.Append(new SomeOperator()); }
 
81
        }
 
82
 
 
83
        #endregion
 
84
 
 
85
        #region None
 
86
 
 
87
        /// <summary>
 
88
        /// Returns a ConstraintExpression, which will apply
 
89
        /// the following constraint to all members of a collection,
 
90
        /// succeeding if all of them fail.
 
91
        /// </summary>
 
92
        public ConstraintExpression None
 
93
        {
 
94
            get { return this.Append(new NoneOperator()); }
 
95
        }
 
96
 
 
97
        #endregion
 
98
 
 
99
        #region Exactly(n)
 
100
 
 
101
        /// <summary>
 
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.
 
105
        /// </summary>
 
106
        public ConstraintExpression Exactly(int expectedCount)
 
107
        {
 
108
            return this.Append(new ExactCountOperator(expectedCount));
 
109
        }
 
110
 
 
111
        #endregion
 
112
 
 
113
        #region Property
 
114
 
 
115
        /// <summary>
 
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.
 
119
        /// </summary>
 
120
        public ResolvableConstraintExpression Property(string name)
 
121
        {
 
122
            return this.Append(new PropOperator(name));
 
123
        }
 
124
 
 
125
        #endregion
 
126
 
 
127
        #region Length
 
128
 
 
129
        /// <summary>
 
130
        /// Returns a new ConstraintExpression, which will apply the following
 
131
        /// constraint to the Length property of the object being tested.
 
132
        /// </summary>
 
133
        public ResolvableConstraintExpression Length
 
134
        {
 
135
            get { return Property("Length"); }
 
136
        }
 
137
 
 
138
        #endregion
 
139
 
 
140
        #region Count
 
141
 
 
142
        /// <summary>
 
143
        /// Returns a new ConstraintExpression, which will apply the following
 
144
        /// constraint to the Count property of the object being tested.
 
145
        /// </summary>
 
146
        public ResolvableConstraintExpression Count
 
147
        {
 
148
            get { return Property("Count"); }
 
149
        }
 
150
 
 
151
        #endregion
 
152
 
 
153
        #region Message
 
154
 
 
155
        /// <summary>
 
156
        /// Returns a new ConstraintExpression, which will apply the following
 
157
        /// constraint to the Message property of the object being tested.
 
158
        /// </summary>
 
159
        public ResolvableConstraintExpression Message
 
160
        {
 
161
            get { return Property("Message"); }
 
162
        }
 
163
 
 
164
        #endregion
 
165
 
 
166
        #region InnerException
 
167
 
 
168
        /// <summary>
 
169
        /// Returns a new ConstraintExpression, which will apply the following
 
170
        /// constraint to the InnerException property of the object being tested.
 
171
        /// </summary>
 
172
        public ResolvableConstraintExpression InnerException
 
173
        {
 
174
            get { return Property("InnerException"); }
 
175
        }
 
176
 
 
177
        #endregion
 
178
 
 
179
        #region Attribute
 
180
 
 
181
        /// <summary>
 
182
        /// Returns a new AttributeConstraint checking for the
 
183
        /// presence of a particular attribute on an object.
 
184
        /// </summary>
 
185
        public ResolvableConstraintExpression Attribute(Type expectedType)
 
186
        {
 
187
            return this.Append(new AttributeOperator(expectedType));
 
188
        }
 
189
 
 
190
#if CLR_2_0 || CLR_4_0
 
191
        /// <summary>
 
192
        /// Returns a new AttributeConstraint checking for the
 
193
        /// presence of a particular attribute on an object.
 
194
        /// </summary>
 
195
        public ResolvableConstraintExpression Attribute<T>()
 
196
        {
 
197
            return Attribute(typeof(T));
 
198
        }
 
199
#endif
 
200
 
 
201
        #endregion
 
202
 
 
203
        #region With
 
204
 
 
205
        /// <summary>
 
206
        /// With is currently a NOP - reserved for future use.
 
207
        /// </summary>
 
208
        public ConstraintExpression With
 
209
        {
 
210
            get { return this.Append(new WithOperator()); }
 
211
        }
 
212
 
 
213
        #endregion
 
214
 
 
215
        #region Matches
 
216
 
 
217
        /// <summary>
 
218
        /// Returns the constraint provided as an argument - used to allow custom
 
219
        /// custom constraints to easily participate in the syntax.
 
220
        /// </summary>
 
221
        public Constraint Matches(Constraint constraint)
 
222
        {
 
223
            return this.Append(constraint);
 
224
        }
 
225
 
 
226
#if CLR_2_0 || CLR_4_0
 
227
        /// <summary>
 
228
        /// Returns the constraint provided as an argument - used to allow custom
 
229
        /// custom constraints to easily participate in the syntax.
 
230
        /// </summary>
 
231
        public Constraint Matches<T>(Predicate<T> predicate)
 
232
        {
 
233
            return this.Append(new PredicateConstraint<T>(predicate));
 
234
        }
 
235
#endif
 
236
 
 
237
        #endregion
 
238
 
 
239
        #region Null
 
240
 
 
241
        /// <summary>
 
242
        /// Returns a constraint that tests for null
 
243
        /// </summary>
 
244
        public NullConstraint Null
 
245
        {
 
246
            get { return (NullConstraint)this.Append(new NullConstraint()); }
 
247
        }
 
248
 
 
249
        #endregion
 
250
 
 
251
        #region True
 
252
 
 
253
        /// <summary>
 
254
        /// Returns a constraint that tests for True
 
255
        /// </summary>
 
256
        public TrueConstraint True
 
257
        {
 
258
            get { return (TrueConstraint)this.Append(new TrueConstraint()); }
 
259
        }
 
260
 
 
261
        #endregion
 
262
 
 
263
        #region False
 
264
 
 
265
        /// <summary>
 
266
        /// Returns a constraint that tests for False
 
267
        /// </summary>
 
268
        public FalseConstraint False
 
269
        {
 
270
            get { return (FalseConstraint)this.Append(new FalseConstraint()); }
 
271
        }
 
272
 
 
273
        #endregion
 
274
 
 
275
        #region Positive
 
276
 
 
277
        /// <summary>
 
278
        /// Returns a constraint that tests for a positive value
 
279
        /// </summary>
 
280
        public GreaterThanConstraint Positive
 
281
        {
 
282
            get { return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(0)); }
 
283
        }
 
284
 
 
285
        #endregion
 
286
 
 
287
        #region Negative
 
288
 
 
289
        /// <summary>
 
290
        /// Returns a constraint that tests for a negative value
 
291
        /// </summary>
 
292
        public LessThanConstraint Negative
 
293
        {
 
294
            get { return (LessThanConstraint)this.Append(new LessThanConstraint(0)); }
 
295
        }
 
296
 
 
297
        #endregion
 
298
 
 
299
        #region NaN
 
300
 
 
301
        /// <summary>
 
302
        /// Returns a constraint that tests for NaN
 
303
        /// </summary>
 
304
        public NaNConstraint NaN
 
305
        {
 
306
            get { return (NaNConstraint)this.Append(new NaNConstraint()); }
 
307
        }
 
308
 
 
309
        #endregion
 
310
 
 
311
        #region Empty
 
312
 
 
313
        /// <summary>
 
314
        /// Returns a constraint that tests for empty
 
315
        /// </summary>
 
316
        public EmptyConstraint Empty
 
317
        {
 
318
            get { return (EmptyConstraint)this.Append(new EmptyConstraint()); }
 
319
        }
 
320
 
 
321
        #endregion
 
322
 
 
323
        #region Unique
 
324
 
 
325
        /// <summary>
 
326
        /// Returns a constraint that tests whether a collection 
 
327
        /// contains all unique items.
 
328
        /// </summary>
 
329
        public UniqueItemsConstraint Unique
 
330
        {
 
331
            get { return (UniqueItemsConstraint)this.Append(new UniqueItemsConstraint()); }
 
332
        }
 
333
 
 
334
        #endregion
 
335
 
 
336
        #region BinarySerializable
 
337
 
 
338
        /// <summary>
 
339
        /// Returns a constraint that tests whether an object graph is serializable in binary format.
 
340
        /// </summary>
 
341
        public BinarySerializableConstraint BinarySerializable
 
342
        {
 
343
            get { return (BinarySerializableConstraint)this.Append(new BinarySerializableConstraint()); }
 
344
        }
 
345
 
 
346
        #endregion
 
347
 
 
348
        #region XmlSerializable
 
349
 
 
350
        /// <summary>
 
351
        /// Returns a constraint that tests whether an object graph is serializable in xml format.
 
352
        /// </summary>
 
353
        public XmlSerializableConstraint XmlSerializable
 
354
        {
 
355
            get { return (XmlSerializableConstraint)this.Append(new XmlSerializableConstraint()); }
 
356
        }
 
357
 
 
358
        #endregion
 
359
 
 
360
        #region EqualTo
 
361
 
 
362
        /// <summary>
 
363
        /// Returns a constraint that tests two items for equality
 
364
        /// </summary>
 
365
        public EqualConstraint EqualTo(object expected)
 
366
        {
 
367
            return (EqualConstraint)this.Append(new EqualConstraint(expected));
 
368
        }
 
369
 
 
370
        #endregion
 
371
 
 
372
        #region SameAs
 
373
 
 
374
        /// <summary>
 
375
        /// Returns a constraint that tests that two references are the same object
 
376
        /// </summary>
 
377
        public SameAsConstraint SameAs(object expected)
 
378
        {
 
379
            return (SameAsConstraint)this.Append(new SameAsConstraint(expected));
 
380
        }
 
381
 
 
382
        #endregion
 
383
 
 
384
        #region GreaterThan
 
385
 
 
386
        /// <summary>
 
387
        /// Returns a constraint that tests whether the
 
388
        /// actual value is greater than the suppled argument
 
389
        /// </summary>
 
390
        public GreaterThanConstraint GreaterThan(object expected)
 
391
        {
 
392
            return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(expected));
 
393
        }
 
394
 
 
395
        #endregion
 
396
 
 
397
        #region GreaterThanOrEqualTo
 
398
 
 
399
        /// <summary>
 
400
        /// Returns a constraint that tests whether the
 
401
        /// actual value is greater than or equal to the suppled argument
 
402
        /// </summary>
 
403
        public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
 
404
        {
 
405
            return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
 
406
        }
 
407
 
 
408
        /// <summary>
 
409
        /// Returns a constraint that tests whether the
 
410
        /// actual value is greater than or equal to the suppled argument
 
411
        /// </summary>
 
412
        public GreaterThanOrEqualConstraint AtLeast(object expected)
 
413
        {
 
414
            return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
 
415
        }
 
416
 
 
417
        #endregion
 
418
 
 
419
        #region LessThan
 
420
 
 
421
        /// <summary>
 
422
        /// Returns a constraint that tests whether the
 
423
        /// actual value is less than the suppled argument
 
424
        /// </summary>
 
425
        public LessThanConstraint LessThan(object expected)
 
426
        {
 
427
            return (LessThanConstraint)this.Append(new LessThanConstraint(expected));
 
428
        }
 
429
 
 
430
        #endregion
 
431
 
 
432
        #region LessThanOrEqualTo
 
433
 
 
434
        /// <summary>
 
435
        /// Returns a constraint that tests whether the
 
436
        /// actual value is less than or equal to the suppled argument
 
437
        /// </summary>
 
438
        public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
 
439
        {
 
440
            return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
 
441
        }
 
442
 
 
443
        /// <summary>
 
444
        /// Returns a constraint that tests whether the
 
445
        /// actual value is less than or equal to the suppled argument
 
446
        /// </summary>
 
447
        public LessThanOrEqualConstraint AtMost(object expected)
 
448
        {
 
449
            return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
 
450
        }
 
451
 
 
452
        #endregion
 
453
 
 
454
        #region TypeOf
 
455
 
 
456
        /// <summary>
 
457
        /// Returns a constraint that tests whether the actual
 
458
        /// value is of the exact type supplied as an argument.
 
459
        /// </summary>
 
460
        public ExactTypeConstraint TypeOf(Type expectedType)
 
461
        {
 
462
            return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(expectedType));
 
463
        }
 
464
 
 
465
#if CLR_2_0 || CLR_4_0
 
466
        /// <summary>
 
467
        /// Returns a constraint that tests whether the actual
 
468
        /// value is of the exact type supplied as an argument.
 
469
        /// </summary>
 
470
        public ExactTypeConstraint TypeOf<T>()
 
471
        {
 
472
            return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(typeof(T)));
 
473
        }
 
474
#endif
 
475
 
 
476
        #endregion
 
477
 
 
478
        #region InstanceOf
 
479
 
 
480
        /// <summary>
 
481
        /// Returns a constraint that tests whether the actual value
 
482
        /// is of the type supplied as an argument or a derived type.
 
483
        /// </summary>
 
484
        public InstanceOfTypeConstraint InstanceOf(Type expectedType)
 
485
        {
 
486
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
 
487
        }
 
488
 
 
489
#if CLR_2_0 || CLR_4_0
 
490
        /// <summary>
 
491
        /// Returns a constraint that tests whether the actual value
 
492
        /// is of the type supplied as an argument or a derived type.
 
493
        /// </summary>
 
494
        public InstanceOfTypeConstraint InstanceOf<T>()
 
495
        {
 
496
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
 
497
        }
 
498
#endif
 
499
 
 
500
        /// <summary>
 
501
        /// Returns a constraint that tests whether the actual value
 
502
        /// is of the type supplied as an argument or a derived type.
 
503
        /// </summary>
 
504
        [Obsolete("Use InstanceOf(expectedType)")]
 
505
        public InstanceOfTypeConstraint InstanceOfType(Type expectedType)
 
506
        {
 
507
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
 
508
        }
 
509
 
 
510
#if CLR_2_0 || CLR_4_0
 
511
        /// <summary>
 
512
        /// Returns a constraint that tests whether the actual value
 
513
        /// is of the type supplied as an argument or a derived type.
 
514
        /// </summary>
 
515
        [Obsolete("Use InstanceOf<T>()")]
 
516
        public InstanceOfTypeConstraint InstanceOfType<T>()
 
517
        {
 
518
            return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(T)));
 
519
        }
 
520
#endif
 
521
 
 
522
        #endregion
 
523
 
 
524
        #region AssignableFrom
 
525
 
 
526
        /// <summary>
 
527
        /// Returns a constraint that tests whether the actual value
 
528
        /// is assignable from the type supplied as an argument.
 
529
        /// </summary>
 
530
        public AssignableFromConstraint AssignableFrom(Type expectedType)
 
531
        {
 
532
            return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(expectedType));
 
533
        }
 
534
 
 
535
#if CLR_2_0 || CLR_4_0
 
536
        /// <summary>
 
537
        /// Returns a constraint that tests whether the actual value
 
538
        /// is assignable from the type supplied as an argument.
 
539
        /// </summary>
 
540
        public AssignableFromConstraint AssignableFrom<T>()
 
541
        {
 
542
            return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(typeof(T)));
 
543
        }
 
544
#endif
 
545
 
 
546
        #endregion
 
547
 
 
548
        #region AssignableTo
 
549
 
 
550
        /// <summary>
 
551
        /// Returns a constraint that tests whether the actual value
 
552
        /// is assignable from the type supplied as an argument.
 
553
        /// </summary>
 
554
        public AssignableToConstraint AssignableTo(Type expectedType)
 
555
        {
 
556
            return (AssignableToConstraint)this.Append(new AssignableToConstraint(expectedType));
 
557
        }
 
558
 
 
559
#if CLR_2_0 || CLR_4_0
 
560
        /// <summary>
 
561
        /// Returns a constraint that tests whether the actual value
 
562
        /// is assignable from the type supplied as an argument.
 
563
        /// </summary>
 
564
        public AssignableToConstraint AssignableTo<T>()
 
565
        {
 
566
            return (AssignableToConstraint)this.Append(new AssignableToConstraint(typeof(T)));
 
567
        }
 
568
#endif
 
569
 
 
570
        #endregion
 
571
 
 
572
        #region EquivalentTo
 
573
 
 
574
        /// <summary>
 
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.
 
578
        /// </summary>
 
579
        public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
 
580
        {
 
581
            return (CollectionEquivalentConstraint)this.Append(new CollectionEquivalentConstraint(expected));
 
582
        }
 
583
 
 
584
        #endregion
 
585
 
 
586
        #region SubsetOf
 
587
 
 
588
        /// <summary>
 
589
        /// Returns a constraint that tests whether the actual value
 
590
        /// is a subset of the collection supplied as an argument.
 
591
        /// </summary>
 
592
        public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
 
593
        {
 
594
            return (CollectionSubsetConstraint)this.Append(new CollectionSubsetConstraint(expected));
 
595
        }
 
596
 
 
597
        #endregion
 
598
 
 
599
        #region Ordered
 
600
 
 
601
        /// <summary>
 
602
        /// Returns a constraint that tests whether a collection is ordered
 
603
        /// </summary>
 
604
        public CollectionOrderedConstraint Ordered
 
605
        {
 
606
            get { return (CollectionOrderedConstraint)this.Append(new CollectionOrderedConstraint()); }
 
607
        }
 
608
 
 
609
        #endregion
 
610
 
 
611
        #region Member
 
612
 
 
613
        /// <summary>
 
614
        /// Returns a new CollectionContainsConstraint checking for the
 
615
        /// presence of a particular object in the collection.
 
616
        /// </summary>
 
617
        public CollectionContainsConstraint Member(object expected)
 
618
        {
 
619
            return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
 
620
        }
 
621
 
 
622
        /// <summary>
 
623
        /// Returns a new CollectionContainsConstraint checking for the
 
624
        /// presence of a particular object in the collection.
 
625
        /// </summary>
 
626
        public CollectionContainsConstraint Contains(object expected)
 
627
        {
 
628
            return (CollectionContainsConstraint)this.Append(new CollectionContainsConstraint(expected));
 
629
        }
 
630
 
 
631
        #endregion
 
632
 
 
633
        #region Contains
 
634
 
 
635
        /// <summary>
 
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.
 
642
        /// </summary>
 
643
        public ContainsConstraint Contains(string expected)
 
644
        {
 
645
            return (ContainsConstraint)this.Append(new ContainsConstraint(expected));
 
646
        }
 
647
 
 
648
        #endregion
 
649
 
 
650
        #region StringContaining
 
651
 
 
652
        /// <summary>
 
653
        /// Returns a constraint that succeeds if the actual
 
654
        /// value contains the substring supplied as an argument.
 
655
        /// </summary>
 
656
        public SubstringConstraint StringContaining(string expected)
 
657
        {
 
658
            return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
 
659
        }
 
660
 
 
661
        /// <summary>
 
662
        /// Returns a constraint that succeeds if the actual
 
663
        /// value contains the substring supplied as an argument.
 
664
        /// </summary>
 
665
        public SubstringConstraint ContainsSubstring(string expected)
 
666
        {
 
667
            return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
 
668
        }
 
669
 
 
670
        #endregion
 
671
 
 
672
        #region StartsWith
 
673
 
 
674
        /// <summary>
 
675
        /// Returns a constraint that succeeds if the actual
 
676
        /// value starts with the substring supplied as an argument.
 
677
        /// </summary>
 
678
        public StartsWithConstraint StartsWith(string expected)
 
679
        {
 
680
            return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
 
681
        }
 
682
 
 
683
        /// <summary>
 
684
        /// Returns a constraint that succeeds if the actual
 
685
        /// value starts with the substring supplied as an argument.
 
686
        /// </summary>
 
687
        public StartsWithConstraint StringStarting(string expected)
 
688
        {
 
689
            return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
 
690
        }
 
691
 
 
692
        #endregion
 
693
 
 
694
        #region EndsWith
 
695
 
 
696
        /// <summary>
 
697
        /// Returns a constraint that succeeds if the actual
 
698
        /// value ends with the substring supplied as an argument.
 
699
        /// </summary>
 
700
        public EndsWithConstraint EndsWith(string expected)
 
701
        {
 
702
            return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
 
703
        }
 
704
 
 
705
        /// <summary>
 
706
        /// Returns a constraint that succeeds if the actual
 
707
        /// value ends with the substring supplied as an argument.
 
708
        /// </summary>
 
709
        public EndsWithConstraint StringEnding(string expected)
 
710
        {
 
711
            return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
 
712
        }
 
713
 
 
714
        #endregion
 
715
 
 
716
        #region Matches
 
717
 
 
718
        /// <summary>
 
719
        /// Returns a constraint that succeeds if the actual
 
720
        /// value matches the regular expression supplied as an argument.
 
721
        /// </summary>
 
722
        public RegexConstraint Matches(string pattern)
 
723
        {
 
724
            return (RegexConstraint)this.Append(new RegexConstraint(pattern));
 
725
        }
 
726
 
 
727
        /// <summary>
 
728
        /// Returns a constraint that succeeds if the actual
 
729
        /// value matches the regular expression supplied as an argument.
 
730
        /// </summary>
 
731
        public RegexConstraint StringMatching(string pattern)
 
732
        {
 
733
            return (RegexConstraint)this.Append(new RegexConstraint(pattern));
 
734
        }
 
735
 
 
736
        #endregion
 
737
 
 
738
        #region SamePath
 
739
 
 
740
        /// <summary>
 
741
        /// Returns a constraint that tests whether the path provided 
 
742
        /// is the same as an expected path after canonicalization.
 
743
        /// </summary>
 
744
        public SamePathConstraint SamePath(string expected)
 
745
        {
 
746
            return (SamePathConstraint)this.Append(new SamePathConstraint(expected));
 
747
        }
 
748
 
 
749
        #endregion
 
750
 
 
751
        #region SubPath
 
752
 
 
753
        /// <summary>
 
754
        /// Returns a constraint that tests whether the path provided 
 
755
        /// is the same path or under an expected path after canonicalization.
 
756
        /// </summary>
 
757
        public SubPathConstraint SubPath(string expected)
 
758
        {
 
759
            return (SubPathConstraint)this.Append(new SubPathConstraint(expected));
 
760
        }
 
761
 
 
762
        #endregion
 
763
 
 
764
        #region SamePathOrUnder
 
765
 
 
766
        /// <summary>
 
767
        /// Returns a constraint that tests whether the path provided 
 
768
        /// is the same path or under an expected path after canonicalization.
 
769
        /// </summary>
 
770
        public SamePathOrUnderConstraint SamePathOrUnder(string expected)
 
771
        {
 
772
            return (SamePathOrUnderConstraint)this.Append(new SamePathOrUnderConstraint(expected));
 
773
        }
 
774
 
 
775
        #endregion
 
776
 
 
777
        #region InRange
 
778
 
 
779
#if CLR_2_0 || CLR_4_0
 
780
        /// <summary>
 
781
        /// Returns a constraint that tests whether the actual value falls 
 
782
        /// within a specified range.
 
783
        /// </summary>
 
784
        public RangeConstraint<T> InRange<T>(T from, T to) where T : IComparable<T>
 
785
        {
 
786
            return (RangeConstraint<T>)this.Append(new RangeConstraint<T>(from, to));
 
787
        }
 
788
#else
 
789
        /// <summary>
 
790
        /// Returns a constraint that tests whether the actual value falls 
 
791
        /// within a specified range.
 
792
        /// </summary>
 
793
        public RangeConstraint InRange(IComparable from, IComparable to)
 
794
        {
 
795
            return (RangeConstraint)this.Append(new RangeConstraint(from, to));
 
796
        }
 
797
#endif
 
798
 
 
799
        #endregion
 
800
 
 
801
    }
 
802
}