/// <summary> /// Apply a <see cref="CompareTarget"/> to a checker for some entities. /// </summary> /// <param name="target"></param> /// <param name="checker"></param> /// <param name="expected"></param> /// <param name="candidate"></param> /// <param name="objectName"></param> protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName) { switch (target) { case CompareTarget.Ignore: break; case CompareTarget.Id: CheckId(expected, candidate, objectName + ".Id"); break; case CompareTarget.Entity: checker.Check(expected, candidate, objectName); break; case CompareTarget.Dictionary: Check(checker, expected as IDictionary, candidate as IDictionary, objectName); break; case CompareTarget.Count: case CompareTarget.Collection: Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName); break; case CompareTarget.Value: Check(expected, candidate, objectName); break; default: throw new NotSupportedException("Cannot perform comparison: " + target); } }
/// <summary> /// Creates a new instance of the <see cref="Conventions{T}" /> class. /// </summary> public Conventions(CompareTarget defaultCompareTarget = Checking.CompareTarget.Unknown) { Comparer = new Conventions <TSource, Func <object, object, bool> >(); CompareTarget = new Conventions <TSource, CompareTarget> { DefaultConvention = defaultCompareTarget }; }
private void CheckProperty(string name, CompareTarget expected) { var checker = new ParentChecker(); var property = checker[name]; Assert.AreEqual(expected, property.CompareTarget); }
protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName) { switch (target) { case CompareTarget.Id: CheckId(expected, candidate, objectName + ".Id"); break; case CompareTarget.Entity: checker.Check(expected, candidate, objectName); break; case CompareTarget.Count: case CompareTarget.Collection: this.Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName); break; default: if (CheckNullNotNull(expected, candidate, objectName)) { return; } if (!expected.Equals(candidate)) { throw new PropertyCheckException(objectName, expected, candidate); } break; } }
private void CheckProperty <T>(string name, CompareTarget expected) { var builder = new CheckerBuilder(CheckerFactory); var checker = (Checker <T>)builder.Build(typeof(T)); var property = checker[name]; Assert.AreEqual(expected, property.CompareTarget); }
/// <summary> /// Include the property in the comparison test. /// </summary> /// <param name="propertyInfo">PropertyInfo to use</param> /// <param name="compareTarget"></param> /// <returns>A new <see cref="PropertyCheckExpression" /> created from the <see cref="PropertyInfo" /></returns> protected PropertyCheckExpression Compare(PropertyInfo propertyInfo, CompareTarget compareTarget) { var pc = this.Find(propertyInfo); if (pc == null) { // Add the new check pc = new PropertyCheck(propertyInfo, compareTarget); this.Properties.Add(pc); } else { // Update to the supplied target pc.CompareTarget = compareTarget; } return(new PropertyCheckExpression(pc)); }
public void compare_two_objects_without_not_implementing_comparable_throws_exception() { var obj1 = new CompareTarget { Nested = new CompareTarget { Value = 3 } }; var obj2 = new CompareTarget { Nested = new CompareTarget { Value = 12 } }; var comparer = PropertyOrderComparer.For <CompareTarget>(x => x.Nested); Assert.Throws <ArgumentException>(() => comparer.Compare(obj1, obj2)); }
private void CheckProperty(string name, CompareTarget expected) { var checker = new ParentChecker(); var property = checker[name]; Assert.AreEqual(expected, property.CompareTarget); }
/// <copydocfrom cref="IConventions{T}.Clear" /> public void Clear() { Comparer.Clear(); CompareTarget.Clear(); }
/// <summary> /// Create a new instance of the <see cref="PropertyCheck" /> class /// </summary> /// <param name="info">PropertyInfo to use</param> /// <param name="compareTarget">CompareTarget to use</param> public PropertyCheck(PropertyInfo info, CompareTarget compareTarget) { this.Info = info; this.CompareTarget = compareTarget; }
/// <summary> /// Create a new instance of the <see cref="PropertyCheck" /> class /// </summary> /// <param name="info">PropertyInfo to use</param> /// <param name="compareTarget">CompareTarget to use</param> public PropertyCheck(PropertyInfo info, CompareTarget compareTarget) { this.Info = info; this.CompareTarget = compareTarget; }
/// <summary> /// 判零规则的构造函数 /// </summary> /// <param name="compareTarget">比较类型</param> /// <param name="comparedIndex"></param> /// <param name="zeroTypeFlag"></param> public ZeroRule(CompareTarget compareTarget, FieldIndex comparedIndex, ZeroTypeFlag zeroTypeFlag) { this.CompareTarget = compareTarget; this.ZeroTypeFlag = zeroTypeFlag; this.ComparedIndex = comparedIndex; }
/// <summary> /// Register a <see cref="CompareTarget"/> convention based on property information. /// </summary> /// <param name="conventions"></param> /// <param name="func"></param> /// <param name="value"></param> public static void Convention(this IConventions <PropertyInfo> conventions, Func <PropertyInfo, bool> func, CompareTarget value) { conventions.CompareTarget.Register(func, value); }
/// <summary> /// Create a new instance of the <see cref="PropertyCheck" /> class /// </summary> /// <param name="info">PropertyInfo to use</param> /// <param name="compareTarget">CompareTarget to use</param> public PropertyCheck(PropertyInfo info, CompareTarget compareTarget) { Info = info; CompareTarget = compareTarget; }
/// <summary> /// Register a <see cref="CompareTarget"/> convention for a type. /// </summary> /// <typeparam name="T">Type to use</typeparam> /// <param name="conventions"></param> /// <param name="target">CompareTarget value to return</param> public static void Convention <T>(this IConventions <Type> conventions, CompareTarget target) { conventions.Convention(typeof(T), target); }
/// <summary> /// Register an explicit <see cref="CompareTarget"/> to use for a type. /// </summary> /// <param name="conventions">Comparer to register against</param> /// <param name="type">Type to use</param> /// <param name="target">CompareTarget to use</param> public static void Register(this IConventions <Type, CompareTarget> conventions, Type type, CompareTarget target) { conventions.Register(x => x.FullName == type.FullName, target); }
/// <summary> /// Register a <see cref="CompareTarget"/> convention for a type. /// </summary> /// <typeparam name="T">Type to use</typeparam> /// <param name="target">CompareTarget value to return</param> public void Convention <T>(CompareTarget target) { TypeConventions.Convention <T>(target); }
/// <summary> /// Create a new instance of the <see cref="PropertyCheck" /> class /// </summary> /// <param name="info">PropertyInfo to use</param> /// <param name="compareTarget">CompareTarget to use</param> public PropertyCheck(PropertyInfo info, CompareTarget compareTarget) { Info = info; CompareTarget = compareTarget; }
/// <summary> /// Apply a <see cref="CompareTarget"/> to a checker for some entities. /// </summary> /// <param name="target"></param> /// <param name="checker"></param> /// <param name="expected"></param> /// <param name="candidate"></param> /// <param name="objectName"></param> protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName) { switch (target) { case CompareTarget.Ignore: break; case CompareTarget.Id: CheckId(expected, candidate, objectName + ".Id"); break; case CompareTarget.Entity: checker.Check(expected, candidate, objectName); break; case CompareTarget.Count: case CompareTarget.Collection: Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName); break; case CompareTarget.Value: Check(expected, candidate, objectName); break; default: throw new NotSupportedException("Cannot perform comparison: " + target); } }
public void Register(Type type, CompareTarget target) { this.types.Add(type, target); }
public void Register(Type type, CompareTarget target) { this.types.Add(type, target); }
/// <summary> /// Register a <see cref="CompareTarget"/> convention for a type. /// </summary> /// <param name="type">Type to use</param> /// <param name="target">CompareTarget value to return</param> public void Convention(Type type, CompareTarget target) { TypeConventions.CompareTarget.Register(type, target); }
public void Convention(Type type, CompareTarget target) { Conventions.Convention(type, target); }
/// <summary> /// Register a <see cref="CompareTarget"/> convention for a type. /// </summary> /// <param name="conventions"></param> /// <param name="type">Type to use</param> /// <param name="target">CompareTarget value to return</param> public static void Convention(this IConventions <Type> conventions, Type type, CompareTarget target) { conventions.CompareTarget.Register(type, target); }
/// <summary> /// Register a <see cref="CompareTarget"/> convention based on type information. /// </summary> /// <param name="func"></param> /// <param name="value"></param> public void Convention(Func <Type, bool> func, CompareTarget value) { TypeConventions.Convention(func, value); }
/// <summary> /// Register a <see cref="CompareTarget"/> convention based on type information. /// </summary> /// <param name="conventions"></param> /// <param name="func"></param> /// <param name="value"></param> public static void Convention(this IConventions <Type> conventions, Func <Type, bool> func, CompareTarget value) { conventions.CompareTarget.Register(func, value); }
/// <summary> /// Register an equality comparer convention based on property information. /// </summary> /// <param name="func"></param> /// <param name="value"></param> public void Convention(Func <PropertyInfo, bool> func, CompareTarget value) { PropertyConventions.CompareTarget.Register(func, value); }
private void CheckTargetType <T>(PropertyConventions targeter, Expression <Func <T, object> > propertyExpression, CompareTarget target) { var pi = propertyExpression.GetPropertyInfo(); Assert.AreEqual(target, targeter.CompareTarget.Convention(pi)); }
protected void Check(CompareTarget target, IChecker checker, object expected, object candidate, string objectName) { switch (target) { case CompareTarget.Id: CheckId(expected, candidate, objectName + ".Id"); break; case CompareTarget.Entity: checker.Check(expected, candidate, objectName); break; case CompareTarget.Count: case CompareTarget.Collection: this.Check(checker, expected as IEnumerable, candidate as IEnumerable, objectName); break; default: if (CheckNullNotNull(expected, candidate, objectName)) { return; } if (!expected.Equals(candidate)) { throw new PropertyCheckException(objectName, expected, candidate); } break; } }