PageRenderTime 24ms CodeModel.GetById 2ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/src/NUnit/framework/Constraints/ConstraintFactory.cs

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