CollectionContainsConstraint is used to test whether a collection contains an expected object as a member.
Inheritance: NUnit.Framework.Constraints.CollectionConstraint
Ejemplo n.º 1
0
        /// <summary>
        /// Build a collection of constraint (in fact one by expected item)
        /// Pay really attention that CollectionContainsConstraint is expecting one unique item!
        /// So if you cant to check for several items, you need to apply several Constraint (one by expected item)
        /// </summary>
        protected virtual void BuildInternalConstraint()
        {
            NUnitCtr.Constraint ctr = null;
            foreach (var item in Expected)
            {
                var localCtr = new NUnitCtr.CollectionContainsConstraint(StringComparerHelper.Build(item));
                var usingCtr = localCtr.Using(Comparer);

                if (ctr != null)
                {
                    ctr = new AndConstraint(ctr, usingCtr);
                }
                else
                {
                    ctr = usingCtr;
                }
            }

            if (ctr == null)
            {
                ctr = new NUnitCtr.EmptyCollectionConstraint();
            }

            IResolveConstraint exp = ctr;

            InternalConstraint = exp.Resolve();
        }
 public void IgnoreCaseIsHonored( object expected, IEnumerable actual )
 {
     var constraint = new CollectionContainsConstraint( expected ).IgnoreCase;
     var constraintResult = constraint.ApplyTo( actual );
     if ( !constraintResult.IsSuccess )
     {
         MessageWriter writer = new TextMessageWriter();
         constraintResult.WriteMessageTo( writer );
         Assert.Fail( writer.ToString() );
     }
 }
        public void IgnoreCaseIsHonored(object expected, IEnumerable actual)
        {
            var constraint       = new CollectionContainsConstraint(expected).IgnoreCase;
            var constraintResult = constraint.ApplyTo(actual);

            if (!constraintResult.IsSuccess)
            {
                MessageWriter writer = new TextMessageWriter();
                constraintResult.WriteMessageTo(writer);
                Assert.Fail(writer.ToString());
            }
        }
Ejemplo n.º 4
0
        protected override NUnitCtr.Constraint BuildInternalConstraint()
        {
            NUnitCtr.Constraint ctr = null;
            foreach (var item in ExpectedItems)
            {
                var localCtr = new NUnitCtr.CollectionContainsConstraint(StringComparerHelper.Build(item));
                var usingCtr = localCtr.Using(Comparer);

                if (ctr != null)
                    ctr = new NUnitCtr.AndConstraint(ctr, usingCtr);
                else
                    ctr = usingCtr;
            }
            return ctr;
        }
Ejemplo n.º 5
0
        protected override NUnitCtr.Constraint BuildInternalConstraint()
        {
            NUnitCtr.Constraint ctr = null;
            foreach (var item in ExpectedItems)
            {
                var localCtr = new NUnitCtr.CollectionContainsConstraint(StringComparerHelper.Build(item));
                var usingCtr = localCtr.Using(Comparer);

                if (ctr != null)
                {
                    ctr = new NUnitCtr.AndConstraint(ctr, usingCtr);
                }
                else
                {
                    ctr = usingCtr;
                }
            }
            return(ctr);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Build a collection of constraint (in fact one by expected item)
        /// Pay really attention that CollectionContainsConstraint is expecting one unique item!
        /// So if you cant to check for several items, you need to apply several Constraint (one by expected item)
        /// </summary>
        protected virtual void BuildInternalConstraint()
        {
            NUnitCtr.Constraint ctr = null;
            foreach (var item in Expected)
            {
                var localCtr = new NUnitCtr.CollectionContainsConstraint(StringComparerHelper.Build(item));
                var usingCtr = localCtr.Using(Comparer);

                if (ctr != null)
                    ctr = new AndConstraint(ctr, usingCtr);
                else
                    ctr = usingCtr;
            }

            if (ctr == null)
                ctr = new NUnitCtr.EmptyCollectionConstraint();

            IResolveConstraint exp = ctr;
            InternalConstraint = exp.Resolve();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Construct a LinkedToConstraint
 /// </summary>
 public LinkedToConstraint(string expected)
     : base()
 {
     InternalConstraint = new CollectionContainsConstraint(StringComparerHelper.Build(expected));
     this.Expected = expected;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Construct a LinkedToConstraint
 /// </summary>
 public LinkedToConstraint(string expected)
     : base()
 {
     InternalConstraint = new CollectionContainsConstraint(expected);
     this.Expected = expected;
 }