Ejemplo n.º 1
0
        public bool ExistsEncodingFile()
        {
            string tempFilePath = GetEncodingTempFilePath();
            bool   isExist      = _fileSystem.FileExists(tempFilePath);

            return(isExist);
        }
Ejemplo n.º 2
0
 ///<summary>
 /// Outputs the token replaced to a file
 ///</summary>
 ///<param name="destination">the destination path</param>
 ///<exception cref="IOException">Occurs if the file already exists</exception>
 public void To(string destination)
 {
     if (_fileSystemWrapper.FileExists(destination))
     {
         throw new IOException("File already exists. Delete it first");
     }
     _fileSystemWrapper.WriteAllText(destination, Input);
 }
Ejemplo n.º 3
0
        public Option <LocalChromeDriverInfo> FindDriverInfo(string driverDirectory)
        {
            var driverDirectoryInfo = new DirectoryInfo(driverDirectory);

            var driverExists = _fileSystemWrapper.FileExists(Constants.DriverFileName, driverDirectoryInfo);

            if (driverExists)
            {
                return(Option.Some(new LocalChromeDriverInfo(driverDirectoryInfo, _shellCommandExecutor)));
            }

            return(Option.None <LocalChromeDriverInfo>());
        }
        public MsBuildPath LocateMostRecentMsBuildPath()
        {
            var searchPaths = new List <string>();

            foreach (var location in MsBuildLocations)
            {
                searchPaths.Add(location);
                if (Fs.FileExists(location))
                {
                    return(new MsBuildPath(location, new List <string>(searchPaths)));
                }
            }

            return(new MsBuildPath(MsBuildLocations.Last(), new List <string>(searchPaths)));
        }
Ejemplo n.º 5
0
        public int?[] GetOriginalFileLineExecutionCounts(int?[] generatedSourceLineExecutionCounts, int sourceLineCount, ReferencedFile referencedFile)
        {
            if (generatedSourceLineExecutionCounts == null)
            {
                throw new ArgumentNullException("generatedSourceLineExecutionCounts");
            }
            if (referencedFile == null)
            {
                throw new ArgumentNullException("referencedFile");
            }
            else if (string.IsNullOrWhiteSpace(referencedFile.SourceMapFilePath))
            {
                return(generatedSourceLineExecutionCounts);
            }
            else if (!fileSystem.FileExists(referencedFile.SourceMapFilePath))
            {
                throw new ArgumentException("mapFilePath", string.Format("Cannot find map file '{0}'", referencedFile.SourceMapFilePath));
            }

            var consumer = this.GetConsumer(fileSystem.GetText(referencedFile.SourceMapFilePath));

            var accumulated = new List <int?>(new int?[sourceLineCount + 1]);

            for (var i = 1; i < generatedSourceLineExecutionCounts.Length; i++)
            {
                int?generatedCount = generatedSourceLineExecutionCounts[i];
                if (generatedCount == null)
                {
                    continue;
                }

                var matches = consumer.OriginalPositionsFor(i);
                if (matches.Any())
                {
                    foreach (var match in matches)
                    {
                        if (match.File.ToLower() != fileSystem.GetFileName(referencedFile.Path.ToLower()))
                        {
                            continue;
                        }

                        accumulated[match.LineNumber] = (accumulated[match.LineNumber] ?? 0) + generatedCount.Value;
                    }
                }
            }

            return(accumulated.ToArray());
        }
        public HandlerResponseMessage HandleCommandLineOptions(ICommandLineOptions commandLineOptions)
        {
            var configFileExists = fileSystem.FileExists(defaultConfigFilePath);

            if (!configFileExists || commandLineOptions.Force)
            {
                CreateConfigFile();
                reporter.Report($@"Created default config file at {defaultConfigFilePath}");
            }
            else
            {
                reporter.Report($"Default config file already exists at: {defaultConfigFilePath} use the '--init' option combined with the '--force' option to overwrite");
            }

            return(new HandlerResponseMessage(true, false));
        }
Ejemplo n.º 7
0
        public HandlerResponseMessage HandleCommandLineOptions(ICommandLineOptions commandLineOptions)
        {
            commandLineOptions.ConfigFile = commandLineOptions.ConfigFile.Trim();
            if (!fileSystem.FileExists(commandLineOptions.ConfigFile))
            {
                reporter.Report($"Config file not found at: {commandLineOptions.ConfigFile} use the '--init' option to create if one does not exist or the '--force' option to overwrite");
            }

            if (!commandLineOptions.LintPath.Any())
            {
                reporter.Report(commandLineOptions.GetUsage());
                return(new HandlerResponseMessage(true, false));
            }

            return(new HandlerResponseMessage(true, true));
        }
Ejemplo n.º 8
0
 public IList <string> GetAllFilesMatching(string filter)
 {
     Console.WriteLine(filter);
     Debug.WriteLine(filter);
     //a full file i.e. c:\temp\file1.txt
     if ((filter.LastIndexOf("*") == -1) && (Path.HasExtension(filter)))
     {
         var list = new List <String>();
         if (_fileSystemWrapper.FileExists(filter))
         {
             list.Add(filter);
         }
         return(list);
     }
     _parser.Parse(filter);
     return(GetAllFilesMatching(_parser.Folder, _parser.SearchPattern, _parser.Recursive));
 }
Ejemplo n.º 9
0
        public string FindSourceMap(string sourceFilePath)
        {
            if (sourceFilePath == null)
            {
                throw new ArgumentNullException("sourceFilePath");
            }

            // Start with the filename convention of having .map suffixed
            var mapPath = sourceFilePath + ".map";

            if (fileSystemWrapper.FileExists(mapPath))
            {
                return(mapPath);
            }

            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Finds a Chutzpah test settings file given a directory. Will recursively scan current direcotry
        /// and all directories above until it finds the file
        /// </summary>
        /// <param name="currentDirectory">the directory to start searching from</param>
        /// <returns>Eithe the found setting file path or null</returns>
        public string FindTestSettingsFile(string currentDirectory)
        {
            string settingsFilePath = null;

            while (!string.IsNullOrEmpty(currentDirectory))
            {
                settingsFilePath = Path.Combine(currentDirectory, Constants.SettingsFileName);
                if (fileSystem.FileExists(settingsFilePath))
                {
                    break;
                }
                else
                {
                    settingsFilePath = null;
                    currentDirectory = Path.GetDirectoryName(currentDirectory);
                }
            }

            return(settingsFilePath);
        }
Ejemplo n.º 11
0
        public CompilerCache(IFileSystemWrapper fileSystem, IBinarySerializer binarySerializer)
        {
            hasher                = new Hasher();
            compilerCache         = new ConcurrentDictionary <string, Tuple <DateTime, string> >();
            filesystem            = fileSystem;
            this.binarySerializer = binarySerializer;
            if (string.IsNullOrEmpty(GlobalOptions.Instance.CompilerCacheFile))
            {
                filename = Path.Combine(filesystem.GetTemporaryFolder(Constants.ChutzpahCompilerCacheFolder),
                                        Constants.ChutzpahCompilerCacheFileName);
            }
            else
            {
                filename = GlobalOptions.Instance.CompilerCacheFile;
            }

            if (fileSystem.FileExists(filename) && GlobalOptions.Instance.CompilerCacheFileMaxSizeBytes > 0)
            {
                using (var cacheStream = fileSystem.Open(filename, FileMode.Open, FileAccess.Read))
                {
                    compilerCache = DeserializeObject(cacheStream);
                }
            }
        }
Ejemplo n.º 12
0
        public CompilerCache(IFileSystemWrapper fileSystem, IBinarySerializer binarySerializer)
        {
            hasher = new Hasher();
            compilerCache = new ConcurrentDictionary<string, Tuple<DateTime, string>>();
            filesystem = fileSystem;
            this.binarySerializer = binarySerializer;
            if (string.IsNullOrEmpty(GlobalOptions.Instance.CompilerCacheFile))
            {
                filename = Path.Combine(filesystem.GetTemporaryFolder(Constants.ChutzpahCompilerCacheFolder),
                                        Constants.ChutzpahCompilerCacheFileName);
            }
            else
            {
                filename = GlobalOptions.Instance.CompilerCacheFile;
            }

            if (fileSystem.FileExists(filename) && GlobalOptions.Instance.CompilerCacheFileMaxSizeBytes > 0)
            {
                using (var cacheStream = fileSystem.Open(filename, FileMode.Open, FileAccess.Read))
                {
                    compilerCache = DeserializeObject(cacheStream);
                }
            }
        }
Ejemplo n.º 13
0
 public void IsValidIfFileExists(bool fileExists)
 {
     _fileSystemWrapper.FileExists(Arg.Any <string>()).Returns(fileExists);
     _dataStore.FileName = "a";
     Assert.AreEqual(fileExists, _dataStore.FileNameIsValid);
 }