internal DependencyConfig LoadConfigFile(GetDependenciesOptions options, string fileName) { if (options.Force) { Log.Debug("Config file not found. Using command line BuildConfigId: {0}", options.BuildConfigId); return(new DependencyConfig { BuildConfigId = options.BuildConfigId }); } string fullPath = GetConfigFullPath(options, fileName); Log.Debug("Loading config file: {0}", fullPath); if (_fileSystem.FileExists(fullPath)) { string json = _fileSystem.ReadAllTextFromFile(fullPath); return(JsonConvert.DeserializeObject <DependencyConfig>(json)); } throw new Exception( string.Format( "Unable to find {0}. Specify Force option on command line to create the file or provide a proper path using the ConfigFilePath option.", fullPath)); }
internal void Should_initialize_new_config_from_command_line_options_When_config_file_does_not_exist( TestResolveDependencyCommand command, GetDependenciesOptions options, string fileName) { command.FileSystem.FileExists(Arg.Any <string>()).Returns(false); DependencyConfig config = command.LoadConfigFile(options, fileName); Assert.Equal(options.BuildConfigId, config.BuildConfigId); Assert.Empty(config.BuildInfos); }
internal void Should_throw_exception_if_Force_is_false_AND_Config_file_not_found_When_config_file_does_not_exist( TestResolveDependencyCommand command, GetDependenciesOptions options, string fileName) { command.FileSystem.FileExists(Arg.Any <string>()).Returns(false); //BuildConfigId set to null will cause Force == false options.BuildConfigId = null; Exception exception = Assert.Throws <Exception>(() => command.LoadConfigFile(options, fileName)); Assert.True(exception.Message.StartsWith("Config file not found")); }
private string GetConfigFullPath(GetDependenciesOptions options, string fileName) { string fullPath = _fileSystem.GetWorkingDirectory();// GetTccDirectory(); if (string.IsNullOrEmpty(options.ConfigFilePath) == false) { fullPath = _fileSystem.GetFullPath(options.ConfigFilePath); } IEnumerable <string> probingPaths = GetProbingPaths(fullPath, fileName); string configPath = probingPaths.FirstOrDefault(x => _fileSystem.FileExists(x)); //string configPath = Path.Combine(fullPath, fileName); if (string.IsNullOrEmpty(configPath) || _fileSystem.FileExists(configPath) == false) { Log.Info("Config path: {0}", configPath); throw new Exception("Config file not found. From command line use the '-i' option to create a new config file or '-p' to provide a custom path to the file."); } return(configPath); }