< Summary

Information
Class: ValidateLib.Metadata.Validators.RowTitlesValidator
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Validators\RowTitlesValidator.cs
Line coverage
15%
Covered lines: 3
Uncovered lines: 17
Coverable lines: 20
Total lines: 47
Line coverage: 15%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBlocks covered Blocks not covered
Validate(...)417
DoesReferencedColumnExist(...)021

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Validators\RowTitlesValidator.cs

#LineLine coverage
 1using ValidateLib.ErrorsAndWarnings.Warnings;
 2using ValidateLib.Metadata.Descriptors;
 3
 4namespace ValidateLib.Metadata.Validators
 5{
 6    internal class RowTitlesValidator : IMValidator<SchemaDescriptor>
 7    {
 8        public List<Warning> Validate(SchemaDescriptor schemaDescriptor)
 9        {
 110            List<Warning> warnings = new List<Warning>();
 111            if (schemaDescriptor.rowTitles is not null)
 12            {
 013                var primaryKeyDescriptor = schemaDescriptor.rowTitles._value;
 014                bool validPrimaryKeyDescriptor = true;
 015                string? nonExistingColumnName = null;
 016                foreach (var primaryKeyColumnName in primaryKeyDescriptor!)
 17                {
 018                    if (!DoesReferencedColumnExist(schemaDescriptor, primaryKeyColumnName))
 19                    {
 020                        nonExistingColumnName = primaryKeyColumnName;
 021                        validPrimaryKeyDescriptor = false;
 22                    }
 23                }
 024                if (!validPrimaryKeyDescriptor)
 25                {
 026                    warnings.Add(WarningFactory.GetReferencedCOlumnDoesNotExistWarning("rowTitles", nonExistingColumnNam
 027                    schemaDescriptor.rowTitles = null;
 28                }
 29            }
 130            return warnings;
 31        }
 32
 33        static bool DoesReferencedColumnExist(SchemaDescriptor schemaDescriptor, string referencedColumnName)
 34        {
 035            if (schemaDescriptor.columns is not null)
 36            {
 037                foreach (var column in schemaDescriptor.columns._value!)
 38                {
 039                    if (column.name is null) continue;
 040                    else if (column.name._value == referencedColumnName) return true;
 41                }
 042                return false;
 43            }
 044            else return false;
 045        }
 46    }
 47}