public void MergeWith_returns_same_instance_if_other_is_same_or_null() { var attribute = new IndexAttribute(); Assert.Same(attribute, attribute.MergeWith(attribute)); Assert.Same(attribute, attribute.MergeWith(null)); }
private static void MergeLists( ICollection <IndexAttribute> existingIndexes, IEnumerable <IndexAttribute> newIndexes, PropertyInfo propertyInfo) { foreach (IndexAttribute newIndex in newIndexes) { IndexAttribute index = newIndex; if (index == null) { throw new ArgumentNullException("indexAttribute"); } IndexAttribute other = existingIndexes.SingleOrDefault <IndexAttribute>((Func <IndexAttribute, bool>)(i => i.Name == index.Name)); if (other == null) { existingIndexes.Add(index); } else { CompatibilityResult compatibilityResult = index.IsCompatibleWith(other, false); if ((bool)compatibilityResult) { existingIndexes.Remove(other); existingIndexes.Add(index.MergeWith(other, false)); } else { string str = Environment.NewLine + "\t" + compatibilityResult.ErrorMessage; throw new InvalidOperationException(propertyInfo == (PropertyInfo)null ? Strings.ConflictingIndexAttribute((object)other.Name, (object)str) : Strings.ConflictingIndexAttributesOnProperty((object)propertyInfo.Name, (object)propertyInfo.ReflectedType.Name, (object)other.Name, (object)str)); } } } }
public void Add(string columnName, IndexAttribute index) { DebugCheck.NotEmpty(columnName); DebugCheck.NotNull(index); Debug.Assert(_index.Name == index.Name); if (_columns.ContainsKey(index.Order)) { throw new InvalidOperationException( Strings.OrderConflictWhenConsolidating(index.Name, _table, index.Order, _columns[index.Order], columnName)); } _columns[index.Order] = columnName; var compat = _index.IsCompatibleWith(index, ignoreOrder: true); if (!compat) { throw new InvalidOperationException(Strings.ConflictWhenConsolidating(index.Name, _table, compat.ErrorMessage)); } _index = _index.MergeWith(index, ignoreOrder: true); }