[NUI] Add Tizen.NUI.Tests for tct developing (#2090)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / nunit.framework / Constraints / AndConstraint.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 namespace NUnit.Framework.Constraints
30 {
31     /// <summary>
32     /// AndConstraint succeeds only if both members succeed.
33     /// </summary>
34     public class AndConstraint : BinaryConstraint
35     {
36         //private enum FailurePoint
37         //{
38         //    None,
39         //    Left,
40         //    Right
41         //};
42
43         //private FailurePoint failurePoint;
44
45         /// <summary>
46         /// Create an AndConstraint from two other constraints
47         /// </summary>
48         /// <param name="left">The first constraint</param>
49         /// <param name="right">The second constraint</param>
50         public AndConstraint(IConstraint left, IConstraint right) : base(left, right) { }
51
52         /// <summary>
53         /// Gets text describing a constraint
54         /// </summary>
55         public override string Description
56         {
57             get { return Left.Description + " and " + Right.Description; }
58         }
59
60         /// <summary>
61         /// Apply both member constraints to an actual value, succeeding 
62         /// succeeding only if both of them succeed.
63         /// </summary>
64         /// <param name="actual">The actual value</param>
65         /// <returns>True if the constraints both succeeded</returns>
66         public override ConstraintResult ApplyTo<TActual>(TActual actual)
67         {
68             var leftResult = Left.ApplyTo(actual);
69             var rightResult = leftResult.IsSuccess
70                 ? Right.ApplyTo(actual)
71                 : new ConstraintResult(Right, actual);
72
73             return new AndConstraintResult(this, actual, leftResult, rightResult);
74         }
75
76         #region Nested Result Class
77
78         class AndConstraintResult : ConstraintResult
79         {
80             private ConstraintResult leftResult;
81             private ConstraintResult rightResult;
82
83             public AndConstraintResult(AndConstraint constraint, object actual, ConstraintResult leftResult, ConstraintResult rightResult)
84                 : base(constraint, actual, leftResult.IsSuccess && rightResult.IsSuccess) 
85             {
86                 this.leftResult = leftResult;
87                 this.rightResult = rightResult;
88             }
89
90             /// <summary>
91             /// Write the actual value for a failing constraint test to a
92             /// MessageWriter. The default implementation simply writes
93             /// the raw value of actual, leaving it to the writer to
94             /// perform any formatting.
95             /// </summary>
96             /// <param name="writer">The writer on which the actual value is displayed</param>
97             public override void WriteActualValueTo(MessageWriter writer)
98             {
99                 if (this.IsSuccess)
100                     base.WriteActualValueTo(writer);
101                 else if (!leftResult.IsSuccess)
102                     leftResult.WriteActualValueTo(writer);
103                 else
104                     rightResult.WriteActualValueTo(writer);
105             }
106         }
107
108         #endregion
109     }
110 }