c24.Sqlizer.DirectoryValidation.Rules.FileNamePatternValidationRule.Validate C# (CSharp) Méthode

Validate() public méthode

public Validate ( string directoryPath ) : void
directoryPath string
Résultat void
        public void Validate(string directoryPath)
        {
            if (string.IsNullOrWhiteSpace(this.pattern))
            {
                return;
            }

            var regex = new Regex(this.pattern);

            var directory = new DirectoryInfo(directoryPath);

            var hasUnexpectedFiles = directory.GetFiles()
                .Any(f => !regex.IsMatch(f.Name));

            if (hasUnexpectedFiles)
            {
                throw new FileNameFormatException("File(s) with unexpected name format were found");
            }
        }
    }

Usage Example

        public void Should_Not_Throw_Exception_If_Pattern_Is_Null_Or_Empty()
        {
            // arrange
            var workingDirectory = TestFileSystem.CreateTempWorkingDirectory();

            TestFileSystem.CreateFile(workingDirectory, "Script_01.sql");
            TestFileSystem.CreateFile(workingDirectory, "Script_02.sql");

            var rule = new FileNamePatternValidationRule(pattern: null);
            // act & assert
            Action action = () => rule.Validate(workingDirectory);

            action.ShouldNotThrow();
        }
All Usage Examples Of c24.Sqlizer.DirectoryValidation.Rules.FileNamePatternValidationRule::Validate
FileNamePatternValidationRule