PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/nunit24/NUnitFramework/framework/CollectionAssert.cs

https://bitbucket.org/danipen/mono
C# | 595 lines | 227 code | 61 blank | 307 comment | 0 complexity | 28493daf54c83a5cc2d22bd3dda985b4 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  1. // ****************************************************************
  2. // This is free software licensed under the NUnit license. You
  3. // may obtain a copy of the license as well as information regarding
  4. // copyright ownership at http://nunit.org/?p=license&r=2.4.
  5. // ****************************************************************
  6. using System;
  7. using System.Collections;
  8. using System.ComponentModel;
  9. using NUnit.Framework.Constraints;
  10. namespace NUnit.Framework
  11. {
  12. /// <summary>
  13. /// A set of Assert methods operationg on one or more collections
  14. /// </summary>
  15. public class CollectionAssert
  16. {
  17. #region Equals and ReferenceEquals
  18. /// <summary>
  19. /// The Equals method throws an AssertionException. This is done
  20. /// to make sure there is no mistake by calling this function.
  21. /// </summary>
  22. /// <param name="a"></param>
  23. /// <param name="b"></param>
  24. [EditorBrowsable(EditorBrowsableState.Never)]
  25. public static new bool Equals(object a, object b)
  26. {
  27. throw new AssertionException("Assert.Equals should not be used for Assertions");
  28. }
  29. /// <summary>
  30. /// override the default ReferenceEquals to throw an AssertionException. This
  31. /// implementation makes sure there is no mistake in calling this function
  32. /// as part of Assert.
  33. /// </summary>
  34. /// <param name="a"></param>
  35. /// <param name="b"></param>
  36. public static new void ReferenceEquals(object a, object b)
  37. {
  38. throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions");
  39. }
  40. #endregion
  41. #region AllItemsAreInstancesOfType
  42. /// <summary>
  43. /// Asserts that all items contained in collection are of the type specified by expectedType.
  44. /// </summary>
  45. /// <param name="collection">IEnumerable containing objects to be considered</param>
  46. /// <param name="expectedType">System.Type that all objects in collection must be instances of</param>
  47. public static void AllItemsAreInstancesOfType (IEnumerable collection, Type expectedType)
  48. {
  49. AllItemsAreInstancesOfType(collection, expectedType, string.Empty, null);
  50. }
  51. /// <summary>
  52. /// Asserts that all items contained in collection are of the type specified by expectedType.
  53. /// </summary>
  54. /// <param name="collection">IEnumerable containing objects to be considered</param>
  55. /// <param name="expectedType">System.Type that all objects in collection must be instances of</param>
  56. /// <param name="message">The message that will be displayed on failure</param>
  57. public static void AllItemsAreInstancesOfType (IEnumerable collection, Type expectedType, string message)
  58. {
  59. AllItemsAreInstancesOfType(collection, expectedType, message, null);
  60. }
  61. /// <summary>
  62. /// Asserts that all items contained in collection are of the type specified by expectedType.
  63. /// </summary>
  64. /// <param name="collection">IEnumerable containing objects to be considered</param>
  65. /// <param name="expectedType">System.Type that all objects in collection must be instances of</param>
  66. /// <param name="message">The message that will be displayed on failure</param>
  67. /// <param name="args">Arguments to be used in formatting the message</param>
  68. public static void AllItemsAreInstancesOfType (IEnumerable collection, Type expectedType, string message, params object[] args)
  69. {
  70. Assert.That(collection, new AllItemsConstraint(new InstanceOfTypeConstraint(expectedType)), message, args);
  71. }
  72. #endregion
  73. #region AllItemsAreNotNull
  74. /// <summary>
  75. /// Asserts that all items contained in collection are not equal to null.
  76. /// </summary>
  77. /// <param name="collection">IEnumerable containing objects to be considered</param>
  78. public static void AllItemsAreNotNull (IEnumerable collection)
  79. {
  80. AllItemsAreNotNull(collection, string.Empty, null);
  81. }
  82. /// <summary>
  83. /// Asserts that all items contained in collection are not equal to null.
  84. /// </summary>
  85. /// <param name="collection">IEnumerable containing objects to be considered</param>
  86. /// <param name="message">The message that will be displayed on failure</param>
  87. public static void AllItemsAreNotNull (IEnumerable collection, string message)
  88. {
  89. AllItemsAreNotNull(collection, message, null);
  90. }
  91. /// <summary>
  92. /// Asserts that all items contained in collection are not equal to null.
  93. /// </summary>
  94. /// <param name="collection">IEnumerable of objects to be considered</param>
  95. /// <param name="message">The message that will be displayed on failure</param>
  96. /// <param name="args">Arguments to be used in formatting the message</param>
  97. public static void AllItemsAreNotNull (IEnumerable collection, string message, params object[] args)
  98. {
  99. Assert.That(collection, new AllItemsConstraint(new NotConstraint(new EqualConstraint(null))), message, args);
  100. }
  101. #endregion
  102. #region AllItemsAreUnique
  103. /// <summary>
  104. /// Ensures that every object contained in collection exists within the collection
  105. /// once and only once.
  106. /// </summary>
  107. /// <param name="collection">IEnumerable of objects to be considered</param>
  108. public static void AllItemsAreUnique (IEnumerable collection)
  109. {
  110. AllItemsAreUnique(collection, string.Empty, null);
  111. }
  112. /// <summary>
  113. /// Ensures that every object contained in collection exists within the collection
  114. /// once and only once.
  115. /// </summary>
  116. /// <param name="collection">IEnumerable of objects to be considered</param>
  117. /// <param name="message">The message that will be displayed on failure</param>
  118. public static void AllItemsAreUnique (IEnumerable collection, string message)
  119. {
  120. AllItemsAreUnique(collection, message, null);
  121. }
  122. /// <summary>
  123. /// Ensures that every object contained in collection exists within the collection
  124. /// once and only once.
  125. /// </summary>
  126. /// <param name="collection">IEnumerable of objects to be considered</param>
  127. /// <param name="message">The message that will be displayed on failure</param>
  128. /// <param name="args">Arguments to be used in formatting the message</param>
  129. public static void AllItemsAreUnique (IEnumerable collection, string message, params object[] args)
  130. {
  131. Assert.That(collection, new UniqueItemsConstraint(), message, args);
  132. }
  133. #endregion
  134. #region AreEqual
  135. /// <summary>
  136. /// Asserts that expected and actual are exactly equal. The collections must have the same count,
  137. /// and contain the exact same objects in the same order.
  138. /// </summary>
  139. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  140. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  141. public static void AreEqual (IEnumerable expected, IEnumerable actual)
  142. {
  143. //AreEqual(expected, actual, null, string.Empty, null);
  144. Assert.That(actual, new EqualConstraint(expected));
  145. }
  146. /// <summary>
  147. /// Asserts that expected and actual are exactly equal. The collections must have the same count,
  148. /// and contain the exact same objects in the same order.
  149. /// If comparer is not null then it will be used to compare the objects.
  150. /// </summary>
  151. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  152. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  153. /// <param name="comparer">The IComparer to use in comparing objects from each IEnumerable</param>
  154. public static void AreEqual (IEnumerable expected, IEnumerable actual, IComparer comparer)
  155. {
  156. AreEqual(expected, actual, comparer, string.Empty, null);
  157. }
  158. /// <summary>
  159. /// Asserts that expected and actual are exactly equal. The collections must have the same count,
  160. /// and contain the exact same objects in the same order.
  161. /// </summary>
  162. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  163. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  164. /// <param name="message">The message that will be displayed on failure</param>
  165. public static void AreEqual (IEnumerable expected, IEnumerable actual, string message)
  166. {
  167. //AreEqual(expected, actual, null, message, null);
  168. Assert.That(actual, new EqualConstraint(expected), message);
  169. }
  170. /// <summary>
  171. /// Asserts that expected and actual are exactly equal. The collections must have the same count,
  172. /// and contain the exact same objects in the same order.
  173. /// If comparer is not null then it will be used to compare the objects.
  174. /// </summary>
  175. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  176. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  177. /// <param name="comparer">The IComparer to use in comparing objects from each IEnumerable</param>
  178. /// <param name="message">The message that will be displayed on failure</param>
  179. public static void AreEqual (IEnumerable expected, IEnumerable actual, IComparer comparer, string message)
  180. {
  181. AreEqual(expected, actual, comparer, message, null);
  182. }
  183. /// <summary>
  184. /// Asserts that expected and actual are exactly equal. The collections must have the same count,
  185. /// and contain the exact same objects in the same order.
  186. /// </summary>
  187. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  188. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  189. /// <param name="message">The message that will be displayed on failure</param>
  190. /// <param name="args">Arguments to be used in formatting the message</param>
  191. public static void AreEqual (IEnumerable expected, IEnumerable actual, string message, params object[] args)
  192. {
  193. //AreEqual(expected, actual, null, message, args);
  194. Assert.That(actual, new EqualConstraint(expected), message, args);
  195. }
  196. /// <summary>
  197. /// Asserts that expected and actual are exactly equal. The collections must have the same count,
  198. /// and contain the exact same objects in the same order.
  199. /// If comparer is not null then it will be used to compare the objects.
  200. /// </summary>
  201. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  202. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  203. /// <param name="comparer">The IComparer to use in comparing objects from each IEnumerable</param>
  204. /// <param name="message">The message that will be displayed on failure</param>
  205. /// <param name="args">Arguments to be used in formatting the message</param>
  206. public static void AreEqual (IEnumerable expected, IEnumerable actual, IComparer comparer, string message, params object[] args)
  207. {
  208. Assert.That(actual, new EqualConstraint(expected).Comparer(comparer), message, args);
  209. }
  210. #endregion
  211. #region AreEquivalent
  212. /// <summary>
  213. /// Asserts that expected and actual are equivalent, containing the same objects but the match may be in any order.
  214. /// </summary>
  215. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  216. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  217. public static void AreEquivalent (IEnumerable expected, IEnumerable actual)
  218. {
  219. AreEquivalent(expected, actual, string.Empty, null);
  220. }
  221. /// <summary>
  222. /// Asserts that expected and actual are equivalent, containing the same objects but the match may be in any order.
  223. /// </summary>
  224. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  225. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  226. /// <param name="message">The message that will be displayed on failure</param>
  227. public static void AreEquivalent (IEnumerable expected, IEnumerable actual, string message)
  228. {
  229. AreEquivalent(expected, actual, message, null);
  230. }
  231. /// <summary>
  232. /// Asserts that expected and actual are equivalent, containing the same objects but the match may be in any order.
  233. /// </summary>
  234. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  235. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  236. /// <param name="message">The message that will be displayed on failure</param>
  237. /// <param name="args">Arguments to be used in formatting the message</param>
  238. public static void AreEquivalent (IEnumerable expected, IEnumerable actual, string message, params object[] args)
  239. {
  240. Assert.That(actual, new CollectionEquivalentConstraint(expected), message, args);
  241. }
  242. #endregion
  243. #region AreNotEqual
  244. /// <summary>
  245. /// Asserts that expected and actual are not exactly equal.
  246. /// </summary>
  247. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  248. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  249. public static void AreNotEqual (IEnumerable expected, IEnumerable actual)
  250. {
  251. Assert.That(actual, new NotConstraint(new EqualConstraint(expected)));
  252. }
  253. /// <summary>
  254. /// Asserts that expected and actual are not exactly equal.
  255. /// If comparer is not null then it will be used to compare the objects.
  256. /// </summary>
  257. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  258. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  259. /// <param name="comparer">The IComparer to use in comparing objects from each IEnumerable</param>
  260. public static void AreNotEqual (IEnumerable expected, IEnumerable actual, IComparer comparer)
  261. {
  262. AreNotEqual(expected, actual, comparer, string.Empty, null);
  263. }
  264. /// <summary>
  265. /// Asserts that expected and actual are not exactly equal.
  266. /// </summary>
  267. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  268. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  269. /// <param name="message">The message that will be displayed on failure</param>
  270. public static void AreNotEqual (IEnumerable expected, IEnumerable actual, string message)
  271. {
  272. //AreNotEqual(expected, actual, null, message, null);
  273. //Assert.AreNotEqual( expected, actual, message );
  274. Assert.That(actual, new NotConstraint(new EqualConstraint(expected)), message);
  275. }
  276. /// <summary>
  277. /// Asserts that expected and actual are not exactly equal.
  278. /// If comparer is not null then it will be used to compare the objects.
  279. /// </summary>
  280. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  281. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  282. /// <param name="comparer">The IComparer to use in comparing objects from each IEnumerable</param>
  283. /// <param name="message">The message that will be displayed on failure</param>
  284. public static void AreNotEqual (IEnumerable expected, IEnumerable actual, IComparer comparer, string message)
  285. {
  286. AreNotEqual(expected, actual, comparer, message, null);
  287. }
  288. /// <summary>
  289. /// Asserts that expected and actual are not exactly equal.
  290. /// </summary>
  291. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  292. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  293. /// <param name="message">The message that will be displayed on failure</param>
  294. /// <param name="args">Arguments to be used in formatting the message</param>
  295. public static void AreNotEqual (IEnumerable expected, IEnumerable actual, string message, params object[] args)
  296. {
  297. //AreNotEqual(expected, actual, null, message, args);
  298. //Assert.AreNotEqual( expected, actual, message, args );
  299. Assert.That(actual, new NotConstraint(new EqualConstraint(expected)), message, args);
  300. }
  301. /// <summary>
  302. /// Asserts that expected and actual are not exactly equal.
  303. /// If comparer is not null then it will be used to compare the objects.
  304. /// </summary>
  305. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  306. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  307. /// <param name="comparer">The IComparer to use in comparing objects from each IEnumerable</param>
  308. /// <param name="message">The message that will be displayed on failure</param>
  309. /// <param name="args">Arguments to be used in formatting the message</param>
  310. public static void AreNotEqual (IEnumerable expected, IEnumerable actual, IComparer comparer, string message, params object[] args)
  311. {
  312. Assert.That(actual, new NotConstraint(new EqualConstraint(expected).Comparer(comparer)), message, args);
  313. }
  314. #endregion
  315. #region AreNotEquivalent
  316. /// <summary>
  317. /// Asserts that expected and actual are not equivalent.
  318. /// </summary>
  319. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  320. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  321. public static void AreNotEquivalent (IEnumerable expected, IEnumerable actual)
  322. {
  323. AreNotEquivalent(expected, actual, string.Empty, null);
  324. }
  325. /// <summary>
  326. /// Asserts that expected and actual are not equivalent.
  327. /// </summary>
  328. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  329. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  330. /// <param name="message">The message that will be displayed on failure</param>
  331. public static void AreNotEquivalent (IEnumerable expected, IEnumerable actual, string message)
  332. {
  333. AreNotEquivalent(expected, actual, message, null);
  334. }
  335. /// <summary>
  336. /// Asserts that expected and actual are not equivalent.
  337. /// </summary>
  338. /// <param name="expected">The first IEnumerable of objects to be considered</param>
  339. /// <param name="actual">The second IEnumerable of objects to be considered</param>
  340. /// <param name="message">The message that will be displayed on failure</param>
  341. /// <param name="args">Arguments to be used in formatting the message</param>
  342. public static void AreNotEquivalent (IEnumerable expected, IEnumerable actual, string message, params object[] args)
  343. {
  344. Assert.That(actual, new NotConstraint(new CollectionEquivalentConstraint(expected)), message, args);
  345. }
  346. #endregion
  347. #region Contains
  348. /// <summary>
  349. /// Asserts that collection contains actual as an item.
  350. /// </summary>
  351. /// <param name="collection">IEnumerable of objects to be considered</param>
  352. /// <param name="actual">Object to be found within collection</param>
  353. public static void Contains (IEnumerable collection, Object actual)
  354. {
  355. Contains(collection, actual, string.Empty, null);
  356. }
  357. /// <summary>
  358. /// Asserts that collection contains actual as an item.
  359. /// </summary>
  360. /// <param name="collection">IEnumerable of objects to be considered</param>
  361. /// <param name="actual">Object to be found within collection</param>
  362. /// <param name="message">The message that will be displayed on failure</param>
  363. public static void Contains (IEnumerable collection, Object actual, string message)
  364. {
  365. Contains(collection, actual, message, null);
  366. }
  367. /// <summary>
  368. /// Asserts that collection contains actual as an item.
  369. /// </summary>
  370. /// <param name="collection">IEnumerable of objects to be considered</param>
  371. /// <param name="actual">Object to be found within collection</param>
  372. /// <param name="message">The message that will be displayed on failure</param>
  373. /// <param name="args">Arguments to be used in formatting the message</param>
  374. public static void Contains (IEnumerable collection, Object actual, string message, params object[] args)
  375. {
  376. Assert.That(collection, new CollectionContainsConstraint(actual), message, args);
  377. }
  378. #endregion
  379. #region DoesNotContain
  380. /// <summary>
  381. /// Asserts that collection does not contain actual as an item.
  382. /// </summary>
  383. /// <param name="collection">IEnumerable of objects to be considered</param>
  384. /// <param name="actual">Object that cannot exist within collection</param>
  385. public static void DoesNotContain (IEnumerable collection, Object actual)
  386. {
  387. DoesNotContain(collection, actual, string.Empty, null);
  388. }
  389. /// <summary>
  390. /// Asserts that collection does not contain actual as an item.
  391. /// </summary>
  392. /// <param name="collection">IEnumerable of objects to be considered</param>
  393. /// <param name="actual">Object that cannot exist within collection</param>
  394. /// <param name="message">The message that will be displayed on failure</param>
  395. public static void DoesNotContain (IEnumerable collection, Object actual, string message)
  396. {
  397. DoesNotContain(collection, actual, message, null);
  398. }
  399. /// <summary>
  400. /// Asserts that collection does not contain actual as an item.
  401. /// </summary>
  402. /// <param name="collection">IEnumerable of objects to be considered</param>
  403. /// <param name="actual">Object that cannot exist within collection</param>
  404. /// <param name="message">The message that will be displayed on failure</param>
  405. /// <param name="args">Arguments to be used in formatting the message</param>
  406. public static void DoesNotContain (IEnumerable collection, Object actual, string message, params object[] args)
  407. {
  408. Assert.That(collection, new NotConstraint( new CollectionContainsConstraint( actual ) ), message, args);
  409. }
  410. #endregion
  411. #region IsNotSubsetOf
  412. /// <summary>
  413. /// Asserts that superset is not a subject of subset.
  414. /// </summary>
  415. /// <param name="subset">The IEnumerable superset to be considered</param>
  416. /// <param name="superset">The IEnumerable subset to be considered</param>
  417. public static void IsNotSubsetOf (IEnumerable subset, IEnumerable superset)
  418. {
  419. IsNotSubsetOf(subset, superset, string.Empty, null);
  420. }
  421. /// <summary>
  422. /// Asserts that superset is not a subject of subset.
  423. /// </summary>
  424. /// <param name="subset">The IEnumerable superset to be considered</param>
  425. /// <param name="superset">The IEnumerable subset to be considered</param>
  426. /// <param name="message">The message that will be displayed on failure</param>
  427. public static void IsNotSubsetOf (IEnumerable subset, IEnumerable superset, string message)
  428. {
  429. IsNotSubsetOf(subset, superset, message, null);
  430. }
  431. /// <summary>
  432. /// Asserts that superset is not a subject of subset.
  433. /// </summary>
  434. /// <param name="subset">The IEnumerable superset to be considered</param>
  435. /// <param name="superset">The IEnumerable subset to be considered</param>
  436. /// <param name="message">The message that will be displayed on failure</param>
  437. /// <param name="args">Arguments to be used in formatting the message</param>
  438. public static void IsNotSubsetOf (IEnumerable subset, IEnumerable superset, string message, params object[] args)
  439. {
  440. Assert.That(subset, new NotConstraint(new CollectionSubsetConstraint(superset)), message, args);
  441. }
  442. #endregion
  443. #region IsSubsetOf
  444. /// <summary>
  445. /// Asserts that superset is a subset of subset.
  446. /// </summary>
  447. /// <param name="subset">The IEnumerable superset to be considered</param>
  448. /// <param name="superset">The IEnumerable subset to be considered</param>
  449. public static void IsSubsetOf (IEnumerable subset, IEnumerable superset)
  450. {
  451. IsSubsetOf(subset, superset, string.Empty, null);
  452. }
  453. /// <summary>
  454. /// Asserts that superset is a subset of subset.
  455. /// </summary>
  456. /// <param name="subset">The IEnumerable superset to be considered</param>
  457. /// <param name="superset">The IEnumerable subset to be considered</param>
  458. /// <param name="message">The message that will be displayed on failure</param>
  459. public static void IsSubsetOf (IEnumerable subset, IEnumerable superset, string message)
  460. {
  461. IsSubsetOf(subset, superset, message, null);
  462. }
  463. /// <summary>
  464. /// Asserts that superset is a subset of subset.
  465. /// </summary>
  466. /// <param name="subset">The IEnumerable superset to be considered</param>
  467. /// <param name="superset">The IEnumerable subset to be considered</param>
  468. /// <param name="message">The message that will be displayed on failure</param>
  469. /// <param name="args">Arguments to be used in formatting the message</param>
  470. public static void IsSubsetOf (IEnumerable subset, IEnumerable superset, string message, params object[] args)
  471. {
  472. Assert.That(subset, new CollectionSubsetConstraint(superset), message, args);
  473. }
  474. #endregion
  475. #region IsEmpty
  476. /// <summary>
  477. /// Assert that an array, list or other collection is empty
  478. /// </summary>
  479. /// <param name="collection">An array, list or other collection implementing IEnumerable</param>
  480. /// <param name="message">The message to be displayed on failure</param>
  481. /// <param name="args">Arguments to be used in formatting the message</param>
  482. public static void IsEmpty(IEnumerable collection, string message, params object[] args)
  483. {
  484. Assert.That(collection, new EmptyConstraint(), message, args);
  485. }
  486. /// <summary>
  487. /// Assert that an array, list or other collection is empty
  488. /// </summary>
  489. /// <param name="collection">An array, list or other collection implementing IEnumerable</param>
  490. /// <param name="message">The message to be displayed on failure</param>
  491. public static void IsEmpty(IEnumerable collection, string message)
  492. {
  493. IsEmpty(collection, message, null);
  494. }
  495. /// <summary>
  496. /// Assert that an array,list or other collection is empty
  497. /// </summary>
  498. /// <param name="collection">An array, list or other collection implementing IEnumerable</param>
  499. public static void IsEmpty(IEnumerable collection)
  500. {
  501. IsEmpty(collection, string.Empty, null);
  502. }
  503. #endregion
  504. #region IsNotEmpty
  505. /// <summary>
  506. /// Assert that an array, list or other collection is empty
  507. /// </summary>
  508. /// <param name="collection">An array, list or other collection implementing IEnumerable</param>
  509. /// <param name="message">The message to be displayed on failure</param>
  510. /// <param name="args">Arguments to be used in formatting the message</param>
  511. public static void IsNotEmpty(IEnumerable collection, string message, params object[] args)
  512. {
  513. Assert.That(collection, new NotConstraint(new EmptyConstraint()), message, args);
  514. }
  515. /// <summary>
  516. /// Assert that an array, list or other collection is empty
  517. /// </summary>
  518. /// <param name="collection">An array, list or other collection implementing IEnumerable</param>
  519. /// <param name="message">The message to be displayed on failure</param>
  520. public static void IsNotEmpty(IEnumerable collection, string message)
  521. {
  522. IsNotEmpty(collection, message, null);
  523. }
  524. /// <summary>
  525. /// Assert that an array,list or other collection is empty
  526. /// </summary>
  527. /// <param name="collection">An array, list or other collection implementing IEnumerable</param>
  528. public static void IsNotEmpty(IEnumerable collection)
  529. {
  530. IsNotEmpty(collection, string.Empty, null);
  531. }
  532. #endregion
  533. }
  534. }