Пример #1
0
        public static void Should <T>(this IEnumerable <T> actual, CollectionEquivalentConstraint constraint, string message = null, params object[] args)
        {
            if (!actual.GetType().IsArray)
            {
                actual = actual.ToArray();
            }

            Assert.That(actual, constraint, message, args);
        }
Пример #2
0
        public void WorksWithArrayAndHashSet()
        {
            var hash  = new HashSet <string>(new string[] { "presto", "abracadabra", "hocuspocus" });
            var array = new string[] { "abracadabra", "presto", "hocuspocus" };

            var constraint = new CollectionEquivalentConstraint(array);

            Assert.That(constraint.Matches(hash));
        }
Пример #3
0
        /// <summary>Construct a <see cref="CollectionEquivalentConstraintResult"/> using a <see cref="CollectionTally.CollectionTallyResult"/>.</summary>
        /// <param name="constraint">Source <see cref="CollectionEquivalentConstraint"/>.</param>
        /// <param name="tallyResult">Result of the collection comparison.</param>
        /// <param name="actual">Actual collection to compare.</param>
        /// <param name="isSuccess">Whether or not the <see cref="CollectionEquivalentConstraint"/> succeeded.</param>
        public CollectionEquivalentConstraintResult(
            CollectionEquivalentConstraint constraint,
            CollectionTally.CollectionTallyResult tallyResult,
            object actual,
            bool isSuccess)
            : base(constraint, actual, isSuccess)
        {
            Guard.ArgumentNotNull(tallyResult, nameof(tallyResult));

            _tallyResult = tallyResult;
        }
Пример #4
0
 protected override void SetUp()
 {
     Matcher    = new CollectionEquivalentConstraint(new int[] { 1, 2, 3, 4, 5 });
     GoodValues = new object[] { new int[] { 1, 3, 5, 4, 2 } };
     BadValues  = new object[] {
         new int[] { 1, 2, 3, 7, 5 },
         new int[] { 1, 2, 2, 2, 5 },
         new int[] { 1, 2, 2, 3, 4, 5 }
     };
     Description = "equivalent to < 1, 2, 3, 4, 5 >";
 }
        public void WorksWithCollectionsOfArrays()
        {
            byte[] array1 = new byte[] { 0x20, 0x44, 0x56, 0x76, 0x1e, 0xff };
            byte[] array2 = new byte[] { 0x42, 0x52, 0x72, 0xef };
            byte[] array3 = new byte[] { 0x20, 0x44, 0x56, 0x76, 0x1e, 0xff };
            byte[] array4 = new byte[] { 0x42, 0x52, 0x72, 0xef };

            ICollection set1 = new ICollectionAdapter(array1, array2);
            ICollection set2 = new ICollectionAdapter(array3, array4);

            Constraint constraint = new CollectionEquivalentConstraint(set1);
            Assert.That(constraint.Matches(set2));

            set2 = new ICollectionAdapter(array4, array3);
            Assert.That(constraint.Matches(set2));
        }
Пример #6
0
        public void WorksWithCollectionsOfArrays()
        {
            byte[] array1 = new byte[] { 0x20, 0x44, 0x56, 0x76, 0x1e, 0xff };
            byte[] array2 = new byte[] { 0x42, 0x52, 0x72, 0xef };
            byte[] array3 = new byte[] { 0x20, 0x44, 0x56, 0x76, 0x1e, 0xff };
            byte[] array4 = new byte[] { 0x42, 0x52, 0x72, 0xef };

            ICollection set1 = new SimpleObjectCollection(array1, array2);
            ICollection set2 = new SimpleObjectCollection(array3, array4);

            Constraint constraint = new CollectionEquivalentConstraint(set1);

            Assert.That(constraint.Matches(set2));

            set2 = new SimpleObjectCollection(array4, array3);
            Assert.That(constraint.Matches(set2));
        }
Пример #7
0
        public void FailureMessageWithHashSetAndArray()
        {
            var hash  = new HashSet <string>(new string[] { "presto", "abracadabra", "hocuspocus" });
            var array = new string[] { "abracadabra", "presto", "hocusfocus" };

            var constraint = new CollectionEquivalentConstraint(hash);

            Assert.False(constraint.Matches(array));

            TextMessageWriter writer = new TextMessageWriter();

            constraint.WriteMessageTo(writer);
            Assert.That(writer.ToString(), Is.EqualTo(
                            "  Expected: equivalent to < \"presto\", \"abracadabra\", \"hocuspocus\" >" + Environment.NewLine +
                            "  But was:  < \"abracadabra\", \"presto\", \"hocusfocus\" >" + Environment.NewLine));
            Console.WriteLine(writer.ToString());
        }
Пример #8
0
 /// <summary>
 /// Construct a CollectionEquivalentConstraint
 /// </summary>
 /// <param name="expected"></param>
 public EquivalentToConstraint(IEnumerable <string> expected)
     : base(expected)
 {
     InternalConstraint = new CollectionEquivalentConstraint(expected.Select(str => StringComparerHelper.Build(str)).ToList());
 }
        public void FailureMessageWithHashSetAndArray()
        {
            var hash = new HashSet<string>(new string[] { "presto", "abracadabra", "hocuspocus" });
            var array = new string[] { "abracadabra", "presto", "hocusfocus" };

            var constraint = new CollectionEquivalentConstraint(hash);
            Assert.False(constraint.Matches(array));

            TextMessageWriter writer = new TextMessageWriter();
            constraint.WriteMessageTo(writer);
            Assert.That(writer.ToString(), Is.EqualTo(
                "  Expected: equivalent to < \"presto\", \"abracadabra\", \"hocuspocus\" >" + Environment.NewLine +
                "  But was:  < \"abracadabra\", \"presto\", \"hocusfocus\" >" + Environment.NewLine));
            Console.WriteLine(writer.ToString());
        }
        public void WorksWithArrayAndHashSet()
        {
            var hash = new HashSet<string>(new string[] { "presto", "abracadabra", "hocuspocus" });
            var array = new string[] { "abracadabra", "presto", "hocuspocus" };

            var constraint = new CollectionEquivalentConstraint(array);
            Assert.That(constraint.Matches(hash));
        }
 public static CollectionItemsEqualConstraint UsingItemComparer(this CollectionEquivalentConstraint constraint)
 => constraint.Using(ItemComparer.Instance);