Beispiel #1
0
        private static TestLanguageWorkerConfig MakeTestConfig(string language, string[] arguments, bool invalid = false, string addAppSvcProfile = "", bool emptyWorkerPath = false)
        {
            string json = WorkerConfigTestUtilities.GetTestWorkerConfig(language, arguments, invalid, addAppSvcProfile, emptyWorkerPath).ToString();

            return(new TestLanguageWorkerConfig()
            {
                Json = json,
                Language = language,
            });
        }
Beispiel #2
0
 public void ValidateWorkerDescription_Succeeds(WorkerDescription workerDescription)
 {
     try
     {
         WorkerConfigTestUtilities.CreateTestWorkerFileInCurrentDir();
         workerDescription.ApplyDefaultsAndValidate();
     }
     finally
     {
         WorkerConfigTestUtilities.DeleteTestWorkerFileInCurrentDir();
     }
 }
Beispiel #3
0
        public void ReadWorkerProviderFromConfig_InvalidWorker()
        {
            var testConfig = MakeTestConfig(testLanguage, new string[0]);
            var configs    = new List <TestLanguageWorkerConfig>()
            {
                testConfig
            };

            WorkerConfigTestUtilities.CreateWorkerFolder(customRootPath, testConfig, false);
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>
            {
                [$"{LanguageWorkerConstants.LanguageWorkersSectionName}:{testLanguage}:{OutOfProcConstants.WorkerDirectorySectionName}"] = customRootPath
            };

            var workerConfigs = TestReadWorkerProviderFromConfig(configs, new TestLogger(testLanguage), null, keyValuePairs);

            Assert.Empty(workerConfigs);
        }
Beispiel #4
0
        public void ReadWorkerProviderFromAppSetting()
        {
            var testConfig = MakeTestConfig(testLanguage, new string[0]);
            var configs    = new List <TestLanguageWorkerConfig>()
            {
                testConfig
            };

            WorkerConfigTestUtilities.CreateWorkerFolder(customRootPath, testConfig);
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>
            {
                [$"{LanguageWorkerConstants.LanguageWorkersSectionName}:{testLanguage}:{OutOfProcConstants.WorkerDirectorySectionName}"] = Path.Combine(customRootPath, testLanguage)
            };

            var workerConfigs = TestReadWorkerProviderFromConfig(configs, new TestLogger(testLanguage), null, keyValuePairs);

            Assert.Single(workerConfigs);
            WorkerConfig workerConfig = workerConfigs.Single();

            Assert.Equal(Path.Combine(customRootPath, testLanguage, $"{WorkerConfigTestUtilities.TestWorkerPathInWorkerConfig}.{testLanguage}"), workerConfig.Description.DefaultWorkerPath);
        }
Beispiel #5
0
        private IEnumerable <WorkerConfig> TestReadWorkerProviderFromConfig(IEnumerable <TestLanguageWorkerConfig> configs, ILogger testLogger, string language = null, Dictionary <string, string> keyValuePairs = null, bool appSvcEnv = false)
        {
            Mock <IEnvironment> mockEnvironment = new Mock <IEnvironment>();
            var workerPathSection = $"{LanguageWorkerConstants.LanguageWorkersSectionName}:{OutOfProcConstants.WorkersDirectorySectionName}";

            try
            {
                foreach (var workerConfig in configs)
                {
                    WorkerConfigTestUtilities.CreateWorkerFolder(rootPath, workerConfig);
                }

                IConfigurationRoot config = TestConfigBuilder(workerPathSection, keyValuePairs);

                var scriptHostOptions     = new ScriptJobHostOptions();
                var scriptSettingsManager = new ScriptSettingsManager(config);
                var configFactory         = new WorkerConfigFactory(config, testLogger, _testSysRuntimeInfo, _testEnvironment);
                if (appSvcEnv)
                {
                    var testEnvVariables = new Dictionary <string, string>
                    {
                        { EnvironmentSettingNames.AzureWebsiteInstanceId, "123" },
                    };
                    using (var variables = new TestScopedSettings(scriptSettingsManager, testEnvVariables))
                    {
                        configFactory.BuildWorkerProviderDictionary();
                        return(configFactory.GetConfigs());
                    }
                }
                configFactory.BuildWorkerProviderDictionary();
                return(configFactory.GetConfigs());
            }
            finally
            {
                WorkerConfigTestUtilities.DeleteTestDir(rootPath);
                WorkerConfigTestUtilities.DeleteTestDir(customRootPath);
            }
        }