private IEnumerable <IWorkerProvider> TestReadWorkerProviderFromConfig(string language, string json, string[] arguments, Mock <ILogger <object> > mockLogger) { string rootPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); string workerPath = Path.Combine(rootPath, language); try { Directory.CreateDirectory(workerPath); File.WriteAllText(Path.Combine(workerPath, ScriptConstants.WorkerConfigFileName), json); var scriptHostConfig = new ScriptHostConfiguration(); var scriptSettingsManager = new ScriptSettingsManager(); var settings = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("workers:config:path", rootPath) }; scriptSettingsManager.SetConfigurationFactory(() => new ConfigurationBuilder() .AddInMemoryCollection(settings).Build()); return(GenericWorkerProvider.ReadWorkerProviderFromConfig(scriptHostConfig, mockLogger.Object, scriptSettingsManager)); } finally { if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } } }
private IEnumerable <IWorkerProvider> TestReadWorkerProviderFromConfig(IEnumerable <TestLanguageWorkerConfig> configs, ILogger testLogger, string language = null) { try { foreach (var workerConfig in configs) { string workerPath = Path.Combine(rootPath, workerConfig.Language); Directory.CreateDirectory(workerPath); File.WriteAllText(Path.Combine(workerPath, ScriptConstants.WorkerConfigFileName), workerConfig.Json); } var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["workers:config:path"] = rootPath }); var config = configBuilder.Build(); var scriptHostConfig = new ScriptHostConfiguration(); var scriptSettingsManager = new ScriptSettingsManager(config); return(GenericWorkerProvider.ReadWorkerProviderFromConfig(scriptHostConfig, testLogger, scriptSettingsManager, language: language)); } finally { if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } } }