private static string BuildExpectedNotEqualMessage(string message, ComparisonResult result) { message = message ?? "Objects expected NOT to be equal"; return(message + Environment.NewLine + result.DifferencesString + Environment.NewLine); }
/// <summary> /// Get the value of a property /// </summary> /// <param name="result"> </param> /// <param name="type"></param> /// <param name="objectValue"></param> /// <param name="propertyName"></param> /// <returns></returns> public static object GetPropertyValue(ComparisonResult result, Type type, object objectValue, string propertyName) { lock (_propertyCache) return(GetPropertyInfo(result, type).First(o => o.Name == propertyName).GetValue(objectValue, null)); }
public bool Compare(object object1, object object2) { _result = _logic.Compare(object1, object2); return _result.AreEqual; }
public CompareObjects(bool useAppConfigSettings) { _logic = new CompareLogic(useAppConfigSettings); _result = new ComparisonResult(_logic.Config); }
public CompareObjects() { _logic = new CompareLogic(); _result = new ComparisonResult(_logic.Config); }
public bool Compare(object object1, object object2) { _result = _logic.Compare(object1, object2); return(_result.AreEqual); }
/// <summary> /// CompareException Constructor /// </summary> /// <param name="result"></param> /// <param name="message"></param> public CompareException(ComparisonResult result, string message) : base(message) { Result = result; }
/// <summary> /// Get a list of the properties in a type /// </summary> /// <param name="result"> </param> /// <param name="type"></param> /// <returns></returns> public static IEnumerable<PropertyInfo> GetPropertyInfo(ComparisonResult result, Type type) { lock (_propertyCache) { if (result.Config.Caching && _propertyCache.ContainsKey(type)) return _propertyCache[type]; PropertyInfo[] currentProperties; #if PORTABLE if (!result.Config.CompareStaticProperties) currentProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); else currentProperties = type.GetProperties(); //Default is public instance and static #else if (result.Config.ComparePrivateProperties && !result.Config.CompareStaticProperties) currentProperties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); else if (result.Config.ComparePrivateProperties && result.Config.CompareStaticProperties) currentProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static); else if (!result.Config.CompareStaticProperties) currentProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); else currentProperties = type.GetProperties(); //Default is public instance and static #endif if (result.Config.Caching) _propertyCache.Add(type, currentProperties); return currentProperties; } }
/// <summary> /// Get the value of a property /// </summary> /// <param name="result"> </param> /// <param name="type"></param> /// <param name="objectValue"></param> /// <param name="propertyName"></param> /// <returns></returns> public static object GetPropertyValue(ComparisonResult result, Type type, object objectValue, string propertyName) { lock (_propertyCache) return GetPropertyInfo(result, type).First(o => o.Name == propertyName).GetValue(objectValue, null); }
/// <summary> /// Compare two objects of the same type to each other. /// </summary> /// <remarks> /// Check the Differences or DifferencesString Properties for the differences. /// Default MaxDifferences is 1 for performance /// </remarks> /// <param name="object1"></param> /// <param name="object2"></param> /// <returns>True if they are equal</returns> public ComparisonResult Compare(object object1, object object2) { ComparisonResult result = new ComparisonResult(Config); #if !PORTABLE result.Watch.Start(); #endif RootComparer rootComparer = RootComparerFactory.GetRootComparer(); CompareParms parms = new CompareParms { Config = Config, Result = result, Object1 = object1, Object2 = object2, BreadCrumb = string.Empty }; rootComparer.Compare(parms); if (Config.AutoClearCache) ClearCache(); #if !PORTABLE result.Watch.Stop(); #endif return result; }
public override bool Matches(object actualValue) { actual = actualValue; _comparisonResult = new CompareLogic(_comparisonConfig).Compare(actualValue, _expectedValue); return _comparisonResult.AreEqual; }