PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/framework/Constraints/ConstraintExpression.cs

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