1 // ****************************************************************
\r
2 // Copyright 2007, Charlie Poole
\r
3 // This is free software licensed under the NUnit license. You may
\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
\r
5 // ****************************************************************
\r
8 using System.Collections;
\r
9 using NUnit.Framework.SyntaxHelpers;
\r
10 using NUnit.Framework.Constraints;
\r
12 namespace NUnit.Framework
\r
15 /// AssertionHelper is an optional base class for user tests,
\r
16 /// allowing the use of shorter names for constraints and
\r
17 /// asserts and avoiding conflict with the definition of
\r
18 /// <see cref="Is"/>, from which it inherits much of its
\r
19 /// behavior, in certain mock object frameworks.
\r
21 public class AssertionHelper : ConstraintBuilder
\r
25 /// Apply a constraint to an actual value, succeeding if the constraint
\r
26 /// is satisfied and throwing an assertion exception on failure. Works
\r
27 /// identically to <see cref="NUnit.Framework.Assert.That(object, Constraint)"/>
\r
29 /// <param name="constraint">A Constraint to be applied</param>
\r
30 /// <param name="actual">The actual value to test</param>
\r
31 static public void Expect( object actual, Constraint constraint )
\r
33 Assert.That( actual, constraint, null, null );
\r
37 /// Apply a constraint to an actual value, succeeding if the constraint
\r
38 /// is satisfied and throwing an assertion exception on failure. Works
\r
39 /// identically to <see cref="NUnit.Framework.Assert.That(object, Constraint, string)"/>
\r
41 /// <param name="constraint">A Constraint to be applied</param>
\r
42 /// <param name="actual">The actual value to test</param>
\r
43 /// <param name="message">The message that will be displayed on failure</param>
\r
44 static public void Expect( object actual, Constraint constraint, string message )
\r
46 Assert.That( actual, constraint, message, null );
\r
50 /// Apply a constraint to an actual value, succeeding if the constraint
\r
51 /// is satisfied and throwing an assertion exception on failure. Works
\r
52 /// identically to <see cref="NUnit.Framework.Assert.That(object, Constraint, string, object[])"/>
\r
54 /// <param name="constraint">A Constraint to be applied</param>
\r
55 /// <param name="actual">The actual value to test</param>
\r
56 /// <param name="message">The message that will be displayed on failure</param>
\r
57 /// <param name="args">Arguments to be used in formatting the message</param>
\r
58 static public void Expect( object actual, Constraint constraint, string message, params object[] args )
\r
60 Assert.That( actual, constraint, message, args );
\r
64 /// Asserts that a condition is true. If the condition is false the method throws
\r
65 /// an <see cref="AssertionException"/>. Works Identically to
\r
66 /// <see cref="Assert.That(bool, string, object[])"/>.
\r
68 /// <param name="condition">The evaluated condition</param>
\r
69 /// <param name="message">The message to display if the condition is false</param>
\r
70 /// <param name="args">Arguments to be used in formatting the message</param>
\r
71 static public void Expect(bool condition, string message, params object[] args)
\r
73 Assert.That(condition, Is.True, message, args);
\r
77 /// Asserts that a condition is true. If the condition is false the method throws
\r
78 /// an <see cref="AssertionException"/>. Works Identically to
\r
79 /// <see cref="Assert.That(bool, string)"/>.
\r
81 /// <param name="condition">The evaluated condition</param>
\r
82 /// <param name="message">The message to display if the condition is false</param>
\r
83 static public void Expect(bool condition, string message)
\r
85 Assert.That(condition, Is.True, message, null);
\r
89 /// Asserts that a condition is true. If the condition is false the method throws
\r
90 /// an <see cref="AssertionException"/>. Works Identically to <see cref="Assert.That(bool)"/>.
\r
92 /// <param name="condition">The evaluated condition</param>
\r
93 static public void Expect(bool condition)
\r
95 Assert.That(condition, Is.True, null, null);
\r
101 /// Returns a ListMapper based on a collection.
\r
103 /// <param name="original">The original collection</param>
\r
104 /// <returns></returns>
\r
105 public ListMapper Map( ICollection original )
\r
107 return new ListMapper( original );
\r