[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Constraints / ConstraintFactory.cs
1 // ***********************************************************************
2 // Copyright (c) 2009 Charlie Poole
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using System.Collections;
31
32 namespace NUnit.Framework.Constraints
33 {
34     /// <summary>
35     /// Helper class with properties and methods that supply
36     /// a number of constraints used in Asserts.
37     /// </summary>
38     public class ConstraintFactory
39     {
40         #region Not
41
42         /// <summary>
43         /// Returns a ConstraintExpression that negates any
44         /// following constraint.
45         /// </summary>
46         public ConstraintExpression Not
47         {
48             get { return Is.Not; }
49         }
50
51         /// <summary>
52         /// Returns a ConstraintExpression that negates any
53         /// following constraint.
54         /// </summary>
55         public ConstraintExpression No
56         {
57             get { return Has.No; }
58         }
59
60         #endregion
61
62         #region All
63
64         /// <summary>
65         /// Returns a ConstraintExpression, which will apply
66         /// the following constraint to all members of a collection,
67         /// succeeding if all of them succeed.
68         /// </summary>
69         public ConstraintExpression All
70         {
71             get { return Is.All; }
72         }
73
74         #endregion
75
76         #region Some
77
78         /// <summary>
79         /// Returns a ConstraintExpression, which will apply
80         /// the following constraint to all members of a collection,
81         /// succeeding if at least one of them succeeds.
82         /// </summary>
83         public ConstraintExpression Some
84         {
85             get { return Has.Some; }
86         }
87
88         #endregion
89
90         #region None
91
92         /// <summary>
93         /// Returns a ConstraintExpression, which will apply
94         /// the following constraint to all members of a collection,
95         /// succeeding if all of them fail.
96         /// </summary>
97         public ConstraintExpression None
98         {
99             get { return Has.None; }
100         }
101
102         #endregion
103
104         #region Exactly(n)
105  
106         /// <summary>
107         /// Returns a ConstraintExpression, which will apply
108         /// the following constraint to all members of a collection,
109         /// succeeding only if a specified number of them succeed.
110         /// </summary>
111         public static ConstraintExpression Exactly(int expectedCount)
112         {
113             return Has.Exactly(expectedCount);
114         }
115  
116         #endregion
117  
118         #region Property
119
120         /// <summary>
121         /// Returns a new PropertyConstraintExpression, which will either
122         /// test for the existence of the named property on the object
123         /// being tested or apply any following constraint to that property.
124         /// </summary>
125         public ResolvableConstraintExpression Property(string name)
126         {
127             return Has.Property(name);
128         }
129
130         #endregion
131
132         #region Length
133
134         /// <summary>
135         /// Returns a new ConstraintExpression, which will apply the following
136         /// constraint to the Length property of the object being tested.
137         /// </summary>
138         public ResolvableConstraintExpression Length
139         {
140             get { return Has.Length; }
141         }
142
143         #endregion
144
145         #region Count
146
147         /// <summary>
148         /// Returns a new ConstraintExpression, which will apply the following
149         /// constraint to the Count property of the object being tested.
150         /// </summary>
151         public ResolvableConstraintExpression Count
152         {
153             get { return Has.Count; }
154         }
155
156         #endregion
157
158         #region Message
159
160         /// <summary>
161         /// Returns a new ConstraintExpression, which will apply the following
162         /// constraint to the Message property of the object being tested.
163         /// </summary>
164         public ResolvableConstraintExpression Message
165         {
166             get { return Has.Message; }
167         }
168
169         #endregion
170
171         #region InnerException
172
173         /// <summary>
174         /// Returns a new ConstraintExpression, which will apply the following
175         /// constraint to the InnerException property of the object being tested.
176         /// </summary>
177         public ResolvableConstraintExpression InnerException
178         {
179             get { return Has.InnerException; }
180         }
181
182         #endregion
183
184         #region Attribute
185
186         /// <summary>
187         /// Returns a new AttributeConstraint checking for the
188         /// presence of a particular attribute on an object.
189         /// </summary>
190         public ResolvableConstraintExpression Attribute(Type expectedType)
191         {
192             return Has.Attribute(expectedType);
193         }
194
195         /// <summary>
196         /// Returns a new AttributeConstraint checking for the
197         /// presence of a particular attribute on an object.
198         /// </summary>
199         public ResolvableConstraintExpression Attribute<TExpected>()
200         {
201             return Attribute(typeof(TExpected));
202         }
203
204         #endregion
205
206         #region Null
207
208         /// <summary>
209         /// Returns a constraint that tests for null
210         /// </summary>
211         public NullConstraint Null
212         {
213             get { return new NullConstraint(); }
214         }
215
216         #endregion
217
218         #region True
219
220         /// <summary>
221         /// Returns a constraint that tests for True
222         /// </summary>
223         public TrueConstraint True
224         {
225             get { return new TrueConstraint(); }
226         }
227
228         #endregion
229
230         #region False
231
232         /// <summary>
233         /// Returns a constraint that tests for False
234         /// </summary>
235         public FalseConstraint False
236         {
237             get { return new FalseConstraint(); }
238         }
239
240         #endregion
241
242         #region Positive
243  
244         /// <summary>
245         /// Returns a constraint that tests for a positive value
246         /// </summary>
247         public GreaterThanConstraint Positive
248         {
249             get { return new GreaterThanConstraint(0); }
250         }
251  
252         #endregion
253  
254         #region Negative
255  
256         /// <summary>
257         /// Returns a constraint that tests for a negative value
258         /// </summary>
259         public LessThanConstraint Negative
260         {
261             get { return new LessThanConstraint(0); }
262         }
263
264         #endregion
265
266         #region Zero
267
268         /// <summary>
269         /// Returns a constraint that tests for equality with zero
270         /// </summary>
271         public EqualConstraint Zero
272         {
273             get { return new EqualConstraint(0); }
274         }
275
276         #endregion
277
278         #region NaN
279
280         /// <summary>
281         /// Returns a constraint that tests for NaN
282         /// </summary>
283         public NaNConstraint NaN
284         {
285             get { return new NaNConstraint(); }
286         }
287
288         #endregion
289
290         #region Empty
291
292         /// <summary>
293         /// Returns a constraint that tests for empty
294         /// </summary>
295         public EmptyConstraint Empty
296         {
297             get { return new EmptyConstraint(); }
298         }
299
300         #endregion
301
302         #region Unique
303
304         /// <summary>
305         /// Returns a constraint that tests whether a collection 
306         /// contains all unique items.
307         /// </summary>
308         public UniqueItemsConstraint Unique
309         {
310             get { return new UniqueItemsConstraint(); }
311         }
312
313         #endregion
314
315         #region BinarySerializable
316
317 #if !NETCF && !SILVERLIGHT && !PORTABLE
318         /// <summary>
319         /// Returns a constraint that tests whether an object graph is serializable in binary format.
320         /// </summary>
321         public BinarySerializableConstraint BinarySerializable
322         {
323             get { return new BinarySerializableConstraint(); }
324         }
325 #endif
326
327         #endregion
328
329         #region XmlSerializable
330
331 #if !SILVERLIGHT && !PORTABLE
332         /// <summary>
333         /// Returns a constraint that tests whether an object graph is serializable in xml format.
334         /// </summary>
335         public XmlSerializableConstraint XmlSerializable
336         {
337             get { return new XmlSerializableConstraint(); }
338         }
339 #endif
340
341         #endregion
342
343         #region EqualTo
344
345         /// <summary>
346         /// Returns a constraint that tests two items for equality
347         /// </summary>
348         public EqualConstraint EqualTo(object expected)
349         {
350             return new EqualConstraint(expected);
351         }
352
353         #endregion
354
355         #region SameAs
356
357         /// <summary>
358         /// Returns a constraint that tests that two references are the same object
359         /// </summary>
360         public SameAsConstraint SameAs(object expected)
361         {
362             return new SameAsConstraint(expected);
363         }
364
365         #endregion
366
367         #region GreaterThan
368
369         /// <summary>
370         /// Returns a constraint that tests whether the
371         /// actual value is greater than the supplied argument
372         /// </summary>
373         public GreaterThanConstraint GreaterThan(object expected)
374         {
375             return new GreaterThanConstraint(expected);
376         }
377
378         #endregion
379
380         #region GreaterThanOrEqualTo
381
382         /// <summary>
383         /// Returns a constraint that tests whether the
384         /// actual value is greater than or equal to the supplied argument
385         /// </summary>
386         public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
387         {
388             return new GreaterThanOrEqualConstraint(expected);
389         }
390
391         /// <summary>
392         /// Returns a constraint that tests whether the
393         /// actual value is greater than or equal to the supplied argument
394         /// </summary>
395         public GreaterThanOrEqualConstraint AtLeast(object expected)
396         {
397             return new GreaterThanOrEqualConstraint(expected);
398         }
399
400         #endregion
401
402         #region LessThan
403
404         /// <summary>
405         /// Returns a constraint that tests whether the
406         /// actual value is less than the supplied argument
407         /// </summary>
408         public LessThanConstraint LessThan(object expected)
409         {
410             return new LessThanConstraint(expected);
411         }
412
413         #endregion
414
415         #region LessThanOrEqualTo
416
417         /// <summary>
418         /// Returns a constraint that tests whether the
419         /// actual value is less than or equal to the supplied argument
420         /// </summary>
421         public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
422         {
423             return new LessThanOrEqualConstraint(expected);
424         }
425
426         /// <summary>
427         /// Returns a constraint that tests whether the
428         /// actual value is less than or equal to the supplied argument
429         /// </summary>
430         public LessThanOrEqualConstraint AtMost(object expected)
431         {
432             return new LessThanOrEqualConstraint(expected);
433         }
434
435         #endregion
436
437         #region TypeOf
438
439         /// <summary>
440         /// Returns a constraint that tests whether the actual
441         /// value is of the exact type supplied as an argument.
442         /// </summary>
443         public ExactTypeConstraint TypeOf(Type expectedType)
444         {
445             return new ExactTypeConstraint(expectedType);
446         }
447
448         /// <summary>
449         /// Returns a constraint that tests whether the actual
450         /// value is of the exact type supplied as an argument.
451         /// </summary>
452         public ExactTypeConstraint TypeOf<TExpected>()
453         {
454             return new ExactTypeConstraint(typeof(TExpected));
455         }
456
457         #endregion
458
459         #region InstanceOf
460
461         /// <summary>
462         /// Returns a constraint that tests whether the actual value
463         /// is of the type supplied as an argument or a derived type.
464         /// </summary>
465         public InstanceOfTypeConstraint InstanceOf(Type expectedType)
466         {
467             return new InstanceOfTypeConstraint(expectedType);
468         }
469
470         /// <summary>
471         /// Returns a constraint that tests whether the actual value
472         /// is of the type supplied as an argument or a derived type.
473         /// </summary>
474         public InstanceOfTypeConstraint InstanceOf<TExpected>()
475         {
476             return new InstanceOfTypeConstraint(typeof(TExpected));
477         }
478
479         #endregion
480
481         #region AssignableFrom
482
483         /// <summary>
484         /// Returns a constraint that tests whether the actual value
485         /// is assignable from the type supplied as an argument.
486         /// </summary>
487         public AssignableFromConstraint AssignableFrom(Type expectedType)
488         {
489             return new AssignableFromConstraint(expectedType);
490         }
491
492         /// <summary>
493         /// Returns a constraint that tests whether the actual value
494         /// is assignable from the type supplied as an argument.
495         /// </summary>
496         public AssignableFromConstraint AssignableFrom<TExpected>()
497         {
498             return new AssignableFromConstraint(typeof(TExpected));
499         }
500
501         #endregion
502
503         #region AssignableTo
504
505         /// <summary>
506         /// Returns a constraint that tests whether the actual value
507         /// is assignable from the type supplied as an argument.
508         /// </summary>
509         public AssignableToConstraint AssignableTo(Type expectedType)
510         {
511             return new AssignableToConstraint(expectedType);
512         }
513
514         /// <summary>
515         /// Returns a constraint that tests whether the actual value
516         /// is assignable from the type supplied as an argument.
517         /// </summary>
518         public AssignableToConstraint AssignableTo<TExpected>()
519         {
520             return new AssignableToConstraint(typeof(TExpected));
521         }
522
523         #endregion
524
525         #region EquivalentTo
526
527         /// <summary>
528         /// Returns a constraint that tests whether the actual value
529         /// is a collection containing the same elements as the 
530         /// collection supplied as an argument.
531         /// </summary>
532         public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
533         {
534             return new CollectionEquivalentConstraint(expected);
535         }
536
537         #endregion
538
539         #region SubsetOf
540
541         /// <summary>
542         /// Returns a constraint that tests whether the actual value
543         /// is a subset of the collection supplied as an argument.
544         /// </summary>
545         public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
546         {
547             return new CollectionSubsetConstraint(expected);
548         }
549
550         #endregion
551
552         #region SupersetOf
553
554         /// <summary>
555         /// Returns a constraint that tests whether the actual value
556         /// is a superset of the collection supplied as an argument.
557         /// </summary>
558         public CollectionSupersetConstraint SupersetOf(IEnumerable expected)
559         {
560             return new CollectionSupersetConstraint(expected);
561         }
562
563         #endregion
564
565         #region Ordered
566
567         /// <summary>
568         /// Returns a constraint that tests whether a collection is ordered
569         /// </summary>
570         public CollectionOrderedConstraint Ordered
571         {
572             get { return new CollectionOrderedConstraint(); }
573         }
574
575         #endregion
576
577         #region Member
578
579         /// <summary>
580         /// Returns a new CollectionContainsConstraint checking for the
581         /// presence of a particular object in the collection.
582         /// </summary>
583         public CollectionContainsConstraint Member(object expected)
584         {
585             return new CollectionContainsConstraint(expected);
586         }
587
588         /// <summary>
589         /// Returns a new CollectionContainsConstraint checking for the
590         /// presence of a particular object in the collection.
591         /// </summary>
592         public CollectionContainsConstraint Contains(object expected)
593         {
594             return new CollectionContainsConstraint(expected);
595         }
596
597         #endregion
598
599         #region Contains
600
601         /// <summary>
602         /// Returns a new ContainsConstraint. This constraint
603         /// will, in turn, make use of the appropriate second-level
604         /// constraint, depending on the type of the actual argument. 
605         /// This overload is only used if the item sought is a string,
606         /// since any other type implies that we are looking for a 
607         /// collection member.
608         /// </summary>
609         public ContainsConstraint Contains(string expected)
610         {
611             return new ContainsConstraint(expected);
612         }
613
614         #endregion
615
616         #region StringContaining
617
618         /// <summary>
619         /// Returns a constraint that succeeds if the actual
620         /// value contains the substring supplied as an argument.
621         /// </summary>
622         [Obsolete("Deprecated, use Contains")]
623         public SubstringConstraint StringContaining(string expected)
624         {
625             return new SubstringConstraint(expected);
626         }
627
628         /// <summary>
629         /// Returns a constraint that succeeds if the actual
630         /// value contains the substring supplied as an argument.
631         /// </summary>
632         [Obsolete("Deprecated, use Contains")]
633         public SubstringConstraint ContainsSubstring(string expected)
634         {
635             return new SubstringConstraint(expected);
636         }
637
638         #endregion
639
640         #region DoesNotContain
641
642         /// <summary>
643         /// Returns a constraint that fails if the actual
644         /// value contains the substring supplied as an argument.
645         /// </summary>
646         [Obsolete("Deprecated, use Does.Not.Contain")]
647         public SubstringConstraint DoesNotContain(string expected)
648         {
649             return new ConstraintExpression().Not.ContainsSubstring(expected);
650         }
651
652         #endregion
653
654         #region StartsWith
655
656         /// <summary>
657         /// Returns a constraint that succeeds if the actual
658         /// value starts with the substring supplied as an argument.
659         /// </summary>
660         public StartsWithConstraint StartWith(string expected)
661         {
662             return new StartsWithConstraint(expected);
663         }
664
665         /// <summary>
666         /// Returns a constraint that succeeds if the actual
667         /// value starts with the substring supplied as an argument.
668         /// </summary>
669         public StartsWithConstraint StartsWith(string expected)
670         {
671             return new StartsWithConstraint(expected);
672         }
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         [Obsolete("Deprecated, use Does.StartWith or StartsWith")]
679         public StartsWithConstraint StringStarting(string expected)
680         {
681             return new StartsWithConstraint(expected);
682         }
683
684         #endregion
685
686         #region DoesNotStartWith
687
688         /// <summary>
689         /// Returns a constraint that fails if the actual
690         /// value starts with the substring supplied as an argument.
691         /// </summary>
692         [Obsolete("Deprecated, use Does.Not.StartWith")]
693         public StartsWithConstraint DoesNotStartWith(string expected)
694         {
695             return new ConstraintExpression().Not.StartsWith(expected);
696         }
697
698         #endregion
699
700         #region EndsWith
701
702         /// <summary>
703         /// Returns a constraint that succeeds if the actual
704         /// value ends with the substring supplied as an argument.
705         /// </summary>
706         public EndsWithConstraint EndWith(string expected)
707         {
708             return new EndsWithConstraint(expected);
709         }
710
711         /// <summary>
712         /// Returns a constraint that succeeds if the actual
713         /// value ends with the substring supplied as an argument.
714         /// </summary>
715         public EndsWithConstraint EndsWith(string expected)
716         {
717             return new EndsWithConstraint(expected);
718         }
719
720         /// <summary>
721         /// Returns a constraint that succeeds if the actual
722         /// value ends with the substring supplied as an argument.
723         /// </summary>
724         [Obsolete("Deprecated, use Does.EndWith or EndsWith")]
725         public EndsWithConstraint StringEnding(string expected)
726         {
727             return new EndsWithConstraint(expected);
728         }
729
730         #endregion
731
732         #region DoesNotEndWith
733
734         /// <summary>
735         /// Returns a constraint that fails if the actual
736         /// value ends with the substring supplied as an argument.
737         /// </summary>
738         [Obsolete("Deprecated, use Does.Not.EndWith")]
739         public EndsWithConstraint DoesNotEndWith(string expected)
740         {
741             return new ConstraintExpression().Not.EndsWith(expected);
742         }
743
744         #endregion
745
746         #region Matches
747
748         /// <summary>
749         /// Returns a constraint that succeeds if the actual
750         /// value matches the regular expression supplied as an argument.
751         /// </summary>
752         public RegexConstraint Match(string pattern)
753         {
754             return new RegexConstraint(pattern);
755         }
756
757         /// <summary>
758         /// Returns a constraint that succeeds if the actual
759         /// value matches the regular expression supplied as an argument.
760         /// </summary>
761         public RegexConstraint Matches(string pattern)
762         {
763             return new RegexConstraint(pattern);
764         }
765
766         /// <summary>
767         /// Returns a constraint that succeeds if the actual
768         /// value matches the regular expression supplied as an argument.
769         /// </summary>
770         [Obsolete("Deprecated, use Does.Match or Matches")]
771         public RegexConstraint StringMatching(string pattern)
772         {
773             return new RegexConstraint(pattern);
774         }
775
776         #endregion
777
778         #region DoesNotMatch
779
780         /// <summary>
781         /// Returns a constraint that fails if the actual
782         /// value matches the pattern supplied as an argument.
783         /// </summary>
784         [Obsolete("Deprecated, use Does.Not.Match")]
785         public RegexConstraint DoesNotMatch(string pattern)
786         {
787             return new ConstraintExpression().Not.Matches(pattern);
788         }
789
790         #endregion
791
792 #if !PORTABLE
793         #region SamePath
794
795         /// <summary>
796         /// Returns a constraint that tests whether the path provided 
797         /// is the same as an expected path after canonicalization.
798         /// </summary>
799         public SamePathConstraint SamePath(string expected)
800         {
801             return new SamePathConstraint(expected);
802         }
803
804         #endregion
805
806         #region SubPath
807
808         /// <summary>
809         /// Returns a constraint that tests whether the path provided 
810         /// is a subpath of the expected path after canonicalization.
811         /// </summary>
812         public SubPathConstraint SubPathOf(string expected)
813         {
814             return new SubPathConstraint(expected);
815         }
816
817         #endregion
818
819         #region SamePathOrUnder
820
821         /// <summary>
822         /// Returns a constraint that tests whether the path provided 
823         /// is the same path or under an expected path after canonicalization.
824         /// </summary>
825         public SamePathOrUnderConstraint SamePathOrUnder(string expected)
826         {
827             return new SamePathOrUnderConstraint(expected);
828         }
829
830         #endregion
831 #endif
832
833         #region InRange
834
835         /// <summary>
836         /// Returns a constraint that tests whether the actual value falls 
837         /// within a specified range.
838         /// </summary>
839         public RangeConstraint InRange(IComparable from, IComparable to)
840         {
841             return new RangeConstraint(from, to);
842         }
843
844         #endregion
845
846     }
847 }