public void TestRowIsValidIfCategoryColumnsArePresentButEmpty()
        {
            var dataUploadValidation = new DataUploadValidation();

            var table = GetBatchPholioDataTableWithCategoryColumns();

            table.Rows.Add(1, 2000, 1, -1, -1, AgeIds.AllAges, SexIds.Persons, AreaCodes.CountyUa_Cambridgeshire,
                1, 1, 1, 1, 1, 1, 1, ValueNoteIds.ThereIsDataQualityIssueWithThisValue, null, null);

            var uploadError = dataUploadValidation.ValidateCategoryTypeIdAndCategoryId(
                GetFirstRow(table), 1, new List<Category>());

            Assert.IsNull(uploadError, "The data was not valid");
        }
        public void TestRowIsNotValidIfCategoryValuesAreNotValid()
        {
            var dataUploadValidation = new DataUploadValidation();

            var table = GetBatchPholioDataTableWithCategoryColumns();

            table.Rows.Add(1, 2000, 1, -1, -1, AgeIds.AllAges, SexIds.Persons, AreaCodes.CountyUa_Cambridgeshire,
                1, 1, 1, 1, 1, 1, 1, ValueNoteIds.ThereIsDataQualityIssueWithThisValue, 1, 2);

            var uploadError = dataUploadValidation.ValidateCategoryTypeIdAndCategoryId(
                GetFirstRow(table), 1, new List<Category>{new Category
                {
                    CategoryTypeId = 1,
                    CategoryId = 3
                }});

            Assert.IsNotNull(uploadError, "The data should not be valid");
        }
        // Validate indicator details
        private void ValidateIndicatorDetails(DataTable dataTable, SimpleUpload simpleUpload, AllowedData allowedData)
        {
            var duv = new DataUploadValidation();

            GetIndicatorValue(dataTable, simpleUpload);
            GetYearValue(dataTable, simpleUpload);
            GetYearRange(dataTable, simpleUpload);
            GetQuarter(dataTable, simpleUpload);
            GetMonth(dataTable, simpleUpload);

            GetAgeId(dataTable, simpleUpload);
            duv.ValidateAgeId(simpleUpload.AgeId, null, allowedData.AgeIds);

            GetSexId(dataTable, simpleUpload);
            duv.ValidateSexId(simpleUpload.SexId, null, allowedData.SexIds);
        }
        private List<UploadValidationFailure> ValidateUploadedRow(DataRow uploadedRow, int rowNumber,
            List<string> allAreaCodes)
        {
            var duv = new DataUploadValidation();
            Exception dataConversionException;
            var uploadErrors = new List<UploadValidationFailure>();

            //Validate the AreaCode
            UploadValidationFailure uploadValidationFailure = duv.ValidateArea(uploadedRow, rowNumber, allAreaCodes);
            if (uploadValidationFailure != null)
            {
                //There was an error so log it
                uploadErrors.Add(uploadValidationFailure);
            }

            //Validate the Count
            dataConversionException = duv.ValidateExpectedDataType(uploadedRow, UploadColumnNames.Count,
                DataUploadValidation.DataType.NullableDouble);
            if (dataConversionException != null)
            {
                uploadErrors.Add(new UploadValidationFailure(rowNumber, UploadColumnNames.Count, "Invalid Count Figure",
                    dataConversionException.Message));
            }

            //Validate the Value
            dataConversionException = duv.ValidateExpectedDataType(uploadedRow, UploadColumnNames.Value,
                DataUploadValidation.DataType.NullableDouble);
            if (dataConversionException != null)
            {
                uploadErrors.Add(new UploadValidationFailure(rowNumber, UploadColumnNames.Value, "Invalid Value Figure",
                    dataConversionException.Message));
            }

            //Validate the LowerCI
            dataConversionException = duv.ValidateExpectedDataType(uploadedRow, UploadColumnNames.LowerCI,
                DataUploadValidation.DataType.NullableDouble);
            if (dataConversionException != null)
            {
                uploadErrors.Add(new UploadValidationFailure(rowNumber, UploadColumnNames.LowerCI,
                    "Invalid Lower CI Figure", dataConversionException.Message));
            }

            //Validate the UpperCI
            dataConversionException = duv.ValidateExpectedDataType(uploadedRow, UploadColumnNames.UpperCI,
                DataUploadValidation.DataType.NullableDouble);
            if (dataConversionException != null)
            {
                uploadErrors.Add(new UploadValidationFailure(rowNumber, UploadColumnNames.UpperCI,
                    "Invalid Upper CI Figure", dataConversionException.Message));
            }

            //Validate the Denominator
            dataConversionException = duv.ValidateExpectedDataType(uploadedRow, UploadColumnNames.Denominator,
                DataUploadValidation.DataType.NullableDouble);
            if (dataConversionException != null)
            {
                uploadErrors.Add(new UploadValidationFailure(rowNumber, UploadColumnNames.Denominator,
                    "Invalid Denominator Figure", dataConversionException.Message));
            }

            //Validate the ValueNoteId            
            dataConversionException = duv.ValidateExpectedDataType(uploadedRow, UploadColumnNames.ValueNoteId,
                DataUploadValidation.DataType.NullableDouble);

            if (dataConversionException != null)
            {
                uploadErrors.Add(new UploadValidationFailure(rowNumber, UploadColumnNames.ValueNoteId,
                    "Invalid Value Note Id", dataConversionException.Message));
            }
            else
            {
                var allowedData = new AllowedData(_profilesReader);
                var columnName = UploadColumnNames.ValueNoteId;
                //Ensure this is a value note id in the DB
                uploadValidationFailure = duv.ValidateValueNoteId((int)uploadedRow.Field<double>(columnName), rowNumber,
                    allowedData.ValueNoteIds);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    uploadErrors.Add(uploadValidationFailure);
                }
            }
            return uploadErrors;
        }
        private List<UploadValidationFailure> ValidateUploadedRow(DataRow row, int rowNumber, AllowedData allowedData)
        {
            rowNumber = rowNumber + 2;

            var duv = new DataUploadValidation();
            Exception dataConversionException;
            var validationFailures = new List<UploadValidationFailure>();

            //Validate the IndicatorID
            string columnName = UploadColumnNames.IndicatorId;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName, null));
            }

            //Validate the Indicator
            UploadValidationFailure uploadValidationFailure = duv.ValidateIndicator(row, rowNumber);
            if (uploadValidationFailure != null)
            {
                //There was an error so log it
                validationFailures.Add(uploadValidationFailure);
            }

            //Validate the Year Data Type
            columnName = UploadColumnNames.Year;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                //Ensure this is a valid Year value
                uploadValidationFailure = duv.ValidateYear(row, rowNumber);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            //Validate the YearRange
            columnName = UploadColumnNames.YearRange;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                uploadValidationFailure = duv.ValidateYearRange(row, rowNumber);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            //Validate the Quarter Data Type
            columnName = UploadColumnNames.Quarter;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                //Validate the Quarter Value
                uploadValidationFailure = duv.ValidateQuarter(row, rowNumber);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            //Validate the Month Data Type
            columnName = UploadColumnNames.Month;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                //Validate the Quarter Value
                uploadValidationFailure = duv.ValidateMonth(row, rowNumber);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            //Validate the AgeId Data Type
            columnName = UploadColumnNames.AgeId;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                //Validate the Age Id Value
                uploadValidationFailure = duv.ValidateAgeId((int)row.Field<double>(columnName), rowNumber,
                    allowedData.AgeIds);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            //Validate the SexId Data Type
            columnName = UploadColumnNames.SexId;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                //Ensure this is a valid Sex Id in the DB
                uploadValidationFailure = duv.ValidateSexId((int)row.Field<double>(columnName), rowNumber,
                    allowedData.SexIds);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            //Validate the AreaCode
            columnName = UploadColumnNames.AreaCode;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.String);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                //Ensure this is a valid Area Code in the DB
                uploadValidationFailure = duv.ValidateArea(row, rowNumber, allowedData.AreaCodes);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            //Validate the Count
            columnName = UploadColumnNames.Count;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.NullableDouble);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }

            //Validate the Value
            columnName = UploadColumnNames.Value;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Double);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }

            //Validate the LowerCI
            columnName = UploadColumnNames.LowerCI;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Double);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }

            //Validate the UpperCI
            columnName = UploadColumnNames.UpperCI;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Double);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }

            //Validate the Denominator
            columnName = UploadColumnNames.Denominator;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Double);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }

            //Validate the Denominator_2
            columnName = UploadColumnNames.Denominator2;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Double);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }

            //Validate the ValueNoteId
            columnName = UploadColumnNames.ValueNoteId;
            dataConversionException = duv.ValidateExpectedDataType(row, columnName,
                DataUploadValidation.DataType.Integer);
            if (dataConversionException != null)
            {
                validationFailures.Add(new UploadValidationFailure(rowNumber, columnName, "Invalid " + columnName,
                    dataConversionException.Message));
            }
            else
            {
                //Ensure this is a value note id in the DB
                uploadValidationFailure = duv.ValidateValueNoteId((int)row.Field<double>(columnName), rowNumber,
                    allowedData.ValueNoteIds);
                if (uploadValidationFailure != null)
                {
                    //There was an error so log it
                    validationFailures.Add(uploadValidationFailure);
                }
            }

            // Validate CategoryTypeId & CategoryId 
            uploadValidationFailure = duv.ValidateCategoryTypeIdAndCategoryId(row, rowNumber, allowedData.Categories);
            if (uploadValidationFailure != null)
            {
                validationFailures.Add(uploadValidationFailure);
            }

            return validationFailures;
        }