1 // ***********************************************************************
2 // Copyright (c) 2011 Charlie Poole
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
24 using System.Collections;
25 using NUnit.Framework.Constraints;
27 namespace NUnit.Framework
29 public partial class Assert
34 /// Asserts that a condition is true. If the condition is false the method throws
35 /// an <see cref="AssertionException"/>.
37 /// <param name="condition">The evaluated condition</param>
38 /// <param name="message">The message to display in case of failure</param>
39 /// <param name="args">Array of objects to be used in formatting the message</param>
40 public static void True(bool? condition, string message, params object[] args)
42 Assert.That(condition, Is.True ,message, args);
46 /// Asserts that a condition is true. If the condition is false the method throws
47 /// an <see cref="AssertionException"/>.
49 /// <param name="condition">The evaluated condition</param>
50 /// <param name="message">The message to display in case of failure</param>
51 /// <param name="args">Array of objects to be used in formatting the message</param>
52 public static void True(bool condition, string message, params object[] args)
54 Assert.That(condition, Is.True, message, args);
58 /// Asserts that a condition is true. If the condition is false the method throws
59 /// an <see cref="AssertionException"/>.
61 /// <param name="condition">The evaluated condition</param>
62 public static void True(bool? condition)
64 Assert.That(condition, Is.True ,null, null);
68 /// Asserts that a condition is true. If the condition is false the method throws
69 /// an <see cref="AssertionException"/>.
71 /// <param name="condition">The evaluated condition</param>
72 public static void True(bool condition)
74 Assert.That(condition, Is.True ,null, null);
78 /// Asserts that a condition is true. If the condition is false the method throws
79 /// an <see cref="AssertionException"/>.
81 /// <param name="condition">The evaluated condition</param>
82 /// <param name="message">The message to display in case of failure</param>
83 /// <param name="args">Array of objects to be used in formatting the message</param>
84 public static void IsTrue(bool? condition, string message, params object[] args)
86 Assert.That(condition, Is.True ,message, args);
90 /// Asserts that a condition is true. If the condition is false the method throws
91 /// an <see cref="AssertionException"/>.
93 /// <param name="condition">The evaluated condition</param>
94 /// <param name="message">The message to display in case of failure</param>
95 /// <param name="args">Array of objects to be used in formatting the message</param>
96 public static void IsTrue(bool condition, string message, params object[] args)
98 Assert.That(condition, Is.True ,message, args);
102 /// Asserts that a condition is true. If the condition is false the method throws
103 /// an <see cref="AssertionException"/>.
105 /// <param name="condition">The evaluated condition</param>
106 public static void IsTrue(bool? condition)
108 Assert.That(condition, Is.True ,null, null);
112 /// Asserts that a condition is true. If the condition is false the method throws
113 /// an <see cref="AssertionException"/>.
115 /// <param name="condition">The evaluated condition</param>
116 public static void IsTrue(bool condition)
118 Assert.That(condition, Is.True ,null, null);
126 /// Asserts that a condition is false. If the condition is true the method throws
127 /// an <see cref="AssertionException"/>.
129 /// <param name="condition">The evaluated condition</param>
130 /// <param name="message">The message to display in case of failure</param>
131 /// <param name="args">Array of objects to be used in formatting the message</param>
132 public static void False(bool? condition, string message, params object[] args)
134 Assert.That(condition, Is.False ,message, args);
138 /// Asserts that a condition is false. If the condition is true the method throws
139 /// an <see cref="AssertionException"/>.
141 /// <param name="condition">The evaluated condition</param>
142 /// <param name="message">The message to display in case of failure</param>
143 /// <param name="args">Array of objects to be used in formatting the message</param>
144 public static void False(bool condition, string message, params object[] args)
146 Assert.That(condition, Is.False ,message, args);
150 /// Asserts that a condition is false. If the condition is true the method throws
151 /// an <see cref="AssertionException"/>.
153 /// <param name="condition">The evaluated condition</param>
154 public static void False(bool? condition)
156 Assert.That(condition, Is.False ,null, null);
160 /// Asserts that a condition is false. If the condition is true the method throws
161 /// an <see cref="AssertionException"/>.
163 /// <param name="condition">The evaluated condition</param>
164 public static void False(bool condition)
166 Assert.That(condition, Is.False ,null, null);
170 /// Asserts that a condition is false. If the condition is true the method throws
171 /// an <see cref="AssertionException"/>.
173 /// <param name="condition">The evaluated condition</param>
174 /// <param name="message">The message to display in case of failure</param>
175 /// <param name="args">Array of objects to be used in formatting the message</param>
176 public static void IsFalse(bool? condition, string message, params object[] args)
178 Assert.That(condition, Is.False ,message, args);
182 /// Asserts that a condition is false. If the condition is true the method throws
183 /// an <see cref="AssertionException"/>.
185 /// <param name="condition">The evaluated condition</param>
186 /// <param name="message">The message to display in case of failure</param>
187 /// <param name="args">Array of objects to be used in formatting the message</param>
188 public static void IsFalse(bool condition, string message, params object[] args)
190 Assert.That(condition, Is.False ,message, args);
194 /// Asserts that a condition is false. If the condition is true the method throws
195 /// an <see cref="AssertionException"/>.
197 /// <param name="condition">The evaluated condition</param>
198 public static void IsFalse(bool? condition)
200 Assert.That(condition, Is.False ,null, null);
204 /// Asserts that a condition is false. If the condition is true the method throws
205 /// an <see cref="AssertionException"/>.
207 /// <param name="condition">The evaluated condition</param>
208 public static void IsFalse(bool condition)
210 Assert.That(condition, Is.False ,null, null);
218 /// Verifies that the object that is passed in is not equal to <code>null</code>
219 /// If the object is <code>null</code> then an <see cref="AssertionException"/>
222 /// <param name="anObject">The object that is to be tested</param>
223 /// <param name="message">The message to display in case of failure</param>
224 /// <param name="args">Array of objects to be used in formatting the message</param>
225 public static void NotNull(object anObject, string message, params object[] args)
227 Assert.That(anObject, Is.Not.Null ,message, args);
231 /// Verifies that the object that is passed in is not equal to <code>null</code>
232 /// If the object is <code>null</code> then an <see cref="AssertionException"/>
235 /// <param name="anObject">The object that is to be tested</param>
236 public static void NotNull(object anObject)
238 Assert.That(anObject, Is.Not.Null ,null, null);
242 /// Verifies that the object that is passed in is not equal to <code>null</code>
243 /// If the object is <code>null</code> then an <see cref="AssertionException"/>
246 /// <param name="anObject">The object that is to be tested</param>
247 /// <param name="message">The message to display in case of failure</param>
248 /// <param name="args">Array of objects to be used in formatting the message</param>
249 public static void IsNotNull(object anObject, string message, params object[] args)
251 Assert.That(anObject, Is.Not.Null ,message, args);
255 /// Verifies that the object that is passed in is not equal to <code>null</code>
256 /// If the object is <code>null</code> then an <see cref="AssertionException"/>
259 /// <param name="anObject">The object that is to be tested</param>
260 public static void IsNotNull(object anObject)
262 Assert.That(anObject, Is.Not.Null ,null, null);
270 /// Verifies that the object that is passed in is equal to <code>null</code>
271 /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
274 /// <param name="anObject">The object that is to be tested</param>
275 /// <param name="message">The message to display in case of failure</param>
276 /// <param name="args">Array of objects to be used in formatting the message</param>
277 public static void Null(object anObject, string message, params object[] args)
279 Assert.That(anObject, Is.Null ,message, args);
283 /// Verifies that the object that is passed in is equal to <code>null</code>
284 /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
287 /// <param name="anObject">The object that is to be tested</param>
288 public static void Null(object anObject)
290 Assert.That(anObject, Is.Null ,null, null);
294 /// Verifies that the object that is passed in is equal to <code>null</code>
295 /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
298 /// <param name="anObject">The object that is to be tested</param>
299 /// <param name="message">The message to display in case of failure</param>
300 /// <param name="args">Array of objects to be used in formatting the message</param>
301 public static void IsNull(object anObject, string message, params object[] args)
303 Assert.That(anObject, Is.Null ,message, args);
307 /// Verifies that the object that is passed in is equal to <code>null</code>
308 /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
311 /// <param name="anObject">The object that is to be tested</param>
312 public static void IsNull(object anObject)
314 Assert.That(anObject, Is.Null ,null, null);
322 /// Verifies that the double that is passed in is an <code>NaN</code> value.
323 /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
326 /// <param name="aDouble">The value that is to be tested</param>
327 /// <param name="message">The message to display in case of failure</param>
328 /// <param name="args">Array of objects to be used in formatting the message</param>
329 public static void IsNaN(double aDouble, string message, params object[] args)
331 Assert.That(aDouble, Is.NaN ,message, args);
335 /// Verifies that the double that is passed in is an <code>NaN</code> value.
336 /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
339 /// <param name="aDouble">The value that is to be tested</param>
340 public static void IsNaN(double aDouble)
342 Assert.That(aDouble, Is.NaN ,null, null);
346 /// Verifies that the double that is passed in is an <code>NaN</code> value.
347 /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
350 /// <param name="aDouble">The value that is to be tested</param>
351 /// <param name="message">The message to display in case of failure</param>
352 /// <param name="args">Array of objects to be used in formatting the message</param>
353 public static void IsNaN(double? aDouble, string message, params object[] args)
355 Assert.That(aDouble, Is.NaN ,message, args);
359 /// Verifies that the double that is passed in is an <code>NaN</code> value.
360 /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
363 /// <param name="aDouble">The value that is to be tested</param>
364 public static void IsNaN(double? aDouble)
366 Assert.That(aDouble, Is.NaN ,null, null);
376 /// Assert that a string is empty - that is equal to string.Empty
378 /// <param name="aString">The string to be tested</param>
379 /// <param name="message">The message to display in case of failure</param>
380 /// <param name="args">Array of objects to be used in formatting the message</param>
381 public static void IsEmpty(string aString, string message, params object[] args)
383 Assert.That(aString, new EmptyStringConstraint() ,message, args);
387 /// Assert that a string is empty - that is equal to string.Empty
389 /// <param name="aString">The string to be tested</param>
390 public static void IsEmpty(string aString)
392 Assert.That(aString, new EmptyStringConstraint() ,null, null);
400 /// Assert that an array, list or other collection is empty
402 /// <param name="collection">An array, list or other collection implementing ICollection</param>
403 /// <param name="message">The message to display in case of failure</param>
404 /// <param name="args">Array of objects to be used in formatting the message</param>
405 public static void IsEmpty(IEnumerable collection, string message, params object[] args)
407 Assert.That(collection, new EmptyCollectionConstraint() ,message, args);
411 /// Assert that an array, list or other collection is empty
413 /// <param name="collection">An array, list or other collection implementing ICollection</param>
414 public static void IsEmpty(IEnumerable collection)
416 Assert.That(collection, new EmptyCollectionConstraint() ,null, null);
428 /// Assert that a string is not empty - that is not equal to string.Empty
430 /// <param name="aString">The string to be tested</param>
431 /// <param name="message">The message to display in case of failure</param>
432 /// <param name="args">Array of objects to be used in formatting the message</param>
433 public static void IsNotEmpty(string aString, string message, params object[] args)
435 Assert.That(aString, Is.Not.Empty ,message, args);
439 /// Assert that a string is not empty - that is not equal to string.Empty
441 /// <param name="aString">The string to be tested</param>
442 public static void IsNotEmpty(string aString)
444 Assert.That(aString, Is.Not.Empty ,null, null);
452 /// Assert that an array, list or other collection is not empty
454 /// <param name="collection">An array, list or other collection implementing ICollection</param>
455 /// <param name="message">The message to display in case of failure</param>
456 /// <param name="args">Array of objects to be used in formatting the message</param>
457 public static void IsNotEmpty(IEnumerable collection, string message, params object[] args)
459 Assert.That(collection, Is.Not.Empty ,message, args);
463 /// Assert that an array, list or other collection is not empty
465 /// <param name="collection">An array, list or other collection implementing ICollection</param>
466 public static void IsNotEmpty(IEnumerable collection)
468 Assert.That(collection, Is.Not.Empty ,null, null);