-
Notifications
You must be signed in to change notification settings - Fork 723
/
ConstraintExpression.cs
990 lines (802 loc) · 31.5 KB
/
ConstraintExpression.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
// ***********************************************************************
// Copyright (c) 2009 Charlie Poole, Rob Prouse
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ***********************************************************************
using System;
using System.Collections;
namespace NUnit.Framework.Constraints
{
/// <summary>
/// ConstraintExpression represents a compound constraint in the
/// process of being constructed from a series of syntactic elements.
///
/// Individual elements are appended to the expression as they are
/// reorganized. When a constraint is appended, it is returned as the
/// value of the operation so that modifiers may be applied. However,
/// any partially built expression is attached to the constraint for
/// later resolution. When an operator is appended, the partial
/// expression is returned. If it's a self-resolving operator, then
/// a ResolvableConstraintExpression is returned.
/// </summary>
public class ConstraintExpression
{
#region Instance Fields
/// <summary>
/// The ConstraintBuilder holding the elements recognized so far
/// </summary>
protected ConstraintBuilder builder;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ConstraintExpression"/> class.
/// </summary>
public ConstraintExpression()
{
this.builder = new ConstraintBuilder();
}
/// <summary>
/// Initializes a new instance of the <see cref="ConstraintExpression"/>
/// class passing in a ConstraintBuilder, which may be prepopulated.
/// </summary>
/// <param name="builder">The builder.</param>
public ConstraintExpression(ConstraintBuilder builder)
{
this.builder = builder;
}
#endregion
#region ToString()
/// <summary>
/// Returns a string representation of the expression as it
/// currently stands. This should only be used for testing,
/// since it has the side-effect of resolving the expression.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return builder.Resolve().ToString();
}
#endregion
#region Append Methods
/// <summary>
/// Appends an operator to the expression and returns the
/// resulting expression itself.
/// </summary>
public ConstraintExpression Append(ConstraintOperator op)
{
builder.Append(op);
return this;
}
/// <summary>
/// Appends a self-resolving operator to the expression and
/// returns a new ResolvableConstraintExpression.
/// </summary>
public ResolvableConstraintExpression Append(SelfResolvingOperator op)
{
builder.Append(op);
return new ResolvableConstraintExpression(builder);
}
/// <summary>
/// Appends a constraint to the expression and returns that
/// constraint, which is associated with the current state
/// of the expression being built. Note that the constraint
/// is not reduced at this time. For example, if there
/// is a NotOperator on the stack we don't reduce and
/// return a NotConstraint. The original constraint must
/// be returned because it may support modifiers that
/// are yet to be applied.
/// </summary>
public Constraint Append(Constraint constraint)
{
builder.Append(constraint);
return constraint;
}
#endregion
#region Not
/// <summary>
/// Returns a ConstraintExpression that negates any
/// following constraint.
/// </summary>
public ConstraintExpression Not
{
get { return this.Append(new NotOperator()); }
}
/// <summary>
/// Returns a ConstraintExpression that negates any
/// following constraint.
/// </summary>
public ConstraintExpression No
{
get { return this.Append(new NotOperator()); }
}
#endregion
#region All
/// <summary>
/// Returns a ConstraintExpression, which will apply
/// the following constraint to all members of a collection,
/// succeeding if all of them succeed.
/// </summary>
public ConstraintExpression All
{
get { return this.Append(new AllOperator()); }
}
#endregion
#region Some
/// <summary>
/// Returns a ConstraintExpression, which will apply
/// the following constraint to all members of a collection,
/// succeeding if at least one of them succeeds.
/// </summary>
public ConstraintExpression Some
{
get { return this.Append(new SomeOperator()); }
}
#endregion
#region None
/// <summary>
/// Returns a ConstraintExpression, which will apply
/// the following constraint to all members of a collection,
/// succeeding if all of them fail.
/// </summary>
public ConstraintExpression None
{
get { return this.Append(new NoneOperator()); }
}
#endregion
#region Exactly(n)
/// <summary>
/// Returns a ConstraintExpression, which will apply
/// the following constraint to all members of a collection,
/// succeeding only if a specified number of them succeed.
/// </summary>
public ItemsConstraintExpression Exactly(int expectedCount)
{
builder.Append(new ExactCountOperator(expectedCount));
return new ItemsConstraintExpression(builder);
}
#endregion
#region One
/// <summary>
/// Returns a <see cref="ItemsConstraintExpression"/>, which will
/// apply the following constraint to a collection of length one, succeeding
/// only if exactly one of them succeeds.
/// </summary>
public ItemsConstraintExpression One
{
get
{
builder.Append(new ExactCountOperator(1));
return new ItemsConstraintExpression(builder);
}
}
#endregion
#region Property
/// <summary>
/// Returns a new PropertyConstraintExpression, which will either
/// test for the existence of the named property on the object
/// being tested or apply any following constraint to that property.
/// </summary>
public ResolvableConstraintExpression Property(string name)
{
return this.Append(new PropOperator(name));
}
#endregion
#region Length
/// <summary>
/// Returns a new ConstraintExpression, which will apply the following
/// constraint to the Length property of the object being tested.
/// </summary>
public ResolvableConstraintExpression Length
{
get { return Property("Length"); }
}
#endregion
#region Count
/// <summary>
/// Returns a new ConstraintExpression, which will apply the following
/// constraint to the Count property of the object being tested.
/// </summary>
public ResolvableConstraintExpression Count
{
get { return Property("Count"); }
}
#endregion
#region Message
/// <summary>
/// Returns a new ConstraintExpression, which will apply the following
/// constraint to the Message property of the object being tested.
/// </summary>
public ResolvableConstraintExpression Message
{
get { return Property("Message"); }
}
#endregion
#region InnerException
/// <summary>
/// Returns a new ConstraintExpression, which will apply the following
/// constraint to the InnerException property of the object being tested.
/// </summary>
public ResolvableConstraintExpression InnerException
{
get { return Property("InnerException"); }
}
#endregion
#region Attribute
/// <summary>
/// Returns a new AttributeConstraint checking for the
/// presence of a particular attribute on an object.
/// </summary>
public ResolvableConstraintExpression Attribute(Type expectedType)
{
return this.Append(new AttributeOperator(expectedType));
}
/// <summary>
/// Returns a new AttributeConstraint checking for the
/// presence of a particular attribute on an object.
/// </summary>
public ResolvableConstraintExpression Attribute<TExpected>()
{
return Attribute(typeof(TExpected));
}
#endregion
#region With
/// <summary>
/// With is currently a NOP - reserved for future use.
/// </summary>
public ConstraintExpression With
{
get { return this.Append(new WithOperator()); }
}
#endregion
#region Matches
/// <summary>
/// Returns the constraint provided as an argument - used to allow custom
/// custom constraints to easily participate in the syntax.
/// </summary>
public Constraint Matches(IResolveConstraint constraint)
{
return this.Append((Constraint)constraint.Resolve());
}
/// <summary>
/// Returns the constraint provided as an argument - used to allow custom
/// custom constraints to easily participate in the syntax.
/// </summary>
public Constraint Matches<TActual>(Predicate<TActual> predicate)
{
return this.Append(new PredicateConstraint<TActual>(predicate));
}
#endregion
#region Null
/// <summary>
/// Returns a constraint that tests for null
/// </summary>
public NullConstraint Null
{
get { return (NullConstraint)this.Append(new NullConstraint()); }
}
#endregion
#region True
/// <summary>
/// Returns a constraint that tests for True
/// </summary>
public TrueConstraint True
{
get { return (TrueConstraint)this.Append(new TrueConstraint()); }
}
#endregion
#region False
/// <summary>
/// Returns a constraint that tests for False
/// </summary>
public FalseConstraint False
{
get { return (FalseConstraint)this.Append(new FalseConstraint()); }
}
#endregion
#region Positive
/// <summary>
/// Returns a constraint that tests for a positive value
/// </summary>
public GreaterThanConstraint Positive
{
get { return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(0)); }
}
#endregion
#region Negative
/// <summary>
/// Returns a constraint that tests for a negative value
/// </summary>
public LessThanConstraint Negative
{
get { return (LessThanConstraint)this.Append(new LessThanConstraint(0)); }
}
#endregion
#region Zero
/// <summary>
/// Returns a constraint that tests if item is equal to zero
/// </summary>
public EqualConstraint Zero
{
get { return (EqualConstraint)this.Append(new EqualConstraint(0)); }
}
#endregion
#region NaN
/// <summary>
/// Returns a constraint that tests for NaN
/// </summary>
public NaNConstraint NaN
{
get { return (NaNConstraint)this.Append(new NaNConstraint()); }
}
#endregion
#region Empty
/// <summary>
/// Returns a constraint that tests for empty
/// </summary>
public EmptyConstraint Empty
{
get { return (EmptyConstraint)this.Append(new EmptyConstraint()); }
}
#endregion
#region Unique
/// <summary>
/// Returns a constraint that tests whether a collection
/// contains all unique items.
/// </summary>
public UniqueItemsConstraint Unique
{
get { return (UniqueItemsConstraint)this.Append(new UniqueItemsConstraint()); }
}
#endregion
#region BinarySerializable
#if !NETSTANDARD1_6
/// <summary>
/// Returns a constraint that tests whether an object graph is serializable in binary format.
/// </summary>
public BinarySerializableConstraint BinarySerializable
{
get { return (BinarySerializableConstraint)this.Append(new BinarySerializableConstraint()); }
}
#endif
#endregion
#region XmlSerializable
#if !NETSTANDARD1_6
/// <summary>
/// Returns a constraint that tests whether an object graph is serializable in XML format.
/// </summary>
public XmlSerializableConstraint XmlSerializable
{
get { return (XmlSerializableConstraint)this.Append(new XmlSerializableConstraint()); }
}
#endif
#endregion
#region EqualTo
/// <summary>
/// Returns a constraint that tests two items for equality
/// </summary>
public EqualConstraint EqualTo(object expected)
{
return (EqualConstraint)this.Append(new EqualConstraint(expected));
}
#endregion
#region SameAs
/// <summary>
/// Returns a constraint that tests that two references are the same object
/// </summary>
public SameAsConstraint SameAs(object expected)
{
return (SameAsConstraint)this.Append(new SameAsConstraint(expected));
}
#endregion
#region GreaterThan
/// <summary>
/// Returns a constraint that tests whether the
/// actual value is greater than the supplied argument
/// </summary>
public GreaterThanConstraint GreaterThan(object expected)
{
return (GreaterThanConstraint)this.Append(new GreaterThanConstraint(expected));
}
#endregion
#region GreaterThanOrEqualTo
/// <summary>
/// Returns a constraint that tests whether the
/// actual value is greater than or equal to the supplied argument
/// </summary>
public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
{
return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
}
/// <summary>
/// Returns a constraint that tests whether the
/// actual value is greater than or equal to the supplied argument
/// </summary>
public GreaterThanOrEqualConstraint AtLeast(object expected)
{
return (GreaterThanOrEqualConstraint)this.Append(new GreaterThanOrEqualConstraint(expected));
}
#endregion
#region LessThan
/// <summary>
/// Returns a constraint that tests whether the
/// actual value is less than the supplied argument
/// </summary>
public LessThanConstraint LessThan(object expected)
{
return (LessThanConstraint)this.Append(new LessThanConstraint(expected));
}
#endregion
#region LessThanOrEqualTo
/// <summary>
/// Returns a constraint that tests whether the
/// actual value is less than or equal to the supplied argument
/// </summary>
public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
{
return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
}
/// <summary>
/// Returns a constraint that tests whether the
/// actual value is less than or equal to the supplied argument
/// </summary>
public LessThanOrEqualConstraint AtMost(object expected)
{
return (LessThanOrEqualConstraint)this.Append(new LessThanOrEqualConstraint(expected));
}
#endregion
#region TypeOf
/// <summary>
/// Returns a constraint that tests whether the actual
/// value is of the exact type supplied as an argument.
/// </summary>
public ExactTypeConstraint TypeOf(Type expectedType)
{
return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(expectedType));
}
/// <summary>
/// Returns a constraint that tests whether the actual
/// value is of the exact type supplied as an argument.
/// </summary>
public ExactTypeConstraint TypeOf<TExpected>()
{
return (ExactTypeConstraint)this.Append(new ExactTypeConstraint(typeof(TExpected)));
}
#endregion
#region InstanceOf
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is of the type supplied as an argument or a derived type.
/// </summary>
public InstanceOfTypeConstraint InstanceOf(Type expectedType)
{
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(expectedType));
}
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is of the type supplied as an argument or a derived type.
/// </summary>
public InstanceOfTypeConstraint InstanceOf<TExpected>()
{
return (InstanceOfTypeConstraint)this.Append(new InstanceOfTypeConstraint(typeof(TExpected)));
}
#endregion
#region AssignableFrom
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is assignable from the type supplied as an argument.
/// </summary>
public AssignableFromConstraint AssignableFrom(Type expectedType)
{
return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(expectedType));
}
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is assignable from the type supplied as an argument.
/// </summary>
public AssignableFromConstraint AssignableFrom<TExpected>()
{
return (AssignableFromConstraint)this.Append(new AssignableFromConstraint(typeof(TExpected)));
}
#endregion
#region AssignableTo
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is assignable from the type supplied as an argument.
/// </summary>
public AssignableToConstraint AssignableTo(Type expectedType)
{
return (AssignableToConstraint)this.Append(new AssignableToConstraint(expectedType));
}
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is assignable from the type supplied as an argument.
/// </summary>
public AssignableToConstraint AssignableTo<TExpected>()
{
return (AssignableToConstraint)this.Append(new AssignableToConstraint(typeof(TExpected)));
}
#endregion
#region EquivalentTo
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is a collection containing the same elements as the
/// collection supplied as an argument.
/// </summary>
public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
{
return (CollectionEquivalentConstraint)this.Append(new CollectionEquivalentConstraint(expected));
}
#endregion
#region SubsetOf
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is a subset of the collection supplied as an argument.
/// </summary>
public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
{
return (CollectionSubsetConstraint)this.Append(new CollectionSubsetConstraint(expected));
}
#endregion
#region SupersetOf
/// <summary>
/// Returns a constraint that tests whether the actual value
/// is a superset of the collection supplied as an argument.
/// </summary>
public CollectionSupersetConstraint SupersetOf(IEnumerable expected)
{
return (CollectionSupersetConstraint)this.Append(new CollectionSupersetConstraint(expected));
}
#endregion
#region Ordered
/// <summary>
/// Returns a constraint that tests whether a collection is ordered
/// </summary>
public CollectionOrderedConstraint Ordered
{
get { return (CollectionOrderedConstraint)this.Append(new CollectionOrderedConstraint()); }
}
#endregion
#region Member
/// <summary>
/// Returns a new <see cref="SomeItemsConstraint"/> checking for the
/// presence of a particular object in the collection.
/// </summary>
public SomeItemsConstraint Member(object expected)
{
return (SomeItemsConstraint)this.Append(new SomeItemsConstraint(new EqualConstraint(expected)));
}
#endregion
#region Contains
/// <summary>
/// Returns a new <see cref="SomeItemsConstraint"/> checking for the
/// presence of a particular object in the collection.
/// </summary>
public SomeItemsConstraint Contains(object expected)
{
return (SomeItemsConstraint)this.Append(new SomeItemsConstraint(new EqualConstraint(expected)));
}
/// <summary>
/// Returns a new ContainsConstraint. This constraint
/// will, in turn, make use of the appropriate second-level
/// constraint, depending on the type of the actual argument.
/// This overload is only used if the item sought is a string,
/// since any other type implies that we are looking for a
/// collection member.
/// </summary>
public ContainsConstraint Contains(string expected)
{
return (ContainsConstraint)this.Append(new ContainsConstraint(expected));
}
/// <summary>
/// Returns a new <see cref="SomeItemsConstraint"/> checking for the
/// presence of a particular object in the collection.
/// </summary>
public SomeItemsConstraint Contain(object expected)
{
return Contains(expected);
}
/// <summary>
/// Returns a new ContainsConstraint. This constraint
/// will, in turn, make use of the appropriate second-level
/// constraint, depending on the type of the actual argument.
/// This overload is only used if the item sought is a string,
/// since any other type implies that we are looking for a
/// collection member.
/// </summary>
public ContainsConstraint Contain(string expected)
{
return Contains(expected);
}
#endregion
#region DictionaryContains
/// <summary>
/// Returns a new DictionaryContainsKeyConstraint checking for the
/// presence of a particular key in the Dictionary key collection.
/// </summary>
/// <param name="expected">The key to be matched in the Dictionary key collection</param>
public DictionaryContainsKeyConstraint ContainKey(object expected)
{
return (DictionaryContainsKeyConstraint)this.Append(new DictionaryContainsKeyConstraint(expected));
}
/// <summary>
/// Returns a new DictionaryContainsValueConstraint checking for the
/// presence of a particular value in the Dictionary value collection.
/// </summary>
/// <param name="expected">The value to be matched in the Dictionary value collection</param>
public DictionaryContainsValueConstraint ContainValue(object expected)
{
return (DictionaryContainsValueConstraint)this.Append(new DictionaryContainsValueConstraint(expected));
}
#endregion
#region StringContaining
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value contains the substring supplied as an argument.
/// </summary>
[Obsolete("Deprecated, use Contains")]
public SubstringConstraint StringContaining(string expected)
{
return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
}
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value contains the substring supplied as an argument.
/// </summary>
[Obsolete("Deprecated, use Contains")]
public SubstringConstraint ContainsSubstring(string expected)
{
return (SubstringConstraint)this.Append(new SubstringConstraint(expected));
}
#endregion
#region StartsWith
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value starts with the substring supplied as an argument.
/// </summary>
public StartsWithConstraint StartWith(string expected)
{
return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
}
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value starts with the substring supplied as an argument.
/// </summary>
public StartsWithConstraint StartsWith(string expected)
{
return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
}
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value starts with the substring supplied as an argument.
/// </summary>
[Obsolete("Deprecated, use Does.StartWith or StartsWith")]
public StartsWithConstraint StringStarting(string expected)
{
return (StartsWithConstraint)this.Append(new StartsWithConstraint(expected));
}
#endregion
#region EndsWith
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value ends with the substring supplied as an argument.
/// </summary>
public EndsWithConstraint EndWith(string expected)
{
return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
}
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value ends with the substring supplied as an argument.
/// </summary>
public EndsWithConstraint EndsWith(string expected)
{
return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
}
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value ends with the substring supplied as an argument.
/// </summary>
[Obsolete("Deprecated, use Does.EndWith or EndsWith")]
public EndsWithConstraint StringEnding(string expected)
{
return (EndsWithConstraint)this.Append(new EndsWithConstraint(expected));
}
#endregion
#region Matches
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value matches the regular expression supplied as an argument.
/// </summary>
public RegexConstraint Match(string pattern)
{
return (RegexConstraint)this.Append(new RegexConstraint(pattern));
}
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value matches the regular expression supplied as an argument.
/// </summary>
public RegexConstraint Matches(string pattern)
{
return (RegexConstraint)this.Append(new RegexConstraint(pattern));
}
/// <summary>
/// Returns a constraint that succeeds if the actual
/// value matches the regular expression supplied as an argument.
/// </summary>
[Obsolete("Deprecated, use Does.Match or Matches")]
public RegexConstraint StringMatching(string pattern)
{
return (RegexConstraint)this.Append(new RegexConstraint(pattern));
}
#endregion
#region SamePath
/// <summary>
/// Returns a constraint that tests whether the path provided
/// is the same as an expected path after canonicalization.
/// </summary>
public SamePathConstraint SamePath(string expected)
{
return (SamePathConstraint)this.Append(new SamePathConstraint(expected));
}
#endregion
#region SubPath
/// <summary>
/// Returns a constraint that tests whether the path provided
/// is the a subpath of the expected path after canonicalization.
/// </summary>
public SubPathConstraint SubPathOf(string expected)
{
return (SubPathConstraint)this.Append(new SubPathConstraint(expected));
}
#endregion
#region SamePathOrUnder
/// <summary>
/// Returns a constraint that tests whether the path provided
/// is the same path or under an expected path after canonicalization.
/// </summary>
public SamePathOrUnderConstraint SamePathOrUnder(string expected)
{
return (SamePathOrUnderConstraint)this.Append(new SamePathOrUnderConstraint(expected));
}
#endregion
#region InRange
/// <summary>
/// Returns a constraint that tests whether the actual value falls
/// inclusively within a specified range.
/// </summary>
/// <param name="from">Inclusive beginning of the range.</param>
/// <param name="to">Inclusive end of the range.</param>
public RangeConstraint InRange(object from, object to)
{
return (RangeConstraint)this.Append(new RangeConstraint(from, to));
}
#endregion
#region Exist
/// <summary>
/// Returns a constraint that succeeds if the value
/// is a file or directory and it exists.
/// </summary>
public Constraint Exist
{
get { return Append(new FileOrDirectoryExistsConstraint()); }
}
#endregion
}
}