public void IsReadableTest()
 {
     Assert.True(FileSupport.IsFileReadable(_fixture.UnwritableFilePath));
     Assert.True(FileSupport.IsFileReadable(_fixture.WritableFilePath));
     Assert.False(FileSupport.IsFileReadable(_fixture.UnreadableFilePath));
     Assert.False(FileSupport.IsFileReadable(_fixture.InvalidFilePath));
 }
Exemple #2
0
        public override CommandResult Validate(CommandArg arg)
        {
            CommandResult result = base.Validate(arg);
            string        path   = arg.Value;

            if (!Path.IsPathFullyQualified(path))
            {
                try
                {
                    path = Path.Combine(GeneralParameters.Instance.WorkingFolder, path);
                }
                catch (Exception ex)
                {
                    result.Append(new CommandResult(false, "Invalid path:", ex));
                }
            }
            if (result.Succeeded)
            {
                if (!FileSupport.IsFileReadable(path))
                {
                    return(new CommandResult(false, $"File '{path}' is not readable."));
                }
                arg.ResolvedValue = path;
            }
            return(result);
        }
        public override CommandResult Validate(CommandArg arg)
        {
            CommandResult result = base.Validate(arg);
            string        path   = arg.Value;

            if (HasDefaultExt && Path.GetExtension(path) == "")
            {
                path += DefaultExt;
            }
            if (!Path.IsPathFullyQualified(path))
            {
                try
                {
                    path = Path.Combine(GeneralParameters.Instance.WorkingFolder, path);
                }
                catch (Exception ex)
                {
                    result.Append(new CommandResult(false, "Invalid path:", ex));
                }
            }
            if (result.Succeeded)
            {
                if (Exists && !File.Exists(path))
                {
                    return(new CommandResult(false, $"File '{path}' does not exist."));
                }
                if (Exists && Folder && !Directory.Exists(path))
                {
                    return(new CommandResult(false, $"Folder '{path}' does not exist."));
                }
                if (Readable && !FileSupport.IsFileReadable(path))
                {
                    return(new CommandResult(false, $"File '{path}' is not readable."));
                }
                if (Writable && !FileSupport.IsFileWritable(path))
                {
                    return(new CommandResult(false, $"File '{path}' is not writable."));
                }
                arg.ResolvedValue = path;
            }
            return(result);
        }