示例#1
0
        protected override void DoValidation(ValidationResult result, RepositoryInfo repositoryInfo, Action <ValidationResult> notify = null)
        {
            var propertyValue      = _projectFileHelper.GetPropertyValue(_propertyName);
            var otherPropertyValue = _projectFileHelper.GetPropertyValue(_otherPropertyName);

            if (string.CompareOrdinal(propertyValue, otherPropertyValue) == 0 && propertyValue.Length > 0)
            {
                result.AddResult(ResultLevel.Passed,
                                 string.Format(Resources.CheckIdenticalProjectFileRule_DoValidation_Properties_in_project_are_identical,
                                               _projectFileHelper.GetProjectShortName(),
                                               _propertyName,
                                               _otherPropertyName,
                                               propertyValue,
                                               _projectFileHelper.GetProjectInfo()), notify);
            }
            else
            {
                result.AddResult(ResultLevel.NotPassed,
                                 string.Format(Resources.CheckIdenticalProjectFileRule_DoValidation_Properties_in_project_are_not_identical,
                                               _projectFileHelper.GetProjectShortName(),
                                               _propertyName,
                                               _otherPropertyName,
                                               propertyValue,
                                               otherPropertyValue,
                                               _projectFileHelper.GetProjectInfo()), notify);
            }
        }
        public void ShouldAddValidationResultWithErrors()
        {
            var errors = new List<Error> { CreateError(), CreateError(), CreateError() };
            var validation = new ValidationResult();
            validation.AddError(errors);

            validationResult.AddResult(validation);
            validationResult.Errors.Should().BeEquivalentTo(errors);
        }
        public void ShouldAddItensResultIfIsSuccess()
        {
            var item       = CreateItem();
            var validation = new ValidationResult <FakeClass>();

            validation.AddItem(item);

            validationResult.AddResult(validation);
            validationResult.Itens.Should().BeEquivalentTo(new List <FakeClass> {
                item
            });
        }
示例#4
0
        public override ValidationResult Validate(RepositoryInfo repositoryInfo, Action <ValidationResult> notify = null)
        {
            var    result = new ValidationResult(this);
            var    exist  = FileSystemHelper.GetFolders(repositoryInfo.RepositoryRootPath, RelativePath).Any();
            string message;

            if (!exist && CheckType == CheckType.MustExist || exist && CheckType == CheckType.MustNotExist)
            {
                message = string.Format("Folder '{0}' {1}.", RelativePath, exist ? Resources.FolderRule_Validate_exists_This_folder_should_not_exist
                                        : Resources.FolderRule_Validate_does_not_exist_This_folder_must_exist);
                result.AddResult(ResultLevel.NotPassed, message);
                return(result);
            }
            message = string.Format("Folder '{0}' {1}.", RelativePath, exist ? Resources.FolderRule_Validate_exists : Resources.FolderRule_Validate_does_not_exist);
            result.AddResult(ResultLevel.Passed, message);

            return(result);
        }
        protected override void DoValidation(ValidationResult result, RepositoryInfo repositoryInfo, Action <ValidationResult> notify = null)
        {
            var configurationNames = _projectFileHelper.GetConfigurations();

            if (configurationNames.Any(cn => String.CompareOrdinal(cn, _expectedConfiguration) == 0))
            {
                result.AddResult(ResultLevel.Passed,
                                 string.Format(Resources.ConfigurationExistsProjectFileRule_Validate_Project_contains_expected_configuration,
                                               _projectFileHelper.GetProjectShortName(),
                                               _expectedConfiguration,
                                               _projectFileHelper.GetProjectInfo(_expectedConfiguration)), notify);
            }
            else
            {
                result.AddResult(ResultLevel.NotPassed,
                                 string.Format("Project '{0}' does not contain expected configuration '{1}'. {2}",
                                               _projectFileHelper.GetProjectShortName(),
                                               _expectedConfiguration,
                                               _projectFileHelper.GetProjectInfo(_expectedConfiguration)), notify);
            }
        }
示例#6
0
        public override ValidationResult Validate(RepositoryInfo repositoryInfo, Action <ValidationResult> notify = null)
        {
            var result        = new ValidationResult(this);
            var searchPattern = RelativePath.Split('\\').Last();
            var folderPattern = RelativePath.Replace(searchPattern, string.Empty);

            var foldersToCheck = new List <string>();

            if (!IsRecursive)
            {
                var folder = Path.Combine(repositoryInfo.RepositoryRootPath, folderPattern);
                foldersToCheck.Add(folder.TrimEnd('\\'));
            }
            else
            {
                foldersToCheck.AddRange(FileSystemHelper.GetFolders(repositoryInfo.RepositoryRootPath, folderPattern));
            }

            var exist = false;

            foreach (var folder in foldersToCheck)
            {
                exist = exist || FileSystemHelper.Exists(folder, searchPattern);
            }

            string message;

            if (!exist && CheckType == CheckType.MustExist || exist && CheckType == CheckType.MustNotExist)
            {
                message = string.Format("File '{0}' {1}.", RelativePath, exist ? Resources.FileRule_Validate_exists__This_file_should_not_exist_
                                        : Resources.FileRule_Validate_does_not_exist__This_file_must_exist_);
                result.AddResult(ResultLevel.NotPassed, message);
                return(result);
            }

            message = string.Format("File '{0}' {1}.", RelativePath, exist ? Resources.FileRule_Validate_exists_ : Resources.FileRule_Validate_does_not_exist_);
            result.AddResult(ResultLevel.Passed, message);
            return(result);
        }
示例#7
0
        protected override void DoValidation(ValidationResult result, RepositoryInfo repositoryInfo, Action <ValidationResult> notify = null)
        {
            var propertyValue = _projectFileHelper.GetPropertyValue(_propertyName);

            if (string.CompareOrdinal(propertyValue, _value) == 0 && _propertyName != EmptyPropertyName)
            {
                result.AddResult(ResultLevel.Passed,
                                 string.Format("Property '{0}' in project {1} has the expected value. ('{2}'). {3}",
                                               _propertyName,
                                               _projectFileHelper.GetProjectShortName(),
                                               propertyValue,
                                               _projectFileHelper.GetProjectInfo()), notify);
            }
            else
            {
                result.AddResult(ResultLevel.NotPassed,
                                 string.Format("Property '{0}' in project {1} has unexpected value. Was '{2}' but expected {3}. {4}",
                                               _propertyName,
                                               _projectFileHelper.GetProjectShortName(),
                                               propertyValue,
                                               _value,
                                               _projectFileHelper.GetProjectInfo()), notify);
            }
        }
示例#8
0
        public ValidationResult IsValueValid <T>(Field <T> field, T item, object value, int row, int column, MessageErrors messageErrors)
        {
            var validationResult = new ValidationResult();

            if (!IsRequiredFieldFilled(field, value))
            {
                validationResult.AddError(new Error(messageErrors.EmptyRequiredField(field.Name), row, column));
            }

            foreach (var validation in field.GetValidations())
            {
                validationResult.AddResult(validation.IsValid(item, value, row, column));
            }

            return(validationResult);
        }
示例#9
0
        public ValidationResult SetValue <T>(Field <T> field, T item, object value, int row, int column, MessageErrors messageErrors)
        {
            var validationColumn = new ValidationResult();

            try
            {
                value = converter.Convert(field.PropertyInfo.Type, value);
            }
            catch
            {
                var error = new Error(messageErrors.InvalidParseValue(field.Name), row, column);
                validationColumn.AddError(error);
            }

            if (!validationColumn.IsSuccess)
            {
                return(validationColumn);
            }

            validationColumn.AddResult(IsValueValid(field, item, value, row, column, messageErrors));

            try
            {
                if (validationColumn.IsSuccess)
                {
                    SetValue(field, item, field.PropertyInfo.Name, value);
                }
            }
            catch
            {
                var error = new Error(messageErrors.InvalidItemValue(field.Name, value), row, column);
                validationColumn.AddError(error);
            }

            return(validationColumn);
        }
示例#10
0
        private void CheckOneOutputPath(string configuration,
                                        string repoRoot,
                                        string expectedOutputPath,
                                        ValidationResult result,
                                        Action <ValidationResult> notify)
        {
            // Must reload the project to make the evaluated values in sync with
            // the configuration under test:

            try
            {
                LoadProject(_projectFileFullName, configuration);

                var    item = _project.GetItems("_OutputPathItem").FirstOrDefault();
                string message;
                if (item == null)
                {
                    message = string.Format(Resources.ProjectFileHelper_CheckOne_Can_not_get_output_path, GetProjectInfo(configuration));
                    result.AddResult(ResultLevel.NotPassed, message, notify);
                    return;
                }
                var outputPath = item.EvaluatedInclude;
                if (Path.IsPathRooted(outputPath) || !outputPath.StartsWith("."))
                {
                    message = string.Format(Resources.ProjectFileHelper_CheckOne_Output_path_must_be_a_relative_path, outputPath,
                                            GetProjectInfo(configuration));
                    result.AddResult(ResultLevel.NotPassed, message, notify);
                    return;
                }
                //($repoRoot)\($expectedOutputPath)\($configuration)\($targetFrameworkVersion)\($projectName)

                repoRoot           = repoRoot.Trim('\\');
                expectedOutputPath = expectedOutputPath.Trim('\\');
                var targetFrameworkVersion = GetTargetFrameworkVersion(_project);

                // We are using the assembly name here for the sake of simplicity. However please note
                // that other rules are forcing project file name to be identical with assembly name and root namespace name

                var projectName   = _assemblyName;
                var projectFolder = Path.GetDirectoryName(_projectFileFullName).Trim('\\');

                var expectedValue = string.Format(@"{0}\{1}\{2}\{3}\{4}", repoRoot, expectedOutputPath, configuration,
                                                  targetFrameworkVersion, projectName).ToLower();

                var actualValue = Path.GetFullPath(Path.Combine(projectFolder, outputPath)).Trim('\\').ToLower();

                if (string.Compare(expectedValue, actualValue, StringComparison.Ordinal) != 0)
                {
                    message = string.Format(Resources.ProjectFileHelper_CheckOne_Output_path_was_evaluated_to, actualValue,
                                            expectedValue, GetProjectInfo(configuration));
                    result.AddResult(ResultLevel.NotPassed, message, notify);
                    return;
                }
                message = string.Format(
                    Resources.ProjectFileHelper_CheckOneOutputPath_OutputPath_conforms_to_the_required_standards,
                    GetProjectInfo(configuration));
                result.AddResult(ResultLevel.Passed, message, notify);
            }
            catch (ProjectFileException e)
            {
                result.AddResult(ResultLevel.NotPassed, e.Message, notify);
            }
            catch (Exception e)
            {
                result.AddResult(ResultLevel.NotPassed, string.Format("Unexpected exception: {0}", e.Message), notify);
            }
        }
示例#11
0
        public override ValidationResult Validate(RepositoryInfo repositoryInfo, Action <ValidationResult> notify = null)
        {
            var result    = new ValidationResult(this);
            var fileNames = _fileSystemHelper.GetFiles(repositoryInfo.RepositoryRootPath, _fileNamePattern, _sourceFileFilters).ToList();

            string message;

            var backupFileName = string.Empty;

            if (_isBackupEnabled)
            {
                try
                {
                    backupFileName = Backup(repositoryInfo.RepositoryRootPath, fileNames);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_rule_can_not_create_backup_file, TransformMessage.ToLower());
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    return(result);
                }
            }

            foreach (var fileName in fileNames)
            {
                string code;
                try
                {
                    code = _fileSystemHelper.ReadAllText(fileName);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_Can_not_read_file, TransformingMessage.ToLower(), fileName);
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    continue;
                }

                if (_isBackupEnabled)
                {
                    if (!BackupExists(backupFileName, fileName, code))
                    {
                        message = string.Format(Resources.TransformRule_Validate_Not_file_because_can_not_verify_backup, TransformingMessage.ToLower(), fileName);
                        result.AddResult(ResultLevel.Error, message, notify);
                        Logger.Error(message);
                        continue;
                    }
                }

                string transformedCode;
                try
                {
                    transformedCode = Transform(code, fileName, notify);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_error_in_file, TransformerMessage, e.Message, fileName);
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    continue;
                }
                try
                {
                    _fileSystemHelper.WriteAllText(fileName, transformedCode, Encoding.UTF8);
                }
                catch (Exception e)
                {
                    message = string.Format(Resources.TransformRule_Validate_Code_error_in_file, TransformingMessage.ToLower(), fileName);
                    result.AddResult(ResultLevel.Error, message, notify);
                    Logger.Error(message, e);
                    continue;
                }

                message = string.Format(Resources.TransformRule_Validate_File_successfully, TransformedMessage.ToLower(), fileName);
                result.AddResult(ResultLevel.Passed, message, notify);
            }
            return(result);
        }