Example #1
0
 internal static EqResult ApplyOperatorEqualityToNull <T>(T obj)
 {
     if (typeof(T).IsClass)
     {
         return(ApplyOperatorEquality <T>(obj, default(T), false));
     }
     return(EqResult.Success());
 }
Example #2
0
 internal static EqResult ApplyEqualsOfT <T>(T objA, T objB, bool expectedEqualObjects)
 {
     if (objA is IEquatable <T> )
     {
         return(ApplyEqualsOfTOnIEquatable <T>(objA as IEquatable <T>, objB, expectedEqualObjects));
     }
     return(EqResult.Success());
 }
Example #3
0
 internal static EqResult ApplyGetHashCodeOnEqualObjects <T>(T objA, T objB)
 {
     return(GetEqResult("GetHashCode", () =>
     {
         if (objA.GetHashCode() != objB.GetHashCode())
         {
             return EqResult.Failure("GetHashCode of equal objects returned different values.");
         }
         return EqResult.Success();
     }));
 }
Example #4
0
 internal static EqResult ApplyEqualsToNonNullOfOtherType <T>(T obj)
 {
     return(GetEqResult("Equals", () =>
     {
         if (obj.Equals(new object()))
         {
             return EqResult.Failure("Equals returned 'true' on comparing with object of a different type.");
         }
         return EqResult.Success();
     }));
 }
Example #5
0
 internal static EqResult ApplyEqualsOfTOnIEquatable <T>(IEquatable <T> objA, T objB, bool expectedEqualObjects)
 {
     return(GetEqResult("Typed Equals", () =>
     {
         var actualEqual = objA.Equals(objB);
         if (actualEqual != expectedEqualObjects)
         {
             var message = string.Format("Typed Equals returned '{0}' on expected {1}equal objects.",
                                         actualEqual.ToString().ToLower(),
                                         expectedEqualObjects ? "" : "non-");
             return EqResult.Failure(message);
         }
         return EqResult.Success();
     }));
 }
Example #6
0
 internal static EqResult ApplyOperatorInequality <T>(T objA, T objB, bool expectedUnequalObjects, MethodInfo operatorInequality)
 {
     return(GetEqResult("Operator !=", () =>
     {
         var actualUnequal = (bool)operatorInequality.Invoke(null, new object[] { objA, objB });
         if (actualUnequal != expectedUnequalObjects)
         {
             var message = string.Format("Inequality operator returned '{0}' on expected {1}equal objects.",
                                         actualUnequal.ToString().ToLower(),
                                         expectedUnequalObjects ? "non-" : "");
             return EqResult.Failure(message);
         }
         return EqResult.Success();
     }));
 }