forked from reqnroll/Reqnroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigurationDriver.cs
31 lines (25 loc) · 1.27 KB
/
ConfigurationDriver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Configuration;
using System.IO;
namespace Reqnroll.TestProjectGenerator;
public class ConfigurationDriver
{
public string TempFolderPath => GetConfigSetting("tempFolder", Path.GetTempPath());
public string TestProjectFolderName => GetConfigSetting("testProjectFolder", "RR");
public string VSTestPath => GetConfigSetting("vstestPath", "Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow");
public string MsBuildPath => GetConfigSetting(nameof(MsBuildPath));
public bool PipelineMode => GetConfigSwitch(nameof(PipelineMode));
public string GlobalNuGetPackages => GetConfigSetting(nameof(GlobalNuGetPackages));
public bool GetConfigSwitch(string key, bool defaultValue = false)
{
return GetConfigSetting(key, defaultValue.ToString()).Equals("true", StringComparison.InvariantCultureIgnoreCase);
}
public string GetConfigSetting(string key, string defaultValue = null)
{
var envSetting = Environment.GetEnvironmentVariable($"REQNROLL_TEST_{key}".ToUpperInvariant());
if (!string.IsNullOrEmpty(envSetting)) return envSetting;
var configSetting = ConfigurationManager.AppSettings[key];
if (!string.IsNullOrEmpty(configSetting)) return configSetting;
return defaultValue;
}
}