[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Assert / AssertionHelper.cs
1 // ***********************************************************************
2 // Copyright (c) 2007 Charlie Poole
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System.Collections;
30 using NUnit.Framework.Constraints;
31
32 namespace NUnit.Framework
33 {
34     /// <summary>
35     /// AssertionHelper is an optional base class for user tests,
36     /// allowing the use of shorter ids for constraints and
37     /// asserts and avoiding conflict with the definition of 
38     /// <see cref="Is"/>, from which it inherits much of its
39     /// behavior, in certain mock object frameworks.
40     /// </summary>
41     public class AssertionHelper : ConstraintFactory
42     {
43         #region Expect
44
45         #region Boolean
46
47         /// <summary>
48         /// Asserts that a condition is true. If the condition is false the method throws
49         /// an <see cref="AssertionException"/>. Works Identically to 
50         /// <see cref="Assert.That(bool, string, object[])"/>.
51         /// </summary> 
52         /// <param name="condition">The evaluated condition</param>
53         /// <param name="message">The message to display if the condition is false</param>
54         /// <param name="args">Arguments to be used in formatting the message</param>
55         public void Expect(bool condition, string message, params object[] args)
56         {
57             Assert.That(condition, Is.True, message, args);
58         }
59
60         /// <summary>
61         /// Asserts that a condition is true. If the condition is false the method throws
62         /// an <see cref="AssertionException"/>. Works Identically to <see cref="Assert.That(bool)"/>.
63         /// </summary>
64         /// <param name="condition">The evaluated condition</param>
65         public void Expect(bool condition)
66         {
67             Assert.That(condition, Is.True, null, null);
68         }
69
70         #endregion
71
72         #region ActualValueDelegate
73         /// <summary>
74         /// Apply a constraint to an actual value, succeeding if the constraint
75         /// is satisfied and throwing an assertion exception on failure.
76         /// </summary>
77         /// <param name="expr">A Constraint expression to be applied</param>
78         /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
79         public void Expect<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr)
80         {
81             Assert.That(del, expr.Resolve(), null, null);
82         }
83
84         /// <summary>
85         /// Apply a constraint to an actual value, succeeding if the constraint
86         /// is satisfied and throwing an assertion exception on failure.
87         /// </summary>
88         /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
89         /// <param name="expr">A Constraint expression to be applied</param>
90         /// <param name="message">The message that will be displayed on failure</param>
91         /// <param name="args">Arguments to be used in formatting the message</param>
92         public void Expect<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, string message, params object[] args)
93         {
94             Assert.That(del, expr, message, args);
95         }
96         #endregion
97
98         #region TestDelegate
99
100         /// <summary>
101         /// Asserts that the code represented by a delegate throws an exception
102         /// that satisfies the constraint provided.
103         /// </summary>
104         /// <param name="code">A TestDelegate to be executed</param>
105         /// <param name="constraint">A ThrowsConstraint used in the test</param>
106         public void Expect(TestDelegate code, IResolveConstraint constraint)
107         {
108             Assert.That((object)code, constraint);
109         }
110
111         #endregion
112
113         #endregion
114
115         #region Expect<TActual>
116
117         /// <summary>
118         /// Apply a constraint to an actual value, succeeding if the constraint
119         /// is satisfied and throwing an assertion exception on failure.
120         /// </summary>
121         /// <param name="expression">A Constraint to be applied</param>
122         /// <param name="actual">The actual value to test</param>
123         static public void Expect<TActual>(TActual actual, IResolveConstraint expression)
124         {
125             Assert.That(actual, expression, null, null);
126         }
127
128         /// <summary>
129         /// Apply a constraint to an actual value, succeeding if the constraint
130         /// is satisfied and throwing an assertion exception on failure.
131         /// </summary>
132         /// <param name="expression">A Constraint expression to be applied</param>
133         /// <param name="actual">The actual value to test</param>
134         /// <param name="message">The message that will be displayed on failure</param>
135         /// <param name="args">Arguments to be used in formatting the message</param>
136         static public void Expect<TActual>(TActual actual, IResolveConstraint expression, string message, params object[] args)
137         {
138             Assert.That(actual, expression, message, args);
139         }
140
141         #endregion
142
143         #region Map
144         /// <summary>
145         /// Returns a ListMapper based on a collection.
146         /// </summary>
147         /// <param name="original">The original collection</param>
148         /// <returns></returns>
149         public ListMapper Map( ICollection original )
150         {
151             return new ListMapper( original );
152         }
153         #endregion
154     }
155 }