コード例 #1
0
        public void TestConstraintResultMessageDisplaysMissingAndExtraElements()
        {
            List <string> expectedCollection = new List <string>()
            {
                "one", "two"
            };
            List <string> actualCollection = new List <string>()
            {
                "three", "one"
            };

            ConstraintResult cr = new CollectionEquivalentConstraint(expectedCollection).ApplyTo(actualCollection);

            TextMessageWriter writer = new TextMessageWriter();

            cr.WriteMessageTo(writer);

            string expectedMsg =
                "  Expected: equivalent to < \"one\", \"two\" >" + Environment.NewLine +
                "  But was:  < \"three\", \"one\" >" + Environment.NewLine +
                "  Missing (1): < \"two\" >" + Environment.NewLine +
                "  Extra (1): < \"three\" >" + Environment.NewLine;

            Assert.AreEqual(expectedMsg, writer.ToString());
        }
コード例 #2
0
        public void WorksWithNonIComparableTuples()
        {
            var message3 = new object();
            var message4 = new object();
            var actual   = new[]
            {
                new Tuple <int, object, CancellationToken>(1, message3, CancellationToken.None),
                new Tuple <int, object, CancellationToken>(2, message3, CancellationToken.None),
                new Tuple <int, object, CancellationToken>(1, message4, CancellationToken.None),
                new Tuple <int, object, CancellationToken>(2, message4, CancellationToken.None)
            };

            var expected = new[]
            {
                new Tuple <int, object, CancellationToken>(1, message4, CancellationToken.None),
                new Tuple <int, object, CancellationToken>(2, message4, CancellationToken.None),
                new Tuple <int, object, CancellationToken>(1, message3, CancellationToken.None),
                new Tuple <int, object, CancellationToken>(2, message3, CancellationToken.None)
            };

            var constraint = new CollectionEquivalentConstraint(expected);
            var result     = constraint.ApplyTo(actual);

            Assert.That(result.IsSuccess);
        }
コード例 #3
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.ApplyTo(hash).IsSuccess);
        }
コード例 #4
0
        public void WorksWithHashSetAndArray()
        {
            var hash  = new HashSet <string>(new string[] { "presto", "abracadabra", "hocuspocus" });
            var array = new string[] { "abracadabra", "presto", "hocuspocus" };

            var constraint = new CollectionEquivalentConstraint(hash);

            Assert.That(constraint.Matches(array));
        }
コード例 #5
0
        public void HonorsIgnoreCase(IEnumerable expected, IEnumerable actual)
        {
            var constraint       = new CollectionEquivalentConstraint(expected).IgnoreCase;
            var constraintResult = constraint.ApplyTo(actual);

            if (!constraintResult.IsSuccess)
            {
                MessageWriter writer = new TextMessageWriter();
                constraintResult.WriteMessageTo(writer);
                Assert.Fail(writer.ToString());
            }
        }
コード例 #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 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));
        }
コード例 #7
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.ApplyTo(set2).IsSuccess);

            set2 = new SimpleObjectCollection(array4, array3);
            Assert.That(constraint.ApplyTo(set2).IsSuccess);
        }
コード例 #8
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 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));
        }
コード例 #9
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.ApplyTo(set2).IsSuccess);

            set2 = new SimpleObjectCollection(array4, array3);
            Assert.That(constraint.ApplyTo(set2).IsSuccess);
        }
コード例 #10
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());
        }
コード例 #11
0
        public void LargeStringCollectionsInReversedOrder()
        {
            var actual   = Enumerable.Range(0, SIZE).Select(i => i.ToString()).ToList();
            var expected = Enumerable.Range(0, SIZE).Select(i => (SIZE - i - 1).ToString()).ToList();

            var watch = Stopwatch.StartNew();

            var constraint       = new CollectionEquivalentConstraint(actual);
            var constraintResult = constraint.ApplyTo(expected);

            Assert.That(constraintResult.IsSuccess, Is.True);

            watch.Stop();
            if (watch.ElapsedMilliseconds > LARGE_COLLECTION_WARN_TIME)
            {
                Assert.Warn($"{TestContext.CurrentContext.Test.MethodName} took {watch.ElapsedMilliseconds} ms.");
            }
        }
コード例 #12
0
        public void LargeByteCollectionsNotEquivalentAtEnd()
        {
            byte[] data      = new byte[SIZE];
            byte[] encrypted = new byte[SIZE];
            encrypted[SIZE - 2] = 2;
            encrypted[SIZE - 1] = 3;

            var watch = Stopwatch.StartNew();

            var constraint       = new CollectionEquivalentConstraint(data);
            var constraintResult = constraint.ApplyTo(encrypted);

            Assert.That(constraintResult.IsSuccess, Is.False);

            watch.Stop();
            if (watch.ElapsedMilliseconds > LARGE_COLLECTION_WARN_TIME)
            {
                Assert.Warn($"{TestContext.CurrentContext.Test.MethodName} took {watch.ElapsedMilliseconds} ms.");
            }
        }
コード例 #13
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);
            var constraintResult = constraint.ApplyTo(array);

            Assert.False(constraintResult.IsSuccess);

            TextMessageWriter writer = new TextMessageWriter();

            constraintResult.WriteMessageTo(writer);

            var expectedMessage =
                "  Expected: equivalent to < \"presto\", \"abracadabra\", \"hocuspocus\" >" + Environment.NewLine +
                "  But was:  < \"abracadabra\", \"presto\", \"hocusfocus\" >" + Environment.NewLine +
                "  Missing (1): < \"hocuspocus\" >" + Environment.NewLine +
                "  Extra (1): < \"hocusfocus\" >" + Environment.NewLine;

            Assert.That(writer.ToString(), Is.EqualTo(expectedMessage));
        }
コード例 #14
0
        public void LargeStringCollection()
        {
            var actual   = new StringCollection();
            var expected = new StringCollection();

            foreach (var i in Enumerable.Range(0, SIZE))
            {
                actual.Add(i.ToString());
                expected.Add(i.ToString());
            }

            var watch = Stopwatch.StartNew();

            var constraint       = new CollectionEquivalentConstraint(actual);
            var constraintResult = constraint.ApplyTo(expected);

            Assert.That(constraintResult.IsSuccess, Is.True);

            watch.Stop();
            if (watch.ElapsedMilliseconds > LARGE_COLLECTION_WARN_TIME)
            {
                Assert.Warn($"{TestContext.CurrentContext.Test.MethodName} took {watch.ElapsedMilliseconds} ms.");
            }
        }
コード例 #15
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 >";
 }
コード例 #16
0
        public void WorksWithHashSetAndArray()
        {
            var hash = new HashSet<string>(new string[] { "presto", "abracadabra", "hocuspocus" });
            var array = new string[] { "abracadabra", "presto", "hocuspocus" };

            var constraint = new CollectionEquivalentConstraint(hash);
            Assert.That(constraint.Matches(array));
        }
コード例 #17
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);
            var constraintResult = constraint.ApplyTo(array);
            Assert.False(constraintResult.IsSuccess);

            TextMessageWriter writer = new TextMessageWriter();
            constraintResult.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());
        }
コード例 #18
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.ApplyTo(hash).IsSuccess);
        }
コード例 #19
0
 public void HonorsIgnoreCase( IEnumerable expected, IEnumerable actual )
 {
     var constraint = new CollectionEquivalentConstraint( expected ).IgnoreCase;
     var constraintResult = constraint.ApplyTo( actual );
     if ( !constraintResult.IsSuccess )
     {
         MessageWriter writer = new TextMessageWriter();
         constraintResult.WriteMessageTo( writer );
         Assert.Fail( writer.ToString() );
     }
 }
コード例 #20
0
 public void HonorsIgnoreCase(IEnumerable expected, IEnumerable actual)
 {
     var constraint = new CollectionEquivalentConstraint(expected).IgnoreCase;
     Assert.That(constraint.Matches(actual));
 }
コード例 #21
0
        public void HonorsIgnoreCase(IEnumerable expected, IEnumerable actual)
        {
            var constraint = new CollectionEquivalentConstraint(expected).IgnoreCase;

            Assert.That(constraint.Matches(actual));
        }
コード例 #22
0
ファイル: EquivalentToConstraint.cs プロジェクト: zyh329/nbi
 /// <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());
 }
コード例 #23
0
 public void TestSetup()
 {
     _constraint = new CollectionEquivalentConstraint(_expected);
     _writer     = new TextMessageWriter();
 }