private bool ObjectsEqual(object expected, object actual) { if (expected == null && actual == null) { return(true); } if (expected == null || actual == null) { return(false); } Type expectedType = expected.GetType(); Type actualType = actual.GetType(); if (expectedType.IsArray && actualType.IsArray && !compareAsCollection) { return(ArraysEqual((Array)expected, (Array)actual)); } if (expected is ICollection && actual is ICollection) { return(CollectionsEqual((ICollection)expected, (ICollection)actual)); } if (expected is Stream && actual is Stream) { return(StreamsEqual((Stream)expected, (Stream)actual)); } if (compareWith != null) { return(compareWith.Compare(expected, actual) == 0); } if (Numerics.IsNumericType(expected) && Numerics.IsNumericType(actual)) { return(Numerics.AreEqual(expected, actual, tolerance)); } if (expected is string && actual is string) { return(string.Compare((string)expected, (string)actual, caseInsensitive) == 0); } foreach (Type type in constraintHelpers.Keys) { if (type.IsInstanceOfType(expected) && type.IsInstanceOfType(actual)) { Type constraintType = (Type)constraintHelpers[type]; Constraint constraint = (Constraint)NUnitLite.Reflect.Construct(constraintType, expected); return(constraint.Matches(actual)); } } return(expected.Equals(actual)); }
/// <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) { this.actual = actual; if (this.caseInsensitive) { baseConstraint = baseConstraint.IgnoreCase; } return(!baseConstraint.Matches(actual)); }
protected override bool DoMatch(NUnitCtr.Constraint ctr) { if (specific == null) { return(ctr.Matches(actual)); } else { return(SpecificMatches(actual)); } }
/// <summary> /// Apply the item constraint to each item in the collection, /// failing if any item fails. /// </summary> /// <param name="actual"></param> /// <returns></returns> public override bool Matches(object actual) { this.actual = actual; if (actual == null || !(actual is ICollection)) { return(false); } if (this.caseInsensitive) { itemConstraint = itemConstraint.IgnoreCase; } foreach (object item in (ICollection)actual) { if (!itemConstraint.Matches(item)) { return(false); } } return(true); }
protected bool doMatch(int actual) { this.actual = actual; return(child.Matches(actual)); }
protected virtual bool DoMatch(NUnitCtr.Constraint ctr) { return(ctr.Matches(actual)); }