Example #1
0
        private void AddPrimaryKey(Field field)
        {
            PrimaryKeyValue primaryKeyValue;
            FieldIndex      key = field.Definition.GetIndex();

            if (_primaryKeys.ContainsKey(key))
            {
                primaryKeyValue = _primaryKeys[key];
            }
            else
            {
                primaryKeyValue = new PrimaryKeyValue(field);
                _primaryKeys.Add(key, primaryKeyValue);
            }
            primaryKeyValue.AddValue(field.Value);
        }
Example #2
0
        protected override void DoRun(Record record)
        {
            List <string> primaryKeyValues = new List <string>();

            foreach (Field field in record.Fields)
            {
                if (field.Definition.IsPartOfPrimaryKey())
                {
                    primaryKeyValues.Add(field.Value);
                }
            }
            PrimaryKeyValue primaryKeyValueForCurrentRecord = new PrimaryKeyValue(primaryKeyValues);

            RecordIndex recordIndex = record.Definition.GetIndex();

            if (!_primaryKeyValuesPerRecord.ContainsKey(recordIndex))
            {
                _primaryKeyValuesPerRecord.Add(recordIndex, new HashSet <PrimaryKeyValue>());
            }
            HashSet <PrimaryKeyValue> allPrimaryKeyValuesForRecord = _primaryKeyValuesPerRecord[recordIndex];

            // If null, this primary key value is already handled
            if (allPrimaryKeyValuesForRecord == null)
            {
                return;
            }

            // If list of primary key values already contains the value, it is not unique
            if (allPrimaryKeyValuesForRecord.Contains(primaryKeyValueForCurrentRecord))
            {
                if (!_nonUniqueprimaryKeyValuesPerRecord.ContainsKey(recordIndex))
                {
                    _nonUniqueprimaryKeyValuesPerRecord.Add(recordIndex, new HashSet <PrimaryKeyValue>());
                }
                _nonUniqueprimaryKeyValuesPerRecord[recordIndex].Add(primaryKeyValueForCurrentRecord);

                _primaryKeyValuesPerRecord[recordIndex].Remove(primaryKeyValueForCurrentRecord);
            }
            else
            {
                allPrimaryKeyValuesForRecord.Add(primaryKeyValueForCurrentRecord);
            }
        }
Example #3
0
        protected override List <TestResult> GetTestResults()
        {
            var results = new List <TestResult>();

            foreach (ForeignKeyValue foreignKeyValue in _foreignKeys)
            {
                if (_primaryKeys.ContainsKey(foreignKeyValue.ReferencingField))
                {
                    PrimaryKeyValue primaryKeyValue = _primaryKeys[foreignKeyValue.ReferencingField];
                    if (!primaryKeyValue.HasValue(foreignKeyValue.Value))
                    {
                        results.Add(CreateInvalidForeignKeyError(foreignKeyValue));
                    }
                }
                else
                {
                    results.Add(CreateInvalidForeignKeyError(foreignKeyValue));
                }
            }
            return(results);
        }
Example #4
0
 protected bool Equals(PrimaryKeyValue other)
 {
     return(_primaryKeyValues.SequenceEqual(other._primaryKeyValues));
 }