Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/guiunit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Laval <jeremie.laval@gmail.com>2017-03-27 20:44:28 +0300
committerJérémie Laval <jeremie.laval@gmail.com>2017-03-27 20:44:49 +0300
commit052ee0fb55fd44c317eb6647b02444fd0734526d (patch)
tree0b8e8d1570428d15e6009a85b4a655d9794bbf5d
parent3a445806895aa25a17d887cbfcddea86e8e14809 (diff)
[framework] Add superset constraint
-rwxr-xr-xsrc/framework/Constraints/CollectionSupersetConstraint.cs67
-rw-r--r--src/framework/GuiUnit_NET_4_5.csproj1
-rwxr-xr-xsrc/framework/Is.cs13
3 files changed, 81 insertions, 0 deletions
diff --git a/src/framework/Constraints/CollectionSupersetConstraint.cs b/src/framework/Constraints/CollectionSupersetConstraint.cs
new file mode 100755
index 0000000..7c3a7b8
--- /dev/null
+++ b/src/framework/Constraints/CollectionSupersetConstraint.cs
@@ -0,0 +1,67 @@
+// ***********************************************************************
+// Copyright (c) 2007 Charlie Poole
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+// ***********************************************************************
+
+using System.Collections;
+
+namespace NUnit.Framework.Constraints
+{
+ /// <summary>
+ /// CollectionSupersetConstraint is used to determine whether
+ /// one collection is a superset of another
+ /// </summary>
+ public class CollectionSupersetConstraint : CollectionItemsEqualConstraint
+ {
+ private IEnumerable expected;
+
+ /// <summary>
+ /// Construct a CollectionSupersetConstraint
+ /// </summary>
+ /// <param name="expected">The collection that the actual value is expected to be a superset of</param>
+ public CollectionSupersetConstraint(IEnumerable expected) : base(expected)
+ {
+ this.expected = expected;
+ this.DisplayName = "supersetof";
+ }
+
+ /// <summary>
+ /// Test whether the actual collection is a superset of
+ /// the expected collection provided.
+ /// </summary>
+ /// <param name="actual"></param>
+ /// <returns></returns>
+ protected override bool doMatch(IEnumerable actual)
+ {
+ return Tally(actual).TryRemove( expected );
+ }
+
+ /// <summary>
+ /// Write a description of this constraint to a MessageWriter
+ /// </summary>
+ /// <param name="writer"></param>
+ public override void WriteDescriptionTo(MessageWriter writer)
+ {
+ writer.WritePredicate( "superset of" );
+ writer.WriteExpectedValue(expected);
+ }
+ }
+}
diff --git a/src/framework/GuiUnit_NET_4_5.csproj b/src/framework/GuiUnit_NET_4_5.csproj
index 35e9b95..e5c8e47 100644
--- a/src/framework/GuiUnit_NET_4_5.csproj
+++ b/src/framework/GuiUnit_NET_4_5.csproj
@@ -346,6 +346,7 @@
<Compile Include="GuiUnit\XmlTestListener.cs" />
<Compile Include="GuiUnit\AdditionalAsserts.cs" />
<Compile Include="GuiUnit\GtkMainLoopIntegration.cs" />
+ <Compile Include="Constraints\CollectionSupersetConstraint.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
diff --git a/src/framework/Is.cs b/src/framework/Is.cs
index fe32db8..824789a 100755
--- a/src/framework/Is.cs
+++ b/src/framework/Is.cs
@@ -402,6 +402,19 @@ namespace NUnit.Framework
#endregion
+ #region SupersetOf
+
+ /// <summary>
+ /// Returns a constraint that tests whether the actual value
+ /// is a superset of the collection supplied as an argument.
+ /// </summary>
+ public static CollectionSupersetConstraint SupersetOf (IEnumerable expected)
+ {
+ return new CollectionSupersetConstraint (expected);
+ }
+
+ #endregion
+
#region Ordered
/// <summary>