Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Settings.GetValue supports env expansion
* Added tests for `Settings.GetValue()` and `Settings.GetSettingValues()` * Added simple implementation for `Settings.GetValue()` * `Settings.GetSettingValues()` still needs an implementation, or an implementation that overlaps both.
- Loading branch information
1 parent
cf8f76c
commit 603907b
Showing
3 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/NuGet.Core.Tests/NuGet.Configuration.Test/EnvironmentSupportTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using NuGet.Test.Utility; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace NuGet.Configuration.Test | ||
{ | ||
public class EnvironmentSupportTests | ||
{ | ||
private readonly string DefaultNuGetConfigurationWithEnvironmentVariable = @" | ||
<configuration> | ||
<config> | ||
<add key='repositoryPath' value='%RP_ENV_VAR%\two' /> | ||
</config> | ||
</configuration>"; | ||
|
||
[Fact] | ||
public void GetValueEvaluatesEnvironmentVariable() | ||
{ | ||
//Arrange | ||
var expectedRepositoryPath = @"ONE\two"; | ||
|
||
using (var nugetConfigFileFolder = TestFileSystemUtility.CreateRandomTestFolder()) | ||
{ | ||
var nugetConfigFile = "NuGet.config"; | ||
var nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile); | ||
|
||
File.WriteAllText(nugetConfigFilePath, DefaultNuGetConfigurationWithEnvironmentVariable); | ||
|
||
Environment.SetEnvironmentVariable("RP_ENV_VAR", "ONE"); | ||
|
||
//Act | ||
ISettings settings = new Settings(nugetConfigFileFolder, nugetConfigFile); | ||
|
||
//Assert | ||
Assert.Equal(settings.GetValue("config", "repositoryPath"), expectedRepositoryPath); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void GetSettingValuesEvaluatesEnvironmentVariable() | ||
{ | ||
//Arrange | ||
var expectedRepositoryPath = @"ONE\two"; | ||
|
||
using (var nugetConfigFileFolder = TestFileSystemUtility.CreateRandomTestFolder()) | ||
{ | ||
var nugetConfigFile = "NuGet.config"; | ||
var nugetConfigFilePath = Path.Combine(nugetConfigFileFolder, nugetConfigFile); | ||
|
||
File.WriteAllText(nugetConfigFilePath, DefaultNuGetConfigurationWithEnvironmentVariable); | ||
|
||
Environment.SetEnvironmentVariable("RP_ENV_VAR", "ONE"); | ||
|
||
//Act | ||
ISettings settings = new Settings(nugetConfigFileFolder, nugetConfigFile); | ||
|
||
//Assert | ||
var settingsForConfig = settings.GetSettingValues("config"); | ||
Assert.Single(settingsForConfig); | ||
Assert.Equal(settingsForConfig.Single().Value, expectedRepositoryPath); | ||
} | ||
} | ||
} | ||
} |