Example #1
0
        /// <summary>
        /// Test whether the constraint is satisfied by a given value
        /// </summary>
        /// <param name="actual">The value to be tested</param>
        /// <returns>True for success, false for failure</returns>
        public override bool Matches(object actual)
        {
            Actual = actual;

            // TODO: Should be argument exception?
            if (actual == null)
            {
                return(false);
            }

            PropertyInfo property = actual.GetType().GetProperty(_name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (property == null)
            {
                return(_propertyExists = false);
            }

            if (BaseConstraint == null)
            {
                return(true);
            }

            _propValue = property.GetValue(actual, null);
            return(BaseConstraint.Matches(_propValue));
        }
Example #2
0
        /// <summary>
        /// Apply the item constraint to each item in the collection, failing if
        /// any item fails.
        /// </summary>
        /// <param name="actual">The value to be tested</param>
        /// <returns>True for success, false for failure</returns>
        /// <exception cref="ArgumentException">if actual is not an ICollection</exception>
        public override bool Matches(object actual)
        {
            Actual = actual;

            PassModifiersToBase();

            if (!(actual is ICollection))
            {
                throw new ArgumentException(Resources.ValueMustBeCollection, "actual");
            }

            foreach (object item in (ICollection)actual)
            {
                if (BaseConstraint.Matches(item))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
 /// <summary>
 /// Test whether the constraint is satisfied by a given value
 /// </summary>
 /// <param name="actual">The value to be tested</param>
 /// <returns>
 /// True for if the base constraint fails, false if it succeeds
 /// </returns>
 public override bool Matches(object actual)
 {
     Actual = actual;
     PassModifiersToBase();
     return(!BaseConstraint.Matches(actual));
 }