[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Constraints / CollectionConstraint.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;
30 using System.Collections;
31
32 namespace NUnit.Framework.Constraints
33 {
34     /// <summary>
35     /// CollectionConstraint is the abstract base class for
36     /// constraints that operate on collections.
37     /// </summary>
38     public abstract class CollectionConstraint : Constraint
39     {
40         /// <summary>
41         /// Construct an empty CollectionConstraint
42         /// </summary>
43         protected CollectionConstraint() { }
44
45         /// <summary>
46         /// Construct a CollectionConstraint
47         /// </summary>
48         /// <param name="arg"></param>
49         protected CollectionConstraint(object arg) : base(arg) { }
50
51         /// <summary>
52         /// Determines whether the specified enumerable is empty.
53         /// </summary>
54         /// <param name="enumerable">The enumerable.</param>
55         /// <returns>
56         /// <c>true</c> if the specified enumerable is empty; otherwise, <c>false</c>.
57         /// </returns>
58         protected static bool IsEmpty(IEnumerable enumerable)
59         {
60             ICollection collection = enumerable as ICollection;
61             if (collection != null)
62                 return collection.Count == 0;
63
64             foreach (object o in enumerable)
65                 return false;
66
67             return true;
68         }
69
70         /// <summary>
71         /// Test whether the constraint is satisfied by a given value
72         /// </summary>
73         /// <param name="actual">The value to be tested</param>
74         /// <returns>True for success, false for failure</returns>
75         public override ConstraintResult ApplyTo<TActual>(TActual actual)
76         {
77             // TODO: Use an error result if actual is not IEnumerable
78             IEnumerable enumerable = actual as IEnumerable;
79             if (enumerable == null)
80                 throw new ArgumentException("The actual value must be an IEnumerable", "actual");
81                 //return new ConstraintResult(this, actual, "The actual value must be an IEnumerable");
82
83             return new ConstraintResult(this, actual, Matches(enumerable));
84         }
85
86         /// <summary>
87         /// Protected method to be implemented by derived classes
88         /// </summary>
89         /// <param name="collection"></param>
90         /// <returns></returns>
91         protected abstract bool Matches(IEnumerable collection);
92     }
93 }