1 // ****************************************************************
2 // Copyright 2007, 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/?p=license&r=2.4
5 // ****************************************************************
6 
7 using System;
8 using System.Collections;
9 using NUnit.Framework.SyntaxHelpers;
10 using NUnit.Framework.Constraints;
11 
12 namespace NUnit.Framework
13 {
14 	/// <summary>
15 	/// AssertionHelper is an optional base class for user tests,
16 	/// allowing the use of shorter names for constraints and
17 	/// asserts and avoiding conflict with the definition of
18 	/// <see cref="Is"/>, from which it inherits much of its
19 	/// behavior, in certain mock object frameworks.
20 	/// </summary>
21 	public class AssertionHelper : ConstraintBuilder
22 	{
23 		#region Expect
24 		/// <summary>
25 		/// Apply a constraint to an actual value, succeeding if the constraint
26 		/// is satisfied and throwing an assertion exception on failure. Works
27 		/// identically to <see cref="NUnit.Framework.Assert.That(object, Constraint)"/>
28 		/// </summary>
29 		/// <param name="constraint">A Constraint to be applied</param>
30 		/// <param name="actual">The actual value to test</param>
Expect( object actual, Constraint constraint )31 		static public void Expect( object actual, Constraint constraint )
32 		{
33 			Assert.That( actual, constraint, null, null );
34 		}
35 
36 		/// <summary>
37 		/// Apply a constraint to an actual value, succeeding if the constraint
38 		/// is satisfied and throwing an assertion exception on failure. Works
39 		/// identically to <see cref="NUnit.Framework.Assert.That(object, Constraint, string)"/>
40 		/// </summary>
41 		/// <param name="constraint">A Constraint to be applied</param>
42 		/// <param name="actual">The actual value to test</param>
43 		/// <param name="message">The message that will be displayed on failure</param>
Expect( object actual, Constraint constraint, string message )44 		static public void Expect( object actual, Constraint constraint, string message )
45 		{
46 			Assert.That( actual, constraint, message, null );
47 		}
48 
49 		/// <summary>
50 		/// Apply a constraint to an actual value, succeeding if the constraint
51 		/// is satisfied and throwing an assertion exception on failure. Works
52 		/// identically to <see cref="NUnit.Framework.Assert.That(object, Constraint, string, object[])"/>
53 		/// </summary>
54 		/// <param name="constraint">A Constraint to be applied</param>
55 		/// <param name="actual">The actual value to test</param>
56 		/// <param name="message">The message that will be displayed on failure</param>
57 		/// <param name="args">Arguments to be used in formatting the message</param>
Expect( object actual, Constraint constraint, string message, params object[] args )58 		static public void Expect( object actual, Constraint constraint, string message, params object[] args )
59 		{
60 			Assert.That( actual, constraint, message, args );
61 		}
62 
63 		/// <summary>
64 		/// Asserts that a condition is true. If the condition is false the method throws
65 		/// an <see cref="AssertionException"/>. Works Identically to
66         /// <see cref="Assert.That(bool, string, object[])"/>.
67 		/// </summary>
68 		/// <param name="condition">The evaluated condition</param>
69 		/// <param name="message">The message to display if the condition is false</param>
70 		/// <param name="args">Arguments to be used in formatting the message</param>
Expect(bool condition, string message, params object[] args)71 		static public void Expect(bool condition, string message, params object[] args)
72 		{
73 			Assert.That(condition, Is.True, message, args);
74 		}
75 
76 		/// <summary>
77 		/// Asserts that a condition is true. If the condition is false the method throws
78 		/// an <see cref="AssertionException"/>. Works Identically to
79         /// <see cref="Assert.That(bool, string)"/>.
80 		/// </summary>
81 		/// <param name="condition">The evaluated condition</param>
82 		/// <param name="message">The message to display if the condition is false</param>
Expect(bool condition, string message)83 		static public void Expect(bool condition, string message)
84 		{
85 			Assert.That(condition, Is.True, 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"/>. Works Identically to <see cref="Assert.That(bool)"/>.
91 		/// </summary>
92 		/// <param name="condition">The evaluated condition</param>
Expect(bool condition)93 		static public void Expect(bool condition)
94 		{
95 			Assert.That(condition, Is.True, null, null);
96 		}
97 		#endregion
98 
99 		#region Map
100 		/// <summary>
101 		/// Returns a ListMapper based on a collection.
102 		/// </summary>
103 		/// <param name="original">The original collection</param>
104 		/// <returns></returns>
Map( ICollection original )105 		public ListMapper Map( ICollection original )
106 		{
107 			return new ListMapper( original );
108 		}
109 		#endregion
110 	}
111 }
112