[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Constraints / CollectionContainsConstraint.cs
1 // ***********************************************************************
2 // Copyright (c) 2007-2015 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     /// CollectionContainsConstraint is used to test whether a collection
36     /// contains an expected object as a member.
37     /// </summary>
38     public class CollectionContainsConstraint : CollectionItemsEqualConstraint
39     {
40         /// <summary>
41         /// Construct a CollectionContainsConstraint
42         /// </summary>
43         /// <param name="expected"></param>
44         public CollectionContainsConstraint(object expected)
45             : base(expected)
46         {
47             Expected = expected;
48         }
49
50         /// <summary> 
51         /// The display name of this Constraint for use by ToString().
52         /// The default value is the name of the constraint with
53         /// trailing "Constraint" removed. Derived classes may set
54         /// this to another name in their constructors.
55         /// </summary>
56         public override string DisplayName { get { return "Contains"; } }
57
58         /// <summary>
59         /// The Description of what this constraint tests, for
60         /// use in messages and in the ConstraintResult.
61         /// </summary>
62         public override string Description
63         {
64             get { return "collection containing " + MsgUtils.FormatValue(Expected); }
65         }
66
67         /// <summary>
68         /// Gets the expected object
69         /// </summary>
70         protected object Expected { get; private set; }
71
72         /// <summary>
73         /// Test whether the expected item is contained in the collection
74         /// </summary>
75         /// <param name="actual"></param>
76         /// <returns></returns>
77         protected override bool Matches(IEnumerable actual)
78         {
79             foreach (object obj in actual)
80                 if (ItemsEqual(obj, Expected))
81                     return true;
82
83             return false;
84         }
85
86
87         /// <summary>
88         /// Flag the constraint to use the supplied predicate function
89         /// </summary>
90         /// <param name="comparison">The comparison function to use.</param>
91         /// <returns>Self.</returns>
92         public CollectionContainsConstraint Using<TCollectionType, TMemberType>(Func<TCollectionType, TMemberType, bool> comparison)
93         {
94             // reverse the order of the arguments to match expectations of PredicateEqualityComparer
95             Func<TMemberType, TCollectionType, bool> invertedComparison = (actual, expected) => comparison.Invoke(expected, actual);
96
97             base.Using(EqualityAdapter.For(invertedComparison));
98             return this;
99         }
100     }
101 }