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