[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Constraints / ConstraintResult.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 #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     /// ConstraintStatus represents the status of a ConstraintResult
33     /// returned by a Constraint being applied to an actual value.
34     /// </summary>
35     public enum ConstraintStatus
36     {
37         /// <summary>
38         /// The status has not yet been set
39         /// </summary>
40         Unknown,
41
42         /// <summary>
43         /// The constraint succeeded
44         /// </summary>
45         Success,
46
47         /// <summary>
48         /// The constraint failed
49         /// </summary>
50         Failure,
51
52         /// <summary>
53         /// An error occured in applying the constraint (reserved for future use)
54         /// </summary>
55         Error
56     }
57
58     /// <summary>
59     /// Contain the result of matching a <see cref="Constraint"/> against an actual value.
60     /// </summary>
61     public class ConstraintResult
62     {
63         IConstraint _constraint;
64
65         #region Constructors
66
67         /// <summary>
68         /// Constructs a <see cref="ConstraintResult"/> for a particular <see cref="Constraint"/>.
69         /// </summary>
70         /// <param name="constraint">The Constraint to which this result applies.</param>
71         /// <param name="actualValue">The actual value to which the Constraint was applied.</param>
72         public ConstraintResult(IConstraint constraint, object actualValue)
73         {
74             _constraint = constraint;
75             ActualValue = actualValue;
76         }
77
78         /// <summary>
79         /// Constructs a <see cref="ConstraintResult"/> for a particular <see cref="Constraint"/>.
80         /// </summary>
81         /// <param name="constraint">The Constraint to which this result applies.</param>
82         /// <param name="actualValue">The actual value to which the Constraint was applied.</param>
83         /// <param name="status">The status of the new ConstraintResult.</param>
84         public ConstraintResult(IConstraint constraint, object actualValue, ConstraintStatus status)
85             : this(constraint, actualValue)
86         {
87             Status = status;
88         }
89
90         /// <summary>
91         /// Constructs a <see cref="ConstraintResult"/> for a particular <see cref="Constraint"/>.
92         /// </summary>
93         /// <param name="constraint">The Constraint to which this result applies.</param>
94         /// <param name="actualValue">The actual value to which the Constraint was applied.</param>
95         /// <param name="isSuccess">If true, applies a status of Success to the result, otherwise Failure.</param>
96         public ConstraintResult(IConstraint constraint, object actualValue, bool isSuccess)
97             : this(constraint, actualValue)
98         {
99             Status = isSuccess ? ConstraintStatus.Success : ConstraintStatus.Failure;
100         }
101
102         #endregion
103
104         #region Properties
105
106         /// <summary>
107         /// The actual value that was passed to the <see cref="Constraint.ApplyTo{TActual}(TActual)"/> method.
108         /// </summary>
109         public object ActualValue { get; private set; }
110
111         /// <summary>
112         /// Gets and sets the ResultStatus for this result.
113         /// </summary>
114         public ConstraintStatus Status { get; set; }
115
116         /// <summary>
117         /// True if actual value meets the Constraint criteria otherwise false.
118         /// </summary>
119         public virtual bool IsSuccess
120         {
121             get { return Status == ConstraintStatus.Success; }
122         }
123
124         /// <summary>
125         /// Display friendly name of the constraint.
126         /// </summary>
127         public string Name { get { return _constraint.DisplayName; } }
128
129         /// <summary>
130         /// Description of the constraint may be affected by the state the constraint had
131         /// when <see cref="Constraint.ApplyTo{TActual}(TActual)"/> was performed against the actual value.
132         /// </summary>
133         public string Description { get { return _constraint.Description; } }
134
135         #endregion
136
137         #region Write Methods
138
139         /// <summary>
140         /// Write the failure message to the MessageWriter provided
141         /// as an argument. The default implementation simply passes
142         /// the result and the actual value to the writer, which
143         /// then displays the constraint description and the value.
144         /// 
145         /// Constraints that need to provide additional details,
146         /// such as where the error occured can override this.
147         /// </summary>
148         /// <param name="writer">The MessageWriter on which to display the message</param>
149         public virtual void WriteMessageTo(MessageWriter writer)
150         {
151             writer.DisplayDifferences(this);
152         }
153
154         /// <summary>
155         /// Write the actual value for a failing constraint test to a
156         /// MessageWriter. The default implementation simply writes
157         /// the raw value of actual, leaving it to the writer to
158         /// perform any formatting.
159         /// </summary>
160         /// <param name="writer">The writer on which the actual value is displayed</param>
161         public virtual void WriteActualValueTo(MessageWriter writer)
162         {
163             writer.WriteActualValue(ActualValue);
164         }
165
166         #endregion
167     }
168 }