[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Assert / Assert.That.cs
1 // ***********************************************************************
2 // Copyright (c) 2011 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
24 using System;
25 using NUnit.Framework.Constraints;
26 using NUnit.Framework.Internal;
27 using NUnit.Framework.TUnit;
28
29 namespace NUnit.Framework
30 {
31     public partial class Assert
32     {
33         #region Assert.That
34
35         #region Boolean
36
37         /// <summary>
38         /// Asserts that a condition is true. If the condition is false the method throws
39         /// an <see cref="AssertionException"/>.
40         /// </summary> 
41         /// <param name="condition">The evaluated condition</param>
42         /// <param name="message">The message to display if the condition is false</param>
43         /// <param name="args">Arguments to be used in formatting the message</param>
44         static public void That(bool condition, string message, params object[] args)
45         {
46             Assert.That(condition, Is.True, message, args);
47         }
48
49         /// <summary>
50         /// Asserts that a condition is true. If the condition is false the method throws
51         /// an <see cref="AssertionException"/>.
52         /// </summary>
53         /// <param name="condition">The evaluated condition</param>
54         static public void That(bool condition)
55         {
56             Assert.That(condition, Is.True, null, null);
57         }
58
59         #endregion
60
61         #region Lambda returning Boolean
62 #if !NET_2_0
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">A lambda that returns a Boolean</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 That(Func<bool> condition, string message, params object[] args)
71         {
72             Assert.That(condition.Invoke(), Is.True, message, args);
73         }
74
75         /// <summary>
76         /// Asserts that a condition is true. If the condition is false the method throws
77         /// an <see cref="AssertionException"/>.
78         /// </summary>
79         /// <param name="condition">A lambda that returns a Boolean</param>
80         static public void That(Func<bool> condition)
81         {
82             Assert.That(condition.Invoke(), Is.True, null, null);
83         }
84 #endif
85         #endregion
86
87         #region ActualValueDelegate
88
89         /// <summary>
90         /// Apply a constraint to an actual value, succeeding if the constraint
91         /// is satisfied and throwing an assertion exception on failure.
92         /// </summary>
93         /// <param name="expr">A Constraint expression to be applied</param>
94         /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
95         static public void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr)
96         {
97             Assert.That(del, expr.Resolve(), null, null);
98         }
99
100         /// <summary>
101         /// Apply a constraint to an actual value, succeeding if the constraint
102         /// is satisfied and throwing an assertion exception on failure.
103         /// </summary>
104         /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
105         /// <param name="expr">A Constraint expression to be applied</param>
106         /// <param name="message">The message that will be displayed on failure</param>
107         /// <param name="args">Arguments to be used in formatting the message</param>
108         static public void That<TActual>(ActualValueDelegate<TActual> del, IResolveConstraint expr, string message, params object[] args)
109         {
110             var constraint = expr.Resolve();
111             
112             IncrementAssertCount();
113             var result = constraint.ApplyTo(del);
114             if (!result.IsSuccess)
115             {
116                 MessageWriter writer = new TextMessageWriter(message, args);
117                 result.WriteMessageTo(writer);
118                 throw new AssertionException(writer.ToString());
119             }
120         }
121
122         #endregion
123
124         #region TestDelegate
125
126         /// <summary>
127         /// Asserts that the code represented by a delegate throws an exception
128         /// that satisfies the constraint provided.
129         /// </summary>
130         /// <param name="code">A TestDelegate to be executed</param>
131         /// <param name="constraint">A ThrowsConstraint used in the test</param>
132         static public void That(TestDelegate code, IResolveConstraint constraint)
133         {
134             Assert.That(code, constraint, null, null);
135         }
136
137         /// <summary>
138         /// Asserts that the code represented by a delegate throws an exception
139         /// that satisfies the constraint provided.
140         /// </summary>
141         /// <param name="code">A TestDelegate to be executed</param>
142         /// <param name="constraint">A ThrowsConstraint used in the test</param>
143         /// <param name="message">The message that will be displayed on failure</param>
144         /// <param name="args">Arguments to be used in formatting the message</param>
145         static public void That(TestDelegate code, IResolveConstraint constraint, string message, params string[] args)
146         {
147             Assert.That((object)code, constraint, message, args);
148         }
149
150         #endregion
151
152         #endregion
153
154         #region Assert.That<TActual>
155
156         /// <summary>
157         /// Apply a constraint to an actual value, succeeding if the constraint
158         /// is satisfied and throwing an assertion exception on failure.
159         /// </summary>
160         /// <param name="expression">A Constraint to be applied</param>
161         /// <param name="actual">The actual value to test</param>
162         static public void That<TActual>(TActual actual, IResolveConstraint expression)
163         {
164             Assert.That(actual, expression, null, null);
165         }
166
167         /// <summary>
168         /// Apply a constraint to an actual value, succeeding if the constraint
169         /// is satisfied and throwing an assertion exception on failure.
170         /// </summary>
171         /// <param name="expression">A Constraint expression to be applied</param>
172         /// <param name="actual">The actual value to test</param>
173         /// <param name="message">The message that will be displayed on failure</param>
174         /// <param name="args">Arguments to be used in formatting the message</param>
175         static public void That<TActual>(TActual actual, IResolveConstraint expression, string message, params object[] args)
176         {
177             var constraint = expression.Resolve();
178
179             IncrementAssertCount();
180             var result = constraint.ApplyTo(actual);
181             if (!result.IsSuccess)
182             {
183                 // [DuongNT][BEGIN]: Write console logs
184                 TLogger.Write(message);
185                 // [DuongNT][END]: Write console logs
186
187                 MessageWriter writer = new TextMessageWriter(message, args);
188                 result.WriteMessageTo(writer);
189                 throw new AssertionException(writer.ToString());
190             }
191         }
192
193         #endregion
194
195         #region Assert.ByVal
196
197         /// <summary>
198         /// Apply a constraint to an actual value, succeeding if the constraint
199         /// is satisfied and throwing an assertion exception on failure.
200         /// Used as a synonym for That in rare cases where a private setter 
201         /// causes a Visual Basic compilation error.
202         /// </summary>
203         /// <param name="expression">A Constraint to be applied</param>
204         /// <param name="actual">The actual value to test</param>
205         static public void ByVal(object actual, IResolveConstraint expression)
206         {
207             Assert.That(actual, expression, null, null);
208         }
209
210         /// <summary>
211         /// Apply a constraint to an actual value, succeeding if the constraint
212         /// is satisfied and throwing an assertion exception on failure. 
213         /// Used as a synonym for That in rare cases where a private setter 
214         /// causes a Visual Basic compilation error.
215         /// </summary>
216         /// <remarks>
217         /// This method is provided for use by VB developers needing to test
218         /// the value of properties with private setters.
219         /// </remarks>
220         /// <param name="expression">A Constraint expression to be applied</param>
221         /// <param name="actual">The actual value to test</param>
222         /// <param name="message">The message that will be displayed on failure</param>
223         /// <param name="args">Arguments to be used in formatting the message</param>
224         static public void ByVal(object actual, IResolveConstraint expression, string message, params object[] args)
225         {
226             Assert.That(actual, expression, message, args);
227         }
228
229         #endregion
230
231     }
232 }