* Mono.Posix.dll.sources: Rename Mono.Posix to Mono.Unix.
[mono.git] / mcs / nunit20 / framework / Assert.cs
1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
3 '
4 ' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright © 2000-2003 Philip A. Craig
6 '
7 ' This software is provided 'as-is', without any express or implied warranty. In no 
8 ' event will the authors be held liable for any damages arising from the use of this 
9 ' software.
10
11 ' Permission is granted to anyone to use this software for any purpose, including 
12 ' commercial applications, and to alter it and redistribute it freely, subject to the 
13 ' following restrictions:
14 '
15 ' 1. The origin of this software must not be misrepresented; you must not claim that 
16 ' you wrote the original software. If you use this software in a product, an 
17 ' acknowledgment (see the following) in the product documentation is required.
18 '
19 ' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright © 2000-2003 Philip A. Craig
21 '
22 ' 2. Altered source versions must be plainly marked as such, and must not be 
23 ' misrepresented as being the original software.
24 '
25 ' 3. This notice may not be removed or altered from any source distribution.
26 '
27 '***********************************************************************************/
28 #endregion
29
30 using System;
31 using System.Collections;
32 using System.ComponentModel;
33
34 namespace NUnit.Framework
35 {
36         /// <summary>
37         /// A set of Assert methods
38         /// </summary>
39         public class Assert
40         {
41                 private static int counter = 0;
42                 
43                 /// <summary>
44                 /// Gets the number of assertions executed so far and 
45                 /// resets the counter to zero.
46                 /// </summary>
47                 public static int Counter
48                 {
49                         get
50                         {
51                                 int cnt = counter;
52                                 counter = 0;
53                                 return cnt;
54                         }
55                 }
56
57                 /// <summary>
58                 /// A private constructor disallows any instances of this object. 
59                 /// </summary>
60                 private Assert()
61                 {}
62
63                 /// <summary>
64                 /// Asserts that a condition is true. If the condition is false the method throws
65                 /// an <see cref="AssertionException"/>.
66                 /// </summary> 
67                 /// <param name="condition">The evaluated condition</param>
68                 /// <param name="message">The message to display if the condition is false</param>
69                 /// <param name="args">Arguments to be used in formatting the message</param>
70                 static public void IsTrue(bool condition, string message, params object[] args) 
71                 {
72                         ++counter;
73                         if (!condition)
74                                 Assert.Fail(message, args);
75                 }
76     
77                 /// <summary>
78                 /// Asserts that a condition is true. If the condition is false the method throws
79                 /// an <see cref="AssertionException"/>.
80                 /// </summary>
81                 /// <param name="condition">The evaluated condition</param>
82                 /// <param name="message">The message to display if the condition is false</param>
83                 static public void IsTrue(bool condition, string message) 
84                 {
85                         Assert.IsTrue(condition, message, null);
86                 }
87
88                 /// <summary>
89                 /// Asserts that a condition is true. If the condition is false the method throws
90                 /// an <see cref="AssertionException"/>.
91                 /// </summary>
92                 /// <param name="condition">The evaluated condition</param>
93                 static public void IsTrue(bool condition) 
94                 {
95                         Assert.IsTrue(condition, string.Empty, null);
96                 }
97
98                 /// <summary>
99                 /// Asserts that a condition is false. If the condition is true the method throws
100                 /// an <see cref="AssertionException"/>.
101                 /// </summary>
102                 /// <param name="condition">The evaluated condition</param>
103                 /// <param name="message">The message to display if the condition is true</param>
104                 /// <param name="args">Arguments to be used in formatting the message</param>
105                 static public void IsFalse(bool condition, string message, params object[] args) 
106                 {
107                         ++counter;
108                         if (condition)
109                                 Assert.Fail(message, args);
110                 }
111                 
112                 /// <summary>
113                 /// Asserts that a condition is false. If the condition is true the method throws
114                 /// an <see cref="AssertionException"/>.
115                 /// </summary>
116                 /// <param name="condition">The evaluated condition</param>
117                 /// <param name="message">The message to display if the condition is true</param>
118                 static public void IsFalse(bool condition, string message) 
119                 {
120                         Assert.IsFalse( condition, message, null );
121                 }
122                 
123                 /// <summary>
124                 /// Asserts that a condition is false. If the condition is true the method throws
125                 /// an <see cref="AssertionException"/>.
126                 /// </summary>
127                 /// <param name="condition">The evaluated condition</param>
128                 static public void IsFalse(bool condition) 
129                 {
130                         Assert.IsFalse(condition, string.Empty, null);
131                 }
132
133                 /// <summary>
134                 /// Verifies that two doubles are equal considering a delta. If the
135                 /// expected value is infinity then the delta value is ignored. If 
136                 /// they are not equals then an <see cref="AssertionException"/> is
137                 /// thrown.
138                 /// </summary>
139                 /// <param name="expected">The expected value</param>
140                 /// <param name="actual">The actual value</param>
141                 /// <param name="delta">The maximum acceptable difference between the
142                 /// the expected and the actual</param>
143                 /// <param name="message">The message that will be printed on failure</param>
144                 /// <param name="args">Arguments to be used in formatting the message</param>
145                 static public void AreEqual(double expected, 
146                         double actual, double delta, string message, params object[] args) 
147                 {
148                         ++counter;
149                         // handle infinity specially since subtracting two infinite values gives 
150                         // NaN and the following test fails. mono also needs NaN to be handled
151                         // specially although ms.net could use either method.
152                         if (double.IsInfinity(expected) || double.IsNaN(expected) || double.IsNaN(actual))
153                         {
154                                 if (!(expected == actual))
155                                         Assert.FailNotEquals(expected, actual, message, args);
156                         }
157                         else if (!(Math.Abs(expected-actual) <= delta))
158                                 Assert.FailNotEquals(expected, actual, message, args);
159                 }
160
161                 /// <summary>
162                 /// Verifies that two doubles are equal considering a delta. If the
163                 /// expected value is infinity then the delta value is ignored. If 
164                 /// they are not equals then an <see cref="AssertionException"/> is
165                 /// thrown.
166                 /// </summary>
167                 /// <param name="expected">The expected value</param>
168                 /// <param name="actual">The actual value</param>
169                 /// <param name="delta">The maximum acceptable difference between the
170                 /// the expected and the actual</param>
171                 /// <param name="message">The message that will be printed on failure</param>
172                 static public void AreEqual(double expected, 
173                         double actual, double delta, string message) 
174                 {
175                         Assert.AreEqual( expected, actual, delta, message, null );
176                 }
177
178                 /// <summary>
179                 /// Verifies that two doubles are equal considering a delta. If the
180                 /// expected value is infinity then the delta value is ignored. If 
181                 /// they are not equals then an <see cref="AssertionException"/> is
182                 /// thrown.
183                 /// </summary>
184                 /// <param name="expected">The expected value</param>
185                 /// <param name="actual">The actual value</param>
186                 /// <param name="delta">The maximum acceptable difference between the
187                 /// the expected and the actual</param>
188                 static public void AreEqual(double expected, double actual, double delta) 
189                 {
190                         Assert.AreEqual(expected, actual, delta, string.Empty, null);
191                 }
192
193                 /// <summary>
194                 /// Verifies that two floats are equal considering a delta. If the
195                 /// expected value is infinity then the delta value is ignored. If 
196                 /// they are not equals then an <see cref="AssertionException"/> is
197                 /// thrown.
198                 /// </summary>
199                 /// <param name="expected">The expected value</param>
200                 /// <param name="actual">The actual value</param>
201                 /// <param name="delta">The maximum acceptable difference between the
202                 /// the expected and the actual</param>
203                 /// <param name="message">The message printed out upon failure</param>
204                 /// <param name="args">Arguments to be used in formatting the message</param>
205                 static public void AreEqual(float expected, 
206                         float actual, float delta, string message, params object[] args) 
207                 {
208                         ++counter;
209                         // handle infinity specially since subtracting two infinite values gives 
210                         // NaN and the following test fails. mono also needs NaN to be handled
211                         // specially although ms.net could use either method.
212                         if (float.IsInfinity(expected) || float.IsNaN(expected) || float.IsNaN(actual)) 
213                         {
214                                 if (!(expected == actual))
215                                         Assert.FailNotEquals(expected, actual, message, args);
216                         } 
217                         else if (!(Math.Abs(expected-actual) <= delta))
218                                 Assert.FailNotEquals(expected, actual, message, args);
219                 }
220
221                 /// <summary>
222                 /// Verifies that two floats are equal considering a delta. If the
223                 /// expected value is infinity then the delta value is ignored. If 
224                 /// they are not equals then an <see cref="AssertionException"/> is
225                 /// thrown.
226                 /// </summary>
227                 /// <param name="expected">The expected value</param>
228                 /// <param name="actual">The actual value</param>
229                 /// <param name="delta">The maximum acceptable difference between the
230                 /// the expected and the actual</param>
231                 /// <param name="message">The message printed out upon failure</param>
232                 static public void AreEqual(float expected, float actual, float delta, string message) 
233                 {
234                         Assert.AreEqual(expected, actual, delta, message, null);
235                 }
236
237                 /// <summary>
238                 /// Verifies that two floats are equal considering a delta. If the
239                 /// expected value is infinity then the delta value is ignored. If 
240                 /// they are not equals then an <see cref="AssertionException"/> is
241                 /// thrown.
242                 /// </summary>
243                 /// <param name="expected">The expected value</param>
244                 /// <param name="actual">The actual value</param>
245                 /// <param name="delta">The maximum acceptable difference between the
246                 /// the expected and the actual</param>
247                 static public void AreEqual(float expected, float actual, float delta) 
248                 {
249                         Assert.AreEqual(expected, actual, delta, string.Empty, null);
250                 }
251
252                 /// <summary>
253                 /// Verifies that two decimals are equal. If 
254                 /// they are not equals then an <see cref="AssertionException"/> is
255                 /// thrown.
256                 /// </summary>
257                 /// <param name="expected">The expected value</param>
258                 /// <param name="actual">The actual value</param>
259                 /// <param name="message">The message printed out upon failure</param>
260                 /// <param name="args">Arguments to be used in formatting the message</param>
261                 static public void AreEqual(decimal expected, decimal actual, string message, params object[] args) 
262                 {
263                         ++counter;
264                         if(!(expected == actual))
265                                 Assert.FailNotEquals(expected, actual, message, args);
266                 }
267
268                 /// <summary>
269                 /// Verifies that two decimals are equal. If 
270                 /// they are not equals then an <see cref="AssertionException"/> is
271                 /// thrown.
272                 /// </summary>
273                 /// <param name="expected">The expected value</param>
274                 /// <param name="actual">The actual value</param>
275                 /// <param name="message">The message printed out upon failure</param>
276                 static public void AreEqual(decimal expected, decimal actual, string message) 
277                 {
278                         Assert.AreEqual(expected, actual, message, null);
279                 }
280                 
281                 /// <summary>
282                 /// Verifies that two decimals are equal. If 
283                 /// they are not equals then an <see cref="AssertionException"/> is
284                 /// thrown.
285                 /// </summary>
286                 /// <param name="expected">The expected value</param>
287                 /// <param name="actual">The actual value</param>
288                 static public void AreEqual(decimal expected, decimal actual) 
289                 {
290                         Assert.AreEqual(expected, actual, string.Empty, null);
291                 }
292                 
293                 /// <summary>
294                 /// Verifies that two ints are equal. If 
295                 /// they are not equals then an <see cref="AssertionException"/> is
296                 /// thrown.
297                 /// </summary>
298                 /// <param name="expected">The expected value</param>
299                 /// <param name="actual">The actual value</param>
300                 /// <param name="message">The message printed out upon failure</param>
301                 /// <param name="args">Arguments to be used in formatting the message</param>
302                 static public void AreEqual(int expected, int actual, string message, params object[] args)
303                 {
304                         ++counter;
305                         if(!(expected == actual))
306                                 Assert.FailNotEquals(expected, actual, message, args);
307                 }
308
309                 /// <summary>
310                 /// Verifies that two ints are equal. If 
311                 /// they are not equals then an <see cref="AssertionException"/> is
312                 /// thrown.
313                 /// </summary>
314                 /// <param name="expected">The expected value</param>
315                 /// <param name="actual">The actual value</param>
316                 /// <param name="message">The message printed out upon failure</param>
317                 static public void AreEqual(int expected, int actual, string message) 
318                 {
319                         Assert.AreEqual(expected, actual, message, null);
320                 }
321
322                 /// <summary>
323                 /// Verifies that two ints are equal. If 
324                 /// they are not equals then an <see cref="AssertionException"/> is
325                 /// thrown.
326                 /// </summary>
327                 /// <param name="expected">The expected value</param>
328                 /// <param name="actual">The actual value</param>
329                 static public void AreEqual(int expected, int actual) 
330                 {
331                         Assert.AreEqual(expected, actual, string.Empty, null);
332                 }
333
334                 /// <summary>
335                 /// Verifies that two arrays are equal. If they are not,
336                 /// then an <see cref="AssertionException"/> is thrown.
337                 /// </summary>
338                 /// <param name="expected">The expected value</param>
339                 /// <param name="actual">The actual value</param>
340                 /// <param name="message">The message printed out upon failure</param>
341                 /// <param name="args">Arguments to be used in formatting the message</param>
342                 static public void AreEqual( System.Array expected, System.Array actual, string message, params object[] args )
343                 {
344                         ++counter;
345
346                         if ( expected == null && actual == null ) return;
347
348                         if ( expected == null || actual == null )
349                                 Assert.FailNotEquals( expected, actual, message, args );
350
351                         if ( expected.Rank != actual.Rank )
352                                 Assert.FailNotEquals( expected, actual, message, args );
353
354                         if ( expected.Rank != 1 )
355                                 Assert.Fail( "Multi-dimension array comparison is not supported" );
356
357                         int iLength = Math.Min( expected.Length, actual.Length );
358                         for( int i = 0; i < iLength; i++ )
359                                 if ( !ObjectsEqual( expected.GetValue( i ), actual.GetValue( i ) ) )
360                                 {
361                                         Assert.FailArraysNotEqual(i, expected, actual, message, args );
362                                 }
363
364                         if ( expected.Length != actual.Length )
365                                 Assert.FailArraysNotEqual( iLength, expected, actual, message, args );
366                                 
367                         return;
368                 }
369                 
370                 /// <summary>
371                 /// Verifies that two arrays are equal. If they are not,
372                 /// then an <see cref="AssertionException"/> is thrown.
373                 /// </summary>
374                 /// <param name="expected">The expected value</param>
375                 /// <param name="actual">The actual value</param>
376                 /// <param name="message">The message printed out upon failure</param>
377                 static public void AreEqual( System.Array expected, System.Array actual, string message )
378                 {
379                         Assert.AreEqual( expected, actual, message, null );
380                 }       
381                 
382                 /// <summary>
383                 /// Verifies that two arrays are equal. If they are not,
384                 /// then an <see cref="AssertionException"/> is thrown.
385                 /// </summary>
386                 /// <param name="expected">The expected value</param>
387                 /// <param name="actual">The actual value</param>
388                 static public void AreEqual( System.Array expected, System.Array actual )
389                 {
390                         Assert.AreEqual( expected, actual, string.Empty, null );
391                 }       
392                 
393                 /// <summary>
394                 /// Verifies that two objects are equal.  Two objects are considered
395                 /// equal if both are null, or if both have the same value.  All
396                 /// non-numeric types are compared by using the <c>Equals</c> method.
397                 /// Arrays are compared by comparing each element using the same rules.
398                 /// If they are not equal an <see cref="AssertionException"/> is thrown.
399                 /// </summary>
400                 /// <param name="expected">The value that is expected</param>
401                 /// <param name="actual">The actual value</param>
402                 /// <param name="message">The message to display if objects are not equal</param>
403                 /// <param name="args">Arguments to be used in formatting the message</param>
404                 static public void AreEqual(Object expected, Object actual, string message, params object[] args)
405                 {
406                         if ( expected == null && actual == null ) return;
407                         if ( expected == null || actual == null )
408                                 Assert.FailNotEquals( expected, actual, message, args );
409
410                         // FOr now, dynamically call array assertion if necessary. Try to move
411                         // this into the ObjectsEqual method later on.
412                         if ( expected.GetType().IsArray && actual.GetType().IsArray )
413                                 Assert.AreEqual( (System.Array)expected, (System.Array)actual, message, args );
414                                         else
415                         {
416                                 ++counter;
417
418                                 if ( !ObjectsEqual( expected, actual ) )
419                                         Assert.FailNotEquals( expected, actual, message, args );
420                         }
421                 }
422
423                 /// <summary>
424                 /// Verifies that two objects are equal.  Two objects are considered
425                 /// equal if both are null, or if both have the same value.  All
426                 /// non-numeric types are compared by using the <c>Equals</c> method.
427                 /// If they are not equal an <see cref="AssertionException"/> is thrown.
428                 /// </summary>
429                 /// <param name="expected">The value that is expected</param>
430                 /// <param name="actual">The actual value</param>
431                 /// <param name="message">The message to display if objects are not equal</param>
432                 static public void AreEqual(Object expected, Object actual, string message) 
433                 {
434                         Assert.AreEqual(expected, actual, message, null);
435                 }
436
437                 /// <summary>
438                 /// Verifies that two objects are equal.  Two objects are considered
439                 /// equal if both are null, or if both have the same value.  All
440                 /// non-numeric types are compared by using the <c>Equals</c> method.
441                 /// If they are not equal an <see cref="AssertionException"/> is thrown.
442                 /// </summary>
443                 /// <param name="expected">The value that is expected</param>
444                 /// <param name="actual">The actual value</param>
445                 static public void AreEqual(Object expected, Object actual) 
446                 {
447                         Assert.AreEqual(expected, actual, string.Empty, null);
448                 }
449
450                 /// <summary>
451                 /// The Equals method throws an AssertionException. This is done 
452                 /// to make sure there is no mistake by calling this function.
453                 /// </summary>
454                 /// <param name="a"></param>
455                 /// <param name="b"></param>
456                 [EditorBrowsable(EditorBrowsableState.Never)]
457                 public static new bool Equals(object a, object b)
458                 {
459                         throw new AssertionException("Assert.Equals should not be used for Assertions");
460                 }
461
462                 /// <summary>
463                 /// override the default ReferenceEquals to throw an AssertionException. This 
464                 /// implementation makes sure there is no mistake in calling this function 
465                 /// as part of Assert. 
466                 /// </summary>
467                 /// <param name="a"></param>
468                 /// <param name="b"></param>
469                 public static new void ReferenceEquals(object a, object b)
470                 {
471                         throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions");
472                 }
473                                 
474                 /// <summary>
475                 /// Checks the type of the object, returning true if
476                 /// the object is a numeric type.
477                 /// </summary>
478                 /// <param name="obj">The object to check</param>
479                 /// <returns>true if the object is a numeric type</returns>
480                 static protected bool IsNumericType( Object obj )
481                 {
482                         if( null != obj )
483                         {
484                                 if( obj is byte    ) return true;
485                                 if( obj is sbyte   ) return true;
486                                 if( obj is decimal ) return true;
487                                 if( obj is double  ) return true;
488                                 if( obj is float   ) return true;
489                                 if( obj is int     ) return true;
490                                 if( obj is uint    ) return true;
491                                 if( obj is long    ) return true;
492                                 if( obj is short   ) return true;
493                                 if( obj is ushort  ) return true;
494
495                                 if( obj is System.Byte    ) return true;
496                                 if( obj is System.SByte   ) return true;
497                                 if( obj is System.Decimal ) return true;
498                                 if( obj is System.Double  ) return true;
499                                 if( obj is System.Single  ) return true;
500                                 if( obj is System.Int32   ) return true;
501                                 if( obj is System.UInt32  ) return true;
502                                 if( obj is System.Int64   ) return true;
503                                 if( obj is System.UInt64  ) return true;
504                                 if( obj is System.Int16   ) return true;
505                                 if( obj is System.UInt16  ) return true;
506                         }
507                         return false;
508                 }
509
510                 /// <summary>
511                 /// Used to compare two objects.  Two nulls are equal and null
512                 /// is not equal to non-null. Comparisons between the same
513                 /// numeric types are fine (Int32 to Int32, or Int64 to Int64),
514                 /// but the Equals method fails across different types so we
515                 /// use <c>ToString</c> and compare the results.
516                 /// </summary>
517                 /// <param name="expected"></param>
518                 /// <param name="actual"></param>
519                 /// <returns></returns>
520                 static protected bool ObjectsEqual( Object expected, Object actual )
521                 {
522                         if ( expected == null && actual == null ) return true;
523                         if ( expected == null || actual == null ) return false;
524
525                         if( IsNumericType( expected )  &&
526                                 IsNumericType( actual ) )
527                         {
528                                 //
529                                 // Convert to strings and compare result to avoid
530                                 // issues with different types that have the same
531                                 // value
532                                 //
533                                 string sExpected = expected.ToString();
534                                 string sActual   = actual.ToString();
535                                 return sExpected.Equals( sActual );
536                         }
537                         return expected.Equals(actual);
538                 }
539     
540                 /// <summary>
541                 /// Verifies that the object that is passed in is not equal to <code>null</code>
542                 /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
543                 /// is thrown.
544                 /// </summary>
545                 /// <param name="anObject">The object that is to be tested</param>
546                 /// <param name="message">The message to be printed when the object is null</param>
547                 /// <param name="args">Arguments to be used in formatting the message</param>
548                 static public void IsNotNull(Object anObject, string message, params object[] args) 
549                 {
550                         Assert.IsTrue(anObject != null, message, args); 
551                 }
552
553                 /// <summary>
554                 /// Verifies that the object that is passed in is not equal to <code>null</code>
555                 /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
556                 /// is thrown.
557                 /// </summary>
558                 /// <param name="anObject">The object that is to be tested</param>
559                 static public void IsNotNull(Object anObject, string message) 
560                 {
561                         Assert.IsNotNull(anObject, message, null);
562                 }
563     
564                 /// <summary>
565                 /// Verifies that the object that is passed in is not equal to <code>null</code>
566                 /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
567                 /// is thrown.
568                 /// </summary>
569                 /// <param name="anObject">The object that is to be tested</param>
570                 static public void IsNotNull(Object anObject) 
571                 {
572                         Assert.IsNotNull(anObject, string.Empty, null);
573                 }
574     
575                     
576                 /// <summary>
577                 /// Verifies that the object that is passed in is equal to <code>null</code>
578                 /// If the object is <code>null</code> then an <see cref="AssertionException"/>
579                 /// is thrown.
580                 /// </summary>
581                 /// <param name="anObject">The object that is to be tested</param>
582                 /// <param name="message">The message to be printed when the object is not null</param>
583                 /// <param name="args">Arguments to be used in formatting the message</param>
584                 static public void IsNull(Object anObject, string message, params object[] args) 
585                 {
586                         Assert.IsTrue(anObject == null, message, args); 
587                 }
588
589                 /// <summary>
590                 /// Verifies that the object that is passed in is equal to <code>null</code>
591                 /// If the object is <code>null</code> then an <see cref="AssertionException"/>
592                 /// is thrown.
593                 /// </summary>
594                 /// <param name="anObject">The object that is to be tested</param>
595                 static public void IsNull(Object anObject, string message) 
596                 {
597                         Assert.IsNull(anObject, message, null);
598                 }
599     
600                 /// <summary>
601                 /// Verifies that the object that is passed in is equal to <code>null</code>
602                 /// If the object is <code>null</code> then an <see cref="AssertionException"/>
603                 /// is thrown.
604                 /// </summary>
605                 /// <param name="anObject">The object that is to be tested</param>
606                 static public void IsNull(Object anObject) 
607                 {
608                         Assert.IsNull(anObject, string.Empty, null);
609                 }
610     
611     
612                 /// <summary>
613                 /// Asserts that two objects refer to the same object. If they
614                 /// are not the same an <see cref="AssertionException"/> is thrown.
615                 /// </summary>
616                 /// <param name="expected">The expected object</param>
617                 /// <param name="actual">The actual object</param>
618                 /// <param name="message">The message to be printed when the two objects are not the same object.</param>
619                 /// <param name="args">Arguments to be used in formatting the message</param>
620                 static public void AreSame(Object expected, Object actual, string message, params object[] args)
621                 {
622                         ++counter;
623                         if (object.ReferenceEquals(expected, actual)) return;
624
625                         Assert.FailNotSame(expected, actual, message, args);
626                 }
627
628                 /// <summary>
629                 /// Asserts that two objects refer to the same object. If they
630                 /// are not the same an <see cref="AssertionException"/> is thrown.
631                 /// </summary>
632                 /// <param name="expected">The expected object</param>
633                 /// <param name="actual">The actual object</param>
634                 /// <param name="message">The message to be printed when the object is null</param>
635                 static public void AreSame(Object expected, Object actual, string message) 
636                 {
637                         Assert.AreSame(expected, actual, message, null);
638                 }
639    
640                 /// <summary>
641                 /// Asserts that two objects refer to the same object. If they
642                 /// are not the same an <see cref="AssertionException"/> is thrown.
643                 /// </summary>
644                 /// <param name="expected">The expected object</param>
645                 /// <param name="actual">The actual object</param>
646                 static public void AreSame(Object expected, Object actual) 
647                 {
648                         Assert.AreSame(expected, actual, string.Empty, null);
649                 }
650    
651                 /// <summary>
652                 /// Throws an <see cref="AssertionException"/> with the message and arguments 
653                 /// that are passed in. This is used by the other Assert functions. 
654                 /// </summary>
655                 /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
656                 /// <param name="args">Arguments to be used in formatting the message</param>
657                 static public void Fail(string message, params object[] args ) 
658                 {
659                         if (message == null) message = string.Empty;
660                         else if ( args != null && args.Length > 0 )
661                                 message = string.Format( message, args );
662
663                         throw new AssertionException(message);
664                 }
665
666                 /// <summary>
667                 /// Throws an <see cref="AssertionException"/> with the message that is 
668                 /// passed in. This is used by the other Assert functions. 
669                 /// </summary>
670                 /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
671                 static public void Fail(string message) 
672                 {
673                         Assert.Fail(message, null);
674                 }
675     
676                 /// <summary>
677                 /// Throws an <see cref="AssertionException"/>. 
678                 /// This is used by the other Assert functions. 
679                 /// </summary>
680                 static public void Fail() 
681                 {
682                         Assert.Fail(string.Empty, null);
683                 }
684
685                 /// <summary>
686                 /// Throws an <see cref="IgnoreException"/> with the message and arguments 
687                 /// that are passed in.  This causes the test to be reported as ignored.
688                 /// </summary>
689                 /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
690                 /// <param name="args">Arguments to be used in formatting the message</param>
691                 static public void Ignore( string message, object[] args )
692                 {
693                         if (message == null) message = string.Empty;
694                         else if ( args != null && args.Length > 0 )
695                                 message = string.Format( message, args );
696
697                         throw new IgnoreException(message);
698                 }
699
700                 /// <summary>
701                 /// Throws an <see cref="IgnoreException"/> with the message that is 
702                 /// passed in. This causes the test to be reported as ignored. 
703                 /// </summary>
704                 /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
705                 static public void Ignore( string message )
706                 {
707                         Assert.Ignore( message, null );
708                 }
709     
710                 /// <summary>
711                 /// Throws an <see cref="IgnoreException"/>. 
712                 /// This causes the test to be reported as ignored. 
713                 /// </summary>
714                 /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
715                 static public void Ignore()
716                 {
717                         Assert.Ignore( string.Empty, null );
718                 }
719     
720                 /// <summary>
721                 /// This method is called when two objects have been compared and found to be
722                 /// different. This prints a nice message to the screen. 
723                 /// </summary>
724                 /// <param name="message">The message that is to be printed prior to the comparison failure</param>
725                 /// <param name="expected">The expected object</param>
726                 /// <param name="actual">The actual object</param>
727                 /// <param name="args">Arguments to be used in formatting the message</param>
728                 static protected void FailNotEquals(Object expected, Object actual, string message,
729                         params object[] args) 
730                 {
731                         Assert.Fail( 
732                                 AssertionFailureMessage.FormatMessageForFailNotEquals( 
733                                 expected, 
734                                 actual, 
735                                 message,
736                                 args));
737                 }
738     
739                 /// <summary>
740                 /// This method is called when two arrays have been compared and found to be
741                 /// different. This prints a nice message to the screen. 
742                 /// </summary>
743                 /// <param name="index">The index at which the failure occured</param>
744                 /// <param name="expected">The expected array</param>
745                 /// <param name="actual">The actual array</param>
746                 /// <param name="message">The message that is to be printed prior to the comparison failure</param>
747                 /// <param name="args">Arguments to be used in formatting the message</param>
748                 static protected void FailArraysNotEqual(int index, Array expected, Array actual, 
749                         string message, params object[] args) 
750                 {
751                         Assert.Fail( 
752                                 AssertionFailureMessage.FormatMessageForFailArraysNotEqual( 
753                                 index,
754                                 expected, 
755                                 actual, 
756                                 message,
757                                 args));
758                 }
759     
760                 /// <summary>
761                 ///  This method is called when the two objects are not the same. 
762                 /// </summary>
763                 /// <param name="message">The message to be printed on the screen</param>
764                 /// <param name="expected">The expected object</param>
765                 /// <param name="actual">The actual object</param>
766                 /// <param name="args">Arguments to be used in formatting the message</param>
767                 static protected void FailNotSame(Object expected, Object actual, string message, params object[] args) 
768                 {
769                         string formatted = string.Empty;
770                         if ( message != null )
771                         {
772                                 if (args != null && args.Length > 0 )
773                                         formatted = string.Format( message+" ", args );
774                                 else
775                                         formatted = message+" ";
776                         }
777
778                         Assert.Fail(formatted+"expected same");
779                 }
780         }
781 }