PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

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