* Cleaning up solution files.

* Fix version.targets issue, and do better cleaning.

* More solution cleanup.

* Switch to Xunit, so tests can be run as part of build process.

* Add XML comments to public members, and include xmldoc files in packages.

* Fix missing versioning. Revamp signing to include all shipping projects.

* Execute SignBinaries target on nuproj projects.

* Get list of files to sign before executing SignFiles target.

* Add 'OutDir' back for nupkg signing.

* Fiddling with nuget pack options.

* Remove superfluous RepositoryRootEx property.
This commit is contained in:
StephenMolloy 2018-06-07 14:53:44 -07:00 коммит произвёл Jinhuafei
Родитель cf0a34c21d
Коммит 956645ff08
48 изменённых файлов: 636 добавлений и 657 удалений

2
.gitignore поставляемый
Просмотреть файл

@ -2,9 +2,11 @@
[Oo]bj/
src/**/[Bb]in/
src/**/[Oo]bj/
src/packages/**/signed/
test/**/[Bb]in/
test/**/[Oo]bj/
.vs/
.binaries/
msbuild.*
/packages/
samples/SampleWebApp/bin/

Просмотреть файл

@ -1,4 +1,5 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<AssemblyProject Include="src\Base\Base.csproj" />
<AssemblyProject Include="src\Environment\Environment.csproj" />
@ -7,28 +8,46 @@
<AssemblyProject Include="src\Json\Json.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(BuildCoreOnly)' != 'true'">
<AssemblyProject Include="test\Microsoft.Configuration.ConfigurationBuilders.Test\Test\Test.csproj" />
<AssemblyProject Include="samples\SampleWebApp\SampleWebApp.csproj" />
<ItemGroup>
<TestProject Include="test\Microsoft.Configuration.ConfigurationBuilders.Test\Test.csproj" />
</ItemGroup>
<ItemGroup>
<SampleProject Include="samples\SampleWebApp\SampleWebApp.csproj" />
</ItemGroup>
<ItemGroup>
<PackageProject Include="src\Packages\Packages.csproj" />
</ItemGroup>
<Target Name="Build" DependsOnTargets="BuildAssemblies;BuildPackages" />
<Target Name="Clean" DependsOnTargets="CleanPackages;CleanAssemblies" />
<Target Name="Build" DependsOnTargets="BuildAssemblies;UnitTest;BuildPackages" />
<Target Name="BuildAll" DependsOnTargets="BuildAssemblies;BuildSamples;UnitTest;BuildPackages" />
<Target Name="Clean" DependsOnTargets="CleanPackages;CleanSamples;CleanTests;CleanAssemblies" />
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
<Target Name="BuildAssemblies" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build" Projects="@(AssemblyProject)" />
</Target>
<Target Name="CleanAssemblies">
<MSBuild Targets="Clean" Projects="MicrosoftConfigurationBuilders.sln" />
</Target>
<Target Name="RebuildAssemblies" DependsOnTargets="Clean;Build" />
<Target Name="BuildTests" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build" Projects="@(TestProject)" />
</Target>
<Target Name="BuildSamples" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build" Projects="@(SampleProject)" />
</Target>
<Target Name="CleanAssemblies">
<MSBuild Targets="Clean" Projects="@(AssemblyProject)" />
</Target>
<Target Name="CleanTests">
<MSBuild Targets="Clean" Projects="@(TestProject)" />
</Target>
<Target Name="CleanSamples">
<MSBuild Targets="Clean" Projects="@(SampleProject)" />
</Target>
<!-- Packages build -->
@ -46,21 +65,8 @@
<Exec Command=".nuget\NuGet.exe restore" />
</Target>
<!--
<Target Name="UnitTest">
<ItemGroup>
<TestDLLs Include="test\Microsoft.Configuration.ConfigurationBuilders.Test\bin\$(Configuration)\*Test.dll" />
</ItemGroup>
<Target Name="UnitTest" DependsOnTargets="BuildTests">
<MSBuild Targets="XunitTest" Projects="@(TestProject)" />
</Target>
<PropertyGroup>
<TestSettingsFile Condition=" '$(Configuration)' == 'CodeCoverage' ">$(MsBuildProjectDirectory)\test\CodeCoverage.testsettings</TestSettingsFile>
<TestSettingsFile Condition=" '$(Configuration)' != 'CodeCoverage' ">$(MsBuildProjectDirectory)\unittest.testsettings</TestSettingsFile>
</PropertyGroup>
<Delete Files="bin\$(Configuration)-TestResults.trx" />
<Exec
Command="&quot;$(VS100COMNTOOLS)..\IDE\MSTEST.EXE&quot; /nologo /usestderr /resultsfile:&quot;bin\$(Configuration)-TestResults.trx&quot; @(TestDLLs -> '/testcontainer:&quot;%(Identity)&quot;', ' ') /testsettings:&quot;$(TestSettingsFile)&quot;" />
</Target>
-->
<Import Project="tools\MicrosoftConfigurationBuilders.targets"/>
</Project>

Просмотреть файл

@ -22,7 +22,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "packages", "src\packages\pa
{F382FBF8-146D-4968-A199-90D37F9EF9A7} = {F382FBF8-146D-4968-A199-90D37F9EF9A7}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "test\Microsoft.Configuration.ConfigurationBuilders.Test\Test\Test.csproj", "{9371A23F-BCB8-4429-8652-0A12D43F14F3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "test\Microsoft.Configuration.ConfigurationBuilders.Test\Test.csproj", "{9371A23F-BCB8-4429-8652-0A12D43F14F3}"
ProjectSection(ProjectDependencies) = postProject
{345C5437-4990-45DC-BE34-6E37AA05D8D2} = {345C5437-4990-45DC-BE34-6E37AA05D8D2}
{84E0CE5D-4AF2-414F-A940-22B3F93FC727} = {84E0CE5D-4AF2-414F-A940-22B3F93FC727}

Просмотреть файл

@ -63,7 +63,7 @@ and the first capture must be the token name to look up in the config source.
### EnvironmentConfigBuilder
```xml
<add name="Environment"
[mode|prefix|stripPrefix]
[mode|prefix|stripPrefix|tokenPattern]
type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
```
This is the simplest of the config builders. It draws its values from Environment, and it does not have any additional configuration options.
@ -71,7 +71,7 @@ This is the simplest of the config builders. It draws its values from Environmen
### UserSecretsConfigBuilder
```xml
<add name="UserSecrets"
[mode|prefix|stripPrefix]
[mode|prefix|stripPrefix|tokenPattern]
(userSecretsId="12345678-90AB-CDEF-1234-567890" | userSecretsFile="~\secrets.file")
[optional="true"]
type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets" />
@ -97,7 +97,7 @@ There are three additional configuration attributes for this config builder:
### AzureKeyVaultConfigBuilder
```xml
<add name="AzureKeyVault"
[mode|prefix|stripPrefix]
[mode|prefix|stripPrefix|tokenPattern]
(vaultName="MyVaultName" |
uri="https://MyVaultName.vault.azure.net")
[connectionString="connection string"]
@ -120,7 +120,7 @@ up connection information from the execution environment if possible, but you ca
### SimpleJsonConfigBuilder
```xml
<add name="SimpleJson"
[mode|prefix|stripPrefix]
[mode|prefix|stripPrefix|tokenPattern]
jsonFile="~\config.json"
[optional="true"]
[jsonMode="(Flat|Sectional)"]

Просмотреть файл

@ -3,47 +3,16 @@
setlocal
set EnableNuGetPackageRestore=true
REM msbuild will compile in Debug mode by default. The nuget packages project is Release by default.
REM Long story short... be explicit. Don't use defaults.
set MSBUILDEXE=msbuild.exe
set cfgOption=/p:Configuration=Release
REM set cfgOption=/p:Configuration=Debug
REM set cfgOption=/p:Configuration=Debug;Release
if not "%1"=="" set cfgOption=/p:Configuration=
set logOptions=/flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err
set logOptions=/v:n /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err
REM set logOptions=/v:diag /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err
set MSBUILDEXE=
if exist "%SystemDrive%\Program Files (x86)\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\15.0\Bin\MSBuild.exe"
GOTO BUILD
)
if exist "%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
GOTO BUILD
)
if exist "%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin\MSBuild.exe"
GOTO BUILD
)
if exist "%SystemDrive%\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
GOTO BUILD
)
if exist "%SystemDrive%\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
GOTO BUILD
)
if not defined MSBUILDEXE (
set MSBUILDEXE="%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
)
:BUILD
REM %MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" %cfgOption% %logOptions% /v:d /maxcpucount /nodeReuse:false %*
%MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" %cfgOption% %logOptions% /v:diag /maxcpucount /nodeReuse:false %*
%MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" /t:BuildAll %logOptions% /maxcpucount /nodeReuse:false %cfgOption%%*
endlocal

Просмотреть файл

@ -2,44 +2,19 @@
setlocal
set logOptions=/flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err
set MSBUILDEXE=msbuild.exe
set MSBUILDEXE=
set cfgOption=/p:Configuration=Release
REM set cfgOption=/p:Configuration=Debug
REM set cfgOption=/p:Configuration=Debug;Release
if not "%1"=="" set cfgOption=/p:Configuration=
if exist "%SystemDrive%\Program Files (x86)\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\15.0\Bin\MSBuild.exe"
GOTO BUILD
)
set logOptions=/v:n /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err
REM set logOptions=/v:diag /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err
if exist "%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
GOTO BUILD
)
if exist "%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\Bin\MSBuild.exe"
GOTO BUILD
)
if exist "%SystemDrive%\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
GOTO BUILD
)
if exist "%SystemDrive%\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" (
set MSBUILDEXE="%SystemDrive%\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
GOTO BUILD
)
if not defined MSBUILDEXE (
set MSBUILDEXE="%WINDIR%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
)
:BUILD
REM %MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" /t:Clean %logOptions% /v:d /maxcpucount /nodeReuse:false %*
%MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" /t:Clean %logOptions% /v:diag /maxcpucount /nodeReuse:false %*
del /F msbuild.log
del /F msbuild.wrn
del /F msbuild.err
%MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" /t:Clean %logOptions% /maxcpucount /nodeReuse:false %cfgOption%%*
del /F msbuild.log
del /F msbuild.wrn
del /F msbuild.err
endlocal

Просмотреть файл

@ -10,9 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Configuration.ConfigurationBuilders</RootNamespace>
<AssemblyName>Microsoft.Configuration.ConfigurationBuilders.Azure</AssemblyName>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkProfile />
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
@ -81,7 +81,6 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\cleanup.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
@ -89,12 +88,4 @@
<Error Condition="!Exists('..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.1\build\Microsoft.Azure.Services.AppAuthentication.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.1\build\Microsoft.Azure.Services.AppAuthentication.targets'))" />
</Target>
<Import Project="..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.1\build\Microsoft.Azure.Services.AppAuthentication.targets" Condition="Exists('..\..\packages\Microsoft.Azure.Services.AppAuthentication.1.0.1\build\Microsoft.Azure.Services.AppAuthentication.targets')" />
<Target Name="AfterBuild">
<ItemGroup>
<FilesToSign Include="$(TargetPath)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>Microsoft</Authenticode>
<StrongName>MsSharedLib72</StrongName>
</FilesToSign>
</ItemGroup>
</Target>
</Project>

Просмотреть файл

@ -15,13 +15,18 @@ using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// A ConfigurationProvider that retrieves values from Azure Key Vault.
/// </summary>
public class AzureKeyVaultConfigBuilder : KeyValueConfigBuilder
{
#pragma warning disable CS1591 // No xml comments for tag literals.
public const string vaultNameTag = "vaultName";
public const string connectionStringTag = "connectionString";
public const string uriTag = "uri";
public const string versionTag = "version";
public const string preloadTag = "preloadSecretNames";
#pragma warning restore CS1591 // No xml comments for tag literals.
private string _vaultName;
private string _connectionString;
@ -32,6 +37,11 @@ namespace Microsoft.Configuration.ConfigurationBuilders
private KeyVaultClient _kvClient;
private List<string> _allKeys;
/// <summary>
/// Initializes the configuration builder.
/// </summary>
/// <param name="name">The friendly name of the provider.</param>
/// <param name="config">A collection of the name/value pairs representing builder-specific attributes specified in the configuration for this provider.</param>
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
@ -66,6 +76,11 @@ namespace Microsoft.Configuration.ConfigurationBuilders
}
}
/// <summary>
/// Looks up a single 'value' for the given 'key.'
/// </summary>
/// <param name="key">The 'key' for the secret to look up in the configured Key Vault. (Prefix handling is not needed here.)</param>
/// <returns>The value corresponding to the given 'key' or null if no value is found.</returns>
public override string GetValue(string key)
{
// Azure Key Vault keys are case-insensitive, so this should be fine.
@ -75,6 +90,11 @@ namespace Microsoft.Configuration.ConfigurationBuilders
return Task.Run(async () => { return await GetValueAsync(key); }).Result;
}
/// <summary>
/// Retrieves all known key/value pairs from the Key Vault where the key begins with with <paramref name="prefix"/>.
/// </summary>
/// <param name="prefix">A prefix string to filter the list of potential keys retrieved from the source.</param>
/// <returns>A collection of key/value pairs.</returns>
public override ICollection<KeyValuePair<string, string>> GetAllValues(string prefix)
{
ConcurrentDictionary<string, string> d = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

Просмотреть файл

@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Azure")]
[assembly: AssemblyTitle("AzureKeyVaultConfigBuilder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Azure")]
[assembly: AssemblyProduct("AzureKeyVaultConfigBuilder")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Просмотреть файл

@ -10,9 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Configuration.ConfigurationBuilders</RootNamespace>
<AssemblyName>Microsoft.Configuration.ConfigurationBuilders.Base</AssemblyName>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkProfile />
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
@ -48,13 +48,4 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\cleanup.targets" />
<Target Name="AfterBuild">
<ItemGroup>
<FilesToSign Include="$(TargetPath)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>Microsoft</Authenticode>
<StrongName>MsSharedLib72</StrongName>
</FilesToSign>
</ItemGroup>
</Target>
</Project>

Просмотреть файл

@ -10,24 +10,55 @@ using System.Xml;
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// Base class for a set of ConfigurationBuilders that follow a simple key/value pair substitution model. This base
/// class handles substitution modes and most prefix concerns, so implementing classes only need to be a simple
/// source of key/value pairs through the <see cref="GetValue(string)"/> and <see cref="GetAllValues(string)"/> methods.
/// </summary>
public abstract class KeyValueConfigBuilder : ConfigurationBuilder
{
#pragma warning disable CS1591 // No xml comments for tag literals.
public const string modeTag = "mode";
public const string prefixTag = "prefix";
public const string stripPrefixTag = "stripPrefix";
public const string tokenPatternTag = "tokenPattern";
#pragma warning restore CS1591 // No xml comments for tag literals.
private bool _greedyInited;
private IDictionary<string, string> _cachedValues;
private bool _stripPrefix = false; // Prefix-stripping is all handled in this class; this is private so it doesn't confuse sub-classes.
/// <summary>
/// Gets or sets a regular expression used for matching tokens in raw xml during Greedy substitution.
/// </summary>
public string TokenPattern { get; protected set; } = @"\$\{(\w+)\}";
/// <summary>
/// Gets or sets the substitution pattern to be used by the KeyValueConfigBuilder.
/// </summary>
public KeyValueMode Mode { get; private set; } = KeyValueMode.Strict;
/// <summary>
/// Gets or sets a prefix string that must be matched by keys to be considered for value substitution.
/// </summary>
public string KeyPrefix { get; private set; }
/// <summary>
/// Looks up a single 'value' for the given 'key.'
/// </summary>
/// <param name="key">The 'key' to look up in the config source. (Prefix handling is not needed here.)</param>
/// <returns>The value corresponding to the given 'key' or null if no value is found.</returns>
public abstract string GetValue(string key);
/// <summary>
/// Retrieves all known key/value pairs for the configuration source where the key begins with with <paramref name="prefix"/>.
/// </summary>
/// <param name="prefix">A prefix string to filter the list of potential keys retrieved from the source.</param>
/// <returns>A collection of key/value pairs.</returns>
public abstract ICollection<KeyValuePair<string, string>> GetAllValues(string prefix);
/// <summary>
/// Initializes the configuration builder.
/// </summary>
/// <param name="name">The friendly name of the provider.</param>
/// <param name="config">A collection of the name/value pairs representing builder-specific attributes specified in the configuration for this provider.</param>
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
@ -52,6 +83,7 @@ namespace Microsoft.Configuration.ConfigurationBuilders
_cachedValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
#pragma warning disable CS1591 // No xml comments for overrides that implementing classes shouldn't worry about.
public override XmlNode ProcessRawXml(XmlNode rawXml)
{
if (Mode == KeyValueMode.Expand)
@ -92,6 +124,7 @@ namespace Microsoft.Configuration.ConfigurationBuilders
return configSection;
}
#pragma warning restore CS1591 // No xml comments for overrides that implementing classes shouldn't worry about.
private XmlNode ExpandTokens(XmlNode rawXml)
{

Просмотреть файл

@ -3,10 +3,22 @@
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// Possible modes (or behaviors) for key/value substitution.
/// </summary>
public enum KeyValueMode
{
/// <summary>
/// Replaces 'value' if 'key' is matched. Only operates on known key/value config sections.
/// </summary>
Strict,
/// <summary>
/// Inserts all 'values' regardless of the previous existence of the 'key.' Only operates on known key/value config sections.
/// </summary>
Greedy,
/// <summary>
/// Replace 'key'-specifying tokens in raw xml with 'values.' Operates on any config section.
/// </summary>
Expand
}
}

Просмотреть файл

@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Basic")]
[assembly: AssemblyTitle("KeyValueConfigBuilder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Basic")]
[assembly: AssemblyProduct("KeyValueConfigBuilder")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Просмотреть файл

@ -7,11 +7,19 @@ using System.Reflection;
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// Utility methods commonly used by KeyValueConfigBuilders.
/// </summary>
public class Utils
{
private static bool? s_isAspNet = null;
private static Type s_hostingEnvironmentType = null;
/// <summary>
/// Returns the physical file path that corresponds to the specified relative path.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static string MapPath(string path)
{
if (String.IsNullOrWhiteSpace(path))

Просмотреть файл

@ -10,9 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Configuration.ConfigurationBuilders</RootNamespace>
<AssemblyName>Microsoft.Configuration.ConfigurationBuilders.Environment</AssemblyName>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkProfile />
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
@ -52,13 +52,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\cleanup.targets" />
<Target Name="AfterBuild">
<ItemGroup>
<FilesToSign Include="$(TargetPath)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>Microsoft</Authenticode>
<StrongName>MsSharedLib72</StrongName>
</FilesToSign>
</ItemGroup>
</Target>
</Project>

Просмотреть файл

@ -7,13 +7,26 @@ using System.Collections.Generic;
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// A ConfigurationProvider that retrieves values from environment variables.
/// </summary>
public class EnvironmentConfigBuilder : KeyValueConfigBuilder
{
/// <summary>
/// Looks up a single 'value' for the given 'key.'
/// </summary>
/// <param name="key">The 'key' to look up in the environment. (Prefix handling is not needed here.)</param>
/// <returns>The value corresponding to the given 'key' or null if no value is found.</returns>
public override string GetValue(string key)
{
return Environment.GetEnvironmentVariable(key);
}
/// <summary>
/// Retrieves all known key/value pairs from the environment where the key begins with with <paramref name="prefix"/>.
/// </summary>
/// <param name="prefix">A prefix string to filter the list of potential keys retrieved from the source.</param>
/// <returns>A collection of key/value pairs.</returns>
public override ICollection<KeyValuePair<string, string>> GetAllValues(string prefix)
{
Dictionary<string, string> values = new Dictionary<string, string>();

Просмотреть файл

@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Basic")]
[assembly: AssemblyTitle("EnvironmentConfigBuilder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Basic")]
[assembly: AssemblyProduct("EnvironmentConfigBuilder")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Просмотреть файл

@ -10,9 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Configuration.ConfigurationBuilders</RootNamespace>
<AssemblyName>Microsoft.Configuration.ConfigurationBuilders.Json</AssemblyName>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkProfile />
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
@ -58,13 +58,4 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\cleanup.targets" />
<Target Name="AfterBuild">
<ItemGroup>
<FilesToSign Include="$(TargetPath)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>Microsoft</Authenticode>
<StrongName>MsSharedLib72</StrongName>
</FilesToSign>
</ItemGroup>
</Target>
</Project>

Просмотреть файл

@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Json")]
[assembly: AssemblyTitle("SimpleJsonConfigBuilder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Json")]
[assembly: AssemblyProduct("SimpleJsonConfigBuilder")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Просмотреть файл

@ -16,20 +16,39 @@ using System.Xml;
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// A ConfigurationProvider that retrieves values from a json config file.
/// </summary>
public class SimpleJsonConfigBuilder : KeyValueConfigBuilder
{
#pragma warning disable CS1591 // No xml comments for tag literals.
public const string jsonFileTag = "jsonFile";
public const string optionalTag = "optional";
public const string jsonModeTag = "jsonMode";
public const string keyDelimiter = ":";
#pragma warning restore CS1591 // No xml comments for tag literals.
private string _currentSection;
private Dictionary<string, Dictionary<string, string>> _allSettings;
/// <summary>
/// Gets or sets a path to the json file to be read.
/// </summary>
public string JsonFile { get; protected set; }
/// <summary>
/// Specifies whether the config builder should cause errors if the json source file cannot be found.
/// </summary>
public bool Optional { get; protected set; }
/// <summary>
/// Gets or sets the json parsing paradigm to be used by the SimpleJsonConfigBuilder.
/// </summary>
public SimpleJsonConfigBuilderMode JsonMode { get; protected set; } = SimpleJsonConfigBuilderMode.Flat; // Flat dictionary, like core secrets.json
/// <summary>
/// Initializes the configuration builder.
/// </summary>
/// <param name="name">The friendly name of the provider.</param>
/// <param name="config">A collection of the name/value pairs representing builder-specific attributes specified in the configuration for this provider.</param>
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
@ -94,6 +113,7 @@ namespace Microsoft.Configuration.ConfigurationBuilders
}
}
#pragma warning disable CS1591 // No xml comments for overrides that should not be called directly.
public override XmlNode ProcessRawXml(XmlNode rawXml)
{
if (rawXml != null)
@ -106,13 +126,24 @@ namespace Microsoft.Configuration.ConfigurationBuilders
_currentSection = configSection.SectionInformation.Name;
return base.ProcessConfigurationSection(configSection);
}
#pragma warning restore CS1591 // No xml comments for overrides that should not be called directly.
/// <summary>
/// Looks up a single 'value' for the given 'key.'
/// </summary>
/// <param name="key">The 'key' to look up in the json source. (Prefix handling is not needed here.)</param>
/// <returns>The value corresponding to the given 'key' or null if no value is found.</returns>
public override string GetValue(string key)
{
string value;
return GetCurrentDictionary().TryGetValue(key, out value) ? value : null;
}
/// <summary>
/// Retrieves all known key/value pairs from the json source where the key begins with with <paramref name="prefix"/>.
/// </summary>
/// <param name="prefix">A prefix string to filter the list of potential keys retrieved from the source.</param>
/// <returns>A collection of key/value pairs.</returns>
public override ICollection<KeyValuePair<string, string>> GetAllValues(string prefix)
{
return GetCurrentDictionary().Where(kvp => kvp.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)).ToList();

Просмотреть файл

@ -3,9 +3,18 @@
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// Possible modes (or paradigms) for parsing a json source file.
/// </summary>
public enum SimpleJsonConfigBuilderMode
{
/// <summary>
/// The whole file is flattened into a single key/value collection.
/// </summary>
Flat,
/// <summary>
/// Use top-level objects to separate into different dictionaries per config section.
/// </summary>
Sectional
}
}

Просмотреть файл

@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Basic")]
[assembly: AssemblyTitle("UserSecretsConfigBuilder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Basic")]
[assembly: AssemblyProduct("UserSecretsConfigBuilder")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Просмотреть файл

@ -10,9 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Configuration.ConfigurationBuilders</RootNamespace>
<AssemblyName>Microsoft.Configuration.ConfigurationBuilders.UserSecrets</AssemblyName>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
<TargetFrameworkProfile />
<SignAssembly>true</SignAssembly>
<DelaySign>true</DelaySign>
@ -52,13 +52,4 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\cleanup.targets" />
<Target Name="AfterBuild">
<ItemGroup>
<FilesToSign Include="$(TargetPath)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>Microsoft</Authenticode>
<StrongName>MsSharedLib72</StrongName>
</FilesToSign>
</ItemGroup>
</Target>
</Project>

Просмотреть файл

@ -11,18 +11,38 @@ using System.Xml.Linq;
namespace Microsoft.Configuration.ConfigurationBuilders
{
/// <summary>
/// A ConfigurationProvider that retrieves values from a local secrets file.
/// </summary>
public class UserSecretsConfigBuilder : KeyValueConfigBuilder
{
#pragma warning disable CS1591 // No xml comments for tag literals.
public const string userSecretsFileTag = "userSecretsFile";
public const string userSecretsIdTag = "userSecretsId";
public const string optionalTag = "optional";
#pragma warning restore CS1591 // No xml comments for tag literals.
private ConcurrentDictionary<string, string> _secrets;
/// <summary>
/// Gets or sets an identifier string used to compose an out-of-solution path to a file that contains secrets.
/// (Set to ${UserSecretsId} to reference the similarly named project property in Visual Studio environments.
/// </summary>
public string UserSecretsId { get; protected set; }
/// <summary>
/// Gets or sets a path to the secrets file to be used.
/// </summary>
public string UserSecretsFile { get; protected set; }
/// <summary>
/// Specifies whether the config builder should cause errors if the secrets file source cannot be found.
/// </summary>
public bool Optional { get; protected set; }
/// <summary>
/// Initializes the configuration builder.
/// </summary>
/// <param name="name">The friendly name of the provider.</param>
/// <param name="config">A collection of the name/value pairs representing builder-specific attributes specified in the configuration for this provider.</param>
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
@ -54,11 +74,21 @@ namespace Microsoft.Configuration.ConfigurationBuilders
}
}
/// <summary>
/// Retrieves all known key/value pairs from the secrets file where the key begins with with <paramref name="prefix"/>.
/// </summary>
/// <param name="prefix">A prefix string to filter the list of potential keys retrieved from the source.</param>
/// <returns>A collection of key/value pairs.</returns>
public override ICollection<KeyValuePair<string, string>> GetAllValues(string prefix)
{
return _secrets?.Where(s => s.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)).ToList();
}
/// <summary>
/// Looks up a single 'value' for the given 'key.'
/// </summary>
/// <param name="key">The 'key' to look up in the secrets file. (Prefix handling is not needed here.)</param>
/// <returns>The value corresponding to the given 'key' or null if no value is found.</returns>
public override string GetValue(string key)
{
if (_secrets != null && _secrets.TryGetValue(key, out string val))

Просмотреть файл

@ -12,12 +12,10 @@
<Source>$(AssemblyPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
<!--
<NuGetContent Include="$(AssemblyName).xml">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
-->
<NuGetContent Include="$(AssemblyName).pdb" Condition="'$(NuGetPackSymbols)' == 'true'">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
@ -37,14 +35,5 @@
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
<Target Name="AfterBuild">
<PropertyGroup>
<OutDir>$(PackageOutputDir)</OutDir>
</PropertyGroup>
<ItemGroup>
<FilesToSign Include="$(NuGetPackTargetFile)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>NuGet</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
<Import Project="$(RepositoryRoot)Tools\signing.targets"/>
</Project>

Просмотреть файл

@ -12,12 +12,10 @@
<Source>$(AssemblyPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
<!--
<NuGetContent Include="$(AssemblyName).xml">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
-->
<NuGetContent Include="$(AssemblyName).pdb" Condition="'$(NuGetPackSymbols)' == 'true'">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
@ -37,14 +35,5 @@
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
<Target Name="AfterBuild">
<PropertyGroup>
<OutDir>$(PackageOutputDir)</OutDir>
</PropertyGroup>
<ItemGroup>
<FilesToSign Include="$(NuGetPackTargetFile)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>NuGet</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
<Import Project="$(RepositoryRoot)Tools\signing.targets"/>
</Project>

Просмотреть файл

@ -12,12 +12,10 @@
<Source>$(AssemblyPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
<!--
<NuGetContent Include="$(AssemblyName).xml">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
-->
<NuGetContent Include="$(AssemblyName).pdb" Condition="'$(NuGetPackSymbols)' == 'true'">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
@ -37,14 +35,5 @@
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
<Target Name="AfterBuild">
<PropertyGroup>
<OutDir>$(PackageOutputDir)</OutDir>
</PropertyGroup>
<ItemGroup>
<FilesToSign Include="$(NuGetPackTargetFile)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>NuGet</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
<Import Project="$(RepositoryRoot)Tools\signing.targets"/>
</Project>

Просмотреть файл

@ -12,12 +12,10 @@
<Source>$(AssemblyPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
<!--
<NuGetContent Include="$(AssemblyName).xml">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
-->
<NuGetContent Include="$(AssemblyName).pdb" Condition="'$(NuGetPackSymbols)' == 'true'">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
@ -37,14 +35,5 @@
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
<Target Name="AfterBuild">
<PropertyGroup>
<OutDir>$(PackageOutputDir)</OutDir>
</PropertyGroup>
<ItemGroup>
<FilesToSign Include="$(NuGetPackTargetFile)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>NuGet</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
<Import Project="$(RepositoryRoot)Tools\signing.targets"/>
</Project>

Просмотреть файл

@ -12,12 +12,10 @@
<Source>$(AssemblyPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
<!--
<NuGetContent Include="$(AssemblyName).xml">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
</NuGetContent>
-->
<NuGetContent Include="$(AssemblyName).pdb" Condition="'$(NuGetPackSymbols)' == 'true'">
<Source>$(OutputPath)</Source>
<Destination>lib\Net471</Destination>
@ -65,14 +63,5 @@
<SignFiles Files="@(ScriptFilesToSign)" Type="$(SignType)" BinariesDirectory="$(MSBuildThisFileDirectory)\tools\Net471\signed"
IntermediatesDirectory="$(MSBuildThisFileDirectory)\tools\Net471" ESRPSigning="$(ESRPSigning)" UseBearerToken="$(UseBearerToken)" />
</Target>
<Target Name="AfterBuild">
<PropertyGroup>
<OutDir>$(PackageOutputDir)</OutDir>
</PropertyGroup>
<ItemGroup>
<FilesToSign Include="$(NuGetPackTargetFile)" Condition="'$(SignAssembly)' == 'true'">
<Authenticode>NuGet</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
<Import Project="$(RepositoryRoot)Tools\signing.targets"/>
</Project>

Просмотреть файл

@ -59,7 +59,6 @@
<Content Include="ConfigurationBuilders.UserSecrets.nupkg\content\sample.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\tools\cleanup.targets" />
<Target Name="Build">
<MSBuild Projects="@(NuGetProject)" Targets="Build" />
</Target>

Просмотреть файл

@ -6,224 +6,223 @@ using System.Linq;
using System.Reflection;
using System.Xml;
using Microsoft.Configuration.ConfigurationBuilders;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Test
{
[TestClass]
public class BaseTests
{
// ======================================================================
// Common Parameters
// ======================================================================
[TestMethod]
[Fact]
public void BaseParameters_Mode()
{
// Default Strict
var builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection());
Assert.AreEqual(builder.Mode, KeyValueMode.Strict);
Assert.Equal(KeyValueMode.Strict, builder.Mode);
// Strict
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Strict" } });
Assert.AreEqual(builder.Mode, KeyValueMode.Strict);
Assert.Equal(KeyValueMode.Strict, builder.Mode);
// Greedy
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" } });
Assert.AreEqual(builder.Mode, KeyValueMode.Greedy);
Assert.Equal(KeyValueMode.Greedy, builder.Mode);
// Expand
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" } });
Assert.AreEqual(builder.Mode, KeyValueMode.Expand);
Assert.Equal(KeyValueMode.Expand, builder.Mode);
// Invalid
builder = new FakeConfigBuilder();
Assert.ThrowsException<ArgumentException>(() => {
Assert.Throws<ArgumentException>(() => {
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "InvalidModeDoesNotExist" } });
});
// Case-insensitive value
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "grEEdy" } });
Assert.AreEqual(builder.Mode, KeyValueMode.Greedy);
Assert.Equal(KeyValueMode.Greedy, builder.Mode);
// Case sensitive attribute name
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "MODE", "Expand" } });
Assert.AreEqual(builder.Mode, KeyValueMode.Expand);
Assert.Equal(KeyValueMode.Expand, builder.Mode);
}
[TestMethod]
[Fact]
public void BaseParameters_Prefix()
{
// Default empty string. (Not null)
var builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection());
Assert.AreEqual(builder.KeyPrefix, "");
Assert.Equal("", builder.KeyPrefix);
// Prefix, case preserved
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "prefix", "_This_is_my_PREFIX:" } });
Assert.AreEqual(builder.KeyPrefix, "_This_is_my_PREFIX:");
Assert.Equal("_This_is_my_PREFIX:", builder.KeyPrefix);
// Case sensitive attribute name
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "PREfix", "$This_is_my_other_PREFIX#" } });
Assert.AreEqual(builder.KeyPrefix, "$This_is_my_other_PREFIX#");
Assert.Equal("$This_is_my_other_PREFIX#", builder.KeyPrefix);
}
[TestMethod]
[Fact]
public void BaseParameters_StripPrefix()
{
// Default false
var builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection());
Assert.AreEqual(builder.StripPrefix, false);
Assert.False(builder.StripPrefix);
// True
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "stripPrefix", "True" } });
Assert.AreEqual(builder.StripPrefix, true);
Assert.True(builder.StripPrefix);
// fAlSe
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "stripPrefix", "fAlSe" } });
Assert.AreEqual(builder.StripPrefix, false);
Assert.False(builder.StripPrefix);
// Works with 'prefix'
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "prefix", "Test_" }, { "stripPrefix", "TRUE" } });
Assert.AreEqual(builder.StripPrefix, true);
Assert.True(builder.StripPrefix);
// Can be set in Greedy mode
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "stripPrefix", "TRUE" } });
Assert.AreEqual(builder.StripPrefix, true);
Assert.True(builder.StripPrefix);
// Can be set in Expand mode
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "stripPrefix", "TRUE" } });
Assert.AreEqual(builder.StripPrefix, true);
Assert.True(builder.StripPrefix);
// Case sensitive attribute name
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "STRIppreFIX", "true" } });
Assert.AreEqual(builder.StripPrefix, true);
Assert.True(builder.StripPrefix);
}
[TestMethod]
[Fact]
public void BaseParameters_TokenPattern()
{
// Default string. (Not null)
var builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection());
Assert.AreEqual(builder.TokenPattern, @"\$\{(\w+)\}");
Assert.Equal(@"\$\{(\w+)\}", builder.TokenPattern);
// TokenPattern, case preserved
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "tokenPattern", @"%([^\s+\W*#$&_-])}%" } });
Assert.AreEqual(builder.TokenPattern, @"%([^\s+\W*#$&_-])}%");
Assert.Equal(@"%([^\s+\W*#$&_-])}%", builder.TokenPattern);
// Case sensitive attribute name
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "TOKenpaTTerN", @"\[pattern\]" } });
Assert.AreEqual(builder.TokenPattern, @"\[pattern\]");
Assert.Equal(@"\[pattern\]", builder.TokenPattern);
// Protected setter
builder = new FakeConfigBuilder();
builder.Initialize("test", null);
builder.SetTokenPattern("TestPattern");
Assert.AreEqual(builder.TokenPattern, @"TestPattern");
Assert.Equal(@"TestPattern", builder.TokenPattern);
}
// ======================================================================
// Behaviors
// ======================================================================
[TestMethod]
[Fact]
public void BaseBehavior_Strict()
{
// Strict - ProcessRawXml is a noop
var builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection());
XmlNode xmlInput = GetNode(rawXmlInput);
Assert.AreEqual(xmlInput, builder.ProcessRawXml(xmlInput));
Assert.Equal(xmlInput, builder.ProcessRawXml(xmlInput));
// Strict - ProcessRawXml is a noop, even with prefix stuff
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "prefix", "Prefix_" }, { "stripPrefix", "TRUE" } });
xmlInput = GetNode(rawXmlInput);
Assert.AreEqual(xmlInput, builder.ProcessRawXml(xmlInput));
Assert.Equal(xmlInput, builder.ProcessRawXml(xmlInput));
// Strict - ProcessConfigurationSection
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection());
AppSettingsSection newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.IsNull(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Null(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
// Strict - ProcessConfigurationSection with prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "prefix", "Prefix_" }});
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.IsNull(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Null(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
// Strict - ProcessConfigurationSection with prefix - NOT Case-Sensitive
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "prefix", "preFIX_" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.IsNull(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Null(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
// Strict - ProcessConfigurationSection with prefix and strip
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "prefix", "preFIX_" }, { "stripPrefix", "true" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("PrefixTest2", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.IsNull(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("Prefix_TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("PrefixTest2", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Null(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
// Strict - ProcessConfigurationSection with strip with no prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "stripPrefix", "true" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.IsNull(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Null(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
}
[TestMethod]
[Fact]
public void BaseBehavior_Expand()
{
// Expand - ProcessConfigurationSection is a noop
@ -231,275 +230,275 @@ namespace Test
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" } });
AppSettingsSection origSettings = GetAppSettings();
AppSettingsSection newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual(origSettings.Settings.Count, newSettings.Settings.Count);
Assert.Equal(origSettings.Settings.Count, newSettings.Settings.Count);
foreach (string key in origSettings.Settings.AllKeys)
Assert.AreEqual(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value);
Assert.Equal(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value);
// Expand - ProcessConfigurationSection is a noop, even with prefix stuff
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "Prefix_" }, { "stripPrefix", "true" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual(origSettings.Settings.Count, newSettings.Settings.Count);
Assert.Equal(origSettings.Settings.Count, newSettings.Settings.Count);
foreach (string key in origSettings.Settings.AllKeys)
Assert.AreEqual(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value);
Assert.Equal(origSettings.Settings[key].Value, newSettings.Settings[key]?.Value);
// Expand - ProcessRawXml
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" } });
XmlNode xmlInput = GetNode(rawXmlInput);
XmlNode xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("TestKey1Value", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("TestKey1Value", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "${TestKey1}"));
// Expand - ProcessRawXml with prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "Prefix_" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
// Expand - ProcessRawXml with prefix - NOT Case-Sensitive
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "prEFiX_" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
// Expand - ProcessRawXml with prefix and strip
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "prefix", "prEFiX_" }, { "stripPrefix", "true" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "Prefix_TestKey1Value"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "Prefix_TestKey1Value"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
// Expand - ProcessRawXml with strip with no prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "stripPrefix", "true" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("TestKey1Value", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("TestKey1Value", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("Prefix_TestKey1Value", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "${TestKey1}"));
// Expand - ProcessRawXml with alternate tokenPattern
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%([\w:]+)%%" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.AreEqual("ThisWasAnAlternateTokenPattern", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.AreEqual("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Equal("ThisWasAnAlternateTokenPattern", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.Equal("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
// Expand - ProcessRawXml does not work with alternate tokenPattern with no capture group
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%[\w:]+%%" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.AreEqual("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.AreEqual("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Equal("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.Equal("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
// Expand - ProcessRawXml does not blow up with alternate tokenPattern with empty capture group
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%(.?)%" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.AreEqual("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.AreEqual("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Equal("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.Equal("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
// Expand - ProcessRawXml with alternate tokenPattern and prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%([\w:]+)%%" }, { "prefix", "Prefix_" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.AreEqual("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.AreEqual("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Equal("%%Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.Equal("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
// Expand - ProcessRawXml with alternate tokenPattern and strip prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Expand" }, { "tokenPattern", @"%%([\w:]+)%%" }, { "prefix", "Prefix_" }, { "stripPrefix", "true" } });
xmlInput = GetNode(rawXmlInput);
xmlOutput = builder.ProcessRawXml(xmlInput);
Assert.AreEqual("appSettings", xmlOutput.Name);
Assert.AreEqual("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.AreEqual("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.AreEqual("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.AreEqual("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.AreEqual("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.AreEqual("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.AreEqual("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.AreEqual("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.IsNull(GetValueFromXml(xmlOutput, "TestKey1Value"));
Assert.Equal("appSettings", xmlOutput.Name);
Assert.Equal("val1", GetValueFromXml(xmlOutput, "TestKey1"));
Assert.Equal("${TestKey1}", GetValueFromXml(xmlOutput, "test1"));
Assert.Equal("expandTestValue", GetValueFromXml(xmlOutput, "${TestKey1}"));
Assert.Equal("PrefixTest1", GetValueFromXml(xmlOutput, "TestKey"));
Assert.Equal("PrefixTest2", GetValueFromXml(xmlOutput, "Prefix_TestKey"));
Assert.Equal("${Prefix_TestKey1}", GetValueFromXml(xmlOutput, "PreTest2"));
Assert.Equal("ThisWasAnAltTokenPatternWithPrefix", GetValueFromXml(xmlOutput, "AltTokenTest"));
Assert.Equal("%%Prefix_Alt:Token%%", GetValueFromXml(xmlOutput, "AltTokenTest2"));
Assert.Null(GetValueFromXml(xmlOutput, "Prefix_TestKey1"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey2"));
Assert.Null(GetValueFromXml(xmlOutput, "TestKey1Value"));
}
[TestMethod]
[Fact]
public void BaseBehavior_Greedy()
{
// Greedy - ProcessRawXml is a noop
var builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" } });
XmlNode xmlInput = GetNode(rawXmlInput);
Assert.AreEqual(xmlInput, builder.ProcessRawXml(xmlInput));
Assert.Equal(xmlInput, builder.ProcessRawXml(xmlInput));
// Greedy - ProcessRawXml is a noop, even with prefix stuff
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "PreFIX_" }, { "stripPrefix", "true" } });
xmlInput = GetNode(rawXmlInput);
Assert.AreEqual(xmlInput, builder.ProcessRawXml(xmlInput));
Assert.Equal(xmlInput, builder.ProcessRawXml(xmlInput));
// Greedy - ProcessConfigurationSection
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" } });
AppSettingsSection newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.AreEqual("TestKey2Value", newSettings.Settings["TestKey2"]?.Value);
Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Equal("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Equal("TestKey2Value", newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
// Greedy - ProcessConfigurationSection with prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "Prefix_" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Equal("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
// Greedy - ProcessConfigurationSection with prefix - NOT Case-Sensitive
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "preFIX_" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("val1", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Equal("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
// Greedy - ProcessConfigurationSection with prefix and strip
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "prefix", "preFIX_" }, { "stripPrefix", "true" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("PrefixTest2", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.IsNull(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.IsNull(newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("Prefix_TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("PrefixTest2", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Null(newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Null(newSettings.Settings["TestKey2"]?.Value);
// Greedy - ProcessConfigurationSection with strip with no prefix
builder = new FakeConfigBuilder();
builder.Initialize("test", new System.Collections.Specialized.NameValueCollection() { { "mode", "Greedy" }, { "stripPrefix", "true" } });
newSettings = (AppSettingsSection)builder.ProcessConfigurationSection(GetAppSettings());
Assert.AreEqual("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.AreEqual("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.AreEqual("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.AreEqual("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.AreEqual("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.AreEqual("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.AreEqual("TestKey2Value", newSettings.Settings["TestKey2"]?.Value);
Assert.AreEqual("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
Assert.Equal("TestKey1Value", newSettings.Settings["TestKey1"]?.Value);
Assert.Equal("${TestKey1}", newSettings.Settings["test1"]?.Value);
Assert.Equal("expandTestValue", newSettings.Settings["${TestKey1}"]?.Value);
Assert.Equal("PrefixTest1", newSettings.Settings["TestKey"]?.Value);
Assert.Equal("Prefix_TestKeyValue", newSettings.Settings["Prefix_TestKey"]?.Value);
Assert.Equal("${Prefix_TestKey1}", newSettings.Settings["PreTest2"]?.Value);
Assert.Equal("TestKey2Value", newSettings.Settings["TestKey2"]?.Value);
Assert.Equal("Prefix_TestKey1Value", newSettings.Settings["Prefix_TestKey1"]?.Value);
}
// ======================================================================
// Errors
// ======================================================================
[TestMethod]
[Fact]
public void BaseErrors_ProcessRawXml()
{
var builder = new FakeConfigBuilder() { FailGetValues = true };
@ -510,28 +509,28 @@ namespace Test
builder.ProcessRawXml(GetNode(rawXmlInput));
// If we don't get an exception, that's bad
Assert.Fail();
Assert.True(false);
}
catch (Exception e)
{
// ProcessRawXml exception in Expand mode contains builder name
Assert.IsTrue(e.Message.Contains("Esteban"));
Assert.IsTrue(e.ToString().Contains("Unique Exception Message in GetValue"));
Assert.Contains("Esteban", e.Message);
Assert.Contains("Unique Exception Message in GetValue", e.ToString());
}
// In Strict or Greedy modes, ProcessRawXml is a noop
builder = new FakeConfigBuilder() { FailGetValues = true };
builder.Initialize("Joe", new NameValueCollection());
builder.ProcessRawXml(GetNode(rawXmlInput));
Assert.IsTrue(true); // I hate implicit success. ;)
Assert.True(true); // I hate implicit success. ;)
builder = new FakeConfigBuilder() { FailGetValues = true };
builder.Initialize("Jose", new NameValueCollection() { { "mode", "Greedy" } });
builder.ProcessRawXml(GetNode(rawXmlInput));
Assert.IsTrue(true); // I hate implicit success. ;)
Assert.True(true); // I hate implicit success. ;)
}
[TestMethod]
[Fact]
public void BaseErrors_ProcessConfigurationSection()
{
var builder = new FakeConfigBuilder() { FailGetValues = true };
@ -541,13 +540,13 @@ namespace Test
builder.ProcessConfigurationSection(GetAppSettings());
// If we don't get an exception, that's bad
Assert.Fail();
Assert.True(false);
}
catch (Exception e)
{
// ProcessConfigurationSection exception in Strict mode contains builder name
Assert.IsTrue(e.Message.Contains("Stefano"));
Assert.IsTrue(e.ToString().Contains("Unique Exception Message in GetValue"));
Assert.Contains("Stefano", e.Message);
Assert.Contains("Unique Exception Message in GetValue", e.ToString());
}
builder = new FakeConfigBuilder() { FailGetValues = true };
@ -557,20 +556,20 @@ namespace Test
builder.ProcessConfigurationSection(GetAppSettings());
// If we don't get an exception, that's bad
Assert.Fail();
Assert.True(false);
}
catch (Exception e)
{
// ProcessConfigurationSection exception in Greedy mode contains builder name
Assert.IsTrue(e.Message.Contains("Stepanya"));
Assert.IsTrue(e.ToString().Contains("Unique Exception Message in GetAllValues"));
Assert.Contains("Stepanya", e.Message);
Assert.Contains("Unique Exception Message in GetAllValues", e.ToString());
}
// In Expand mode, ProcessConfigurationSection is a noop
builder = new FakeConfigBuilder() { FailGetValues = true };
builder.Initialize("Josef", new NameValueCollection() { { "mode", "Expand" } });
builder.ProcessConfigurationSection(GetAppSettings());
Assert.IsTrue(true); // I hate implicit success. ;)
Assert.True(true); // I hate implicit success. ;)
}

Просмотреть файл

@ -2,12 +2,11 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using Microsoft.Configuration.ConfigurationBuilders;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Test
{
[TestClass]
public class CommonBuilderTests
{
public static NameValueCollection CommonKeyValuePairs = new NameValueCollection() {
@ -28,16 +27,13 @@ namespace Test
builder.Initialize(name, attrs ?? new NameValueCollection());
// Gets what is there.
Assert.AreEqual(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"),
$"GetValue[{name}]: Failed to retrieve existing value.");
Assert.Equal(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"));
// Does not get what is not there.
Assert.IsNull(builder.GetValue("This_Value_Does_Not_Exist"),
$"GetValue[{name}]: Returned non-null value for a key that doesn't exist.");
Assert.Null(builder.GetValue("This_Value_Does_Not_Exist"));
// Is NOT case-sensitive.
Assert.AreEqual(CommonKeyValuePairs["TestKey"], builder.GetValue("testkey"),
$"GetValue[{name}]: Failed to retrieve existing value for case-insensitive key.");
Assert.Equal(CommonKeyValuePairs["TestKey"], builder.GetValue("testkey"));
}
public static void GetValue_Prefix1(KeyValueConfigBuilder builder, string name, NameValueCollection attrs = null)
@ -47,10 +43,8 @@ namespace Test
builder.Initialize(name, attrs);
// Does not care about prefix...
Assert.AreEqual(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"),
$"GetValue_Prefix1[{name}]: Failed to retrieve first existing value.");
Assert.AreEqual(CommonKeyValuePairs["Prefix_TestKey"], builder.GetValue("Prefix_TestKey"),
$"GetValue_Prefix1[{name}]: Failed to retrieve second existing value.");
Assert.Equal(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"));
Assert.Equal(CommonKeyValuePairs["Prefix_TestKey"], builder.GetValue("Prefix_TestKey"));
}
public static void GetValue_Prefix2(KeyValueConfigBuilder builder, string name, NameValueCollection attrs = null)
@ -61,10 +55,8 @@ namespace Test
builder.Initialize(name, attrs);
// or stripPrefix...
Assert.AreEqual(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"),
$"GetValue_Prefix2[{name}]: Failed to retrieve first existing value.");
Assert.AreEqual(CommonKeyValuePairs["Prefix_TestKey"], builder.GetValue("Prefix_TestKey"),
$"GetValue_Prefix2[{name}]: Failed to retrieve second existing value.");
Assert.Equal(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"));
Assert.Equal(CommonKeyValuePairs["Prefix_TestKey"], builder.GetValue("Prefix_TestKey"));
}
public static void GetValue_Prefix3(KeyValueConfigBuilder builder, string name, NameValueCollection attrs = null)
@ -74,10 +66,8 @@ namespace Test
builder.Initialize(name, attrs);
// even if there is no prefix given.
Assert.AreEqual(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"),
$"GetValue_Prefix3[{name}]: Failed to retrieve dirst existing value.");
Assert.AreEqual(CommonKeyValuePairs["Prefix_TestKey"], builder.GetValue("Prefix_TestKey"),
$"GetValue_Prefix3[{name}]: Failed to retrieve second existing value.");
Assert.Equal(CommonKeyValuePairs["TestKey"], builder.GetValue("TestKey"));
Assert.Equal(CommonKeyValuePairs["Prefix_TestKey"], builder.GetValue("Prefix_TestKey"));
}
@ -93,15 +83,12 @@ namespace Test
var allValues = builder.GetAllValues("");
// Has all the test values
Assert.AreEqual(CommonKeyValuePairs["TestKey"], GetValueFromCollection(allValues, "TestKey"),
$"GetAllValues[{name}]: Failed to retrieve first existing value.");
Assert.AreEqual(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"),
$"GetAllValues[{name}]: Failed to retrieve second existing value.");
Assert.Equal(CommonKeyValuePairs["TestKey"], GetValueFromCollection(allValues, "TestKey"));
Assert.Equal(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"));
// Does not contain what is not there.
// This would be a super wierd one to fail.
Assert.IsNull(GetValueFromCollection(allValues, "This_Value_Does_Not_Exist"),
$"GetAllValues[{name}]: Returned non-null value for a key that doesn't exist.");
Assert.Null(GetValueFromCollection(allValues, "This_Value_Does_Not_Exist"));
}
public static void GetAllValues_Prefix1(KeyValueConfigBuilder builder, string name, NameValueCollection attrs = null)
@ -113,12 +100,10 @@ namespace Test
var allValues = builder.GetAllValues("Prefix_");
// Has all the test values
Assert.AreEqual(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"),
$"GetAllValues_Prefix1[{name}]: Failed to retrieve first existing value.");
Assert.Equal(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"));
// Does not contain what is not there.
Assert.IsNull(GetValueFromCollection(allValues, "TestKey"),
$"GetAllValues_Prefix1[{name}]: Returned non-null value for a key that doesn't exist.");
Assert.Null(GetValueFromCollection(allValues, "TestKey"));
}
public static void GetAllValues_Prefix2(KeyValueConfigBuilder builder, string name, NameValueCollection attrs = null)
@ -132,12 +117,10 @@ namespace Test
var allValues = builder.GetAllValues("Prefix_");
// Has all the test values
Assert.AreEqual(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"),
$"GetAllValues_Prefix2[{name}]: Failed to retrieve first existing value.");
Assert.Equal(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"));
// Does not contain what is not there.
Assert.IsNull(GetValueFromCollection(allValues, "TestKey"),
$"GetAllValues_Prefix2[{name}]: Returned non-null value for a key that doesn't exist.");
Assert.Null(GetValueFromCollection(allValues, "TestKey"));
}
public static void GetAllValues_Prefix3(KeyValueConfigBuilder builder, string name, NameValueCollection attrs = null)
@ -149,10 +132,8 @@ namespace Test
var allValues = builder.GetAllValues("");
// Has all the test values
Assert.AreEqual(CommonKeyValuePairs["TestKey"], GetValueFromCollection(allValues, "TestKey"),
$"GetAllValues_Prefix3[{name}]: Failed to retrieve first existing value.");
Assert.AreEqual(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"),
$"GetAllValues_Prefix3[{name}]: Failed to retrieve second existing value.");
Assert.Equal(CommonKeyValuePairs["TestKey"], GetValueFromCollection(allValues, "TestKey"));
Assert.Equal(CommonKeyValuePairs["Prefix_TestKey"], GetValueFromCollection(allValues, "Prefix_TestKey"));
}

Просмотреть файл

@ -1,11 +1,10 @@
using System;
using Microsoft.Configuration.ConfigurationBuilders;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Test
{
[TestClass]
public class EnvironmentTests
{
public EnvironmentTests()
@ -18,7 +17,7 @@ namespace Test
// ======================================================================
// CommonBuilderTests
// ======================================================================
[TestMethod]
[Fact]
public void Environment_GetValue()
{
CommonBuilderTests.GetValue(new EnvironmentConfigBuilder(), "EnvironmentBuilder");
@ -27,7 +26,7 @@ namespace Test
CommonBuilderTests.GetValue_Prefix3(new EnvironmentConfigBuilder(), "EnvironmentBuilderPrefix3");
}
[TestMethod]
[Fact]
public void Environment_GetAllValues()
{
CommonBuilderTests.GetAllValues(new EnvironmentConfigBuilder(), "EnvironmentBuilder");

Просмотреть файл

@ -2,11 +2,11 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Test")]
[assembly: AssemblyTitle("Microsoft.Configuration.ConfigurationBuilders.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Test")]
[assembly: AssemblyProduct("Microsoft.Configuration.ConfigurationBuilders.Test")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Просмотреть файл

@ -1,11 +1,10 @@
using System;
using Microsoft.Configuration.ConfigurationBuilders;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Test
{
[TestClass]
public class SimpleJsonTests
{
public SimpleJsonTests()
@ -24,12 +23,12 @@ namespace Test
// ======================================================================
// CommonBuilderTests
// ======================================================================
[TestMethod]
[Fact]
public void SimpleJson_GetValue()
{
}
[TestMethod]
[Fact]
public void SimpleJson_GetAllValues()
{
}

Просмотреть файл

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props')" />
<Import Project="..\..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
<Import Project="..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.props" Condition="Exists('..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -39,16 +41,23 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MSTest.TestFramework.1.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\MSTest.TestFramework.1.3.0\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CommonBuilderTests.cs" />
@ -60,19 +69,19 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Base\Base.csproj">
<ProjectReference Include="..\..\src\Base\Base.csproj">
<Project>{f382fbf8-146d-4968-a199-90d37f9ef9a7}</Project>
<Name>Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Environment\Environment.csproj">
<ProjectReference Include="..\..\src\Environment\Environment.csproj">
<Project>{c6530e81-d8d8-47a8-912e-d2939f801835}</Project>
<Name>Environment</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Json\Json.csproj">
<ProjectReference Include="..\..\src\Json\Json.csproj">
<Project>{84e0ce5d-4af2-414f-a940-22b3f93fc727}</Project>
<Name>Json</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\UserSecrets\UserSecrets.csproj">
<ProjectReference Include="..\..\src\UserSecrets\UserSecrets.csproj">
<Project>{c60d6cbb-d513-4692-81a6-0be5d45e4702}</Project>
<Name>UserSecrets</Name>
</ProjectReference>
@ -80,14 +89,21 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\xunit.analyzers.0.7.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.props'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.targets'))" />
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
<Error Condition="!Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
</Target>
<Import Project="..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.1.3.0\build\net45\MSTest.TestAdapter.targets')" />
<Import Project="..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.targets" Condition="Exists('..\..\packages\xunit.runner.msbuild.2.3.1\build\net452\xunit.runner.msbuild.targets')" />
<Import Project="..\..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
</Project>

Просмотреть файл

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.3.0" targetFramework="net471" />
<package id="MSTest.TestFramework" version="1.3.0" targetFramework="net471" />
</packages>

Просмотреть файл

@ -1,11 +1,10 @@
using System;
using Microsoft.Configuration.ConfigurationBuilders;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Test
{
[TestClass]
public class UserSecretsTests
{
public UserSecretsTests()
@ -26,12 +25,12 @@ namespace Test
// ======================================================================
// CommonBuilderTests
// ======================================================================
[TestMethod]
[Fact]
public void UserSecrets_GetValue()
{
}
[TestMethod]
[Fact]
public void UserSecrets_GetAllValues()
{
}

Просмотреть файл

@ -2,33 +2,32 @@
using System.IO;
using System.Reflection;
using Microsoft.Configuration.ConfigurationBuilders;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace Test
{
[TestClass]
public class UtilsTests
{
[TestMethod]
[Fact]
public void Utils_MapPath()
{
// Absolute paths
Assert.AreEqual(Utils.MapPath(@"C:\Windows\System32"), Path.GetFullPath(@"C:\Windows\System32"));
Assert.AreEqual(Utils.MapPath(@"/Windows"), Path.GetFullPath(@"/Windows"));
Assert.Equal(Utils.MapPath(@"C:\Windows\System32"), Path.GetFullPath(@"C:\Windows\System32"));
Assert.Equal(Utils.MapPath(@"/Windows"), Path.GetFullPath(@"/Windows"));
// Relative paths
Assert.AreEqual(Utils.MapPath(@"foo\bar\baz"), Path.GetFullPath(@"foo\bar\baz"));
Assert.AreEqual(Utils.MapPath(@"..\foo\..\baz"), Path.GetFullPath(@"..\foo\..\baz"));
Assert.Equal(Utils.MapPath(@"foo\bar\baz"), Path.GetFullPath(@"foo\bar\baz"));
Assert.Equal(Utils.MapPath(@"..\foo\..\baz"), Path.GetFullPath(@"..\foo\..\baz"));
// Home-relative paths
string baseDir = AppDomain.CurrentDomain.BaseDirectory;
Assert.AreEqual(Utils.MapPath(@"~\"), baseDir);
Assert.AreEqual(Utils.MapPath(@"~/"), baseDir);
Assert.AreEqual(Utils.MapPath(@"~/hello"), Path.Combine(baseDir, @"hello"));
Assert.AreEqual(Utils.MapPath(@"~\good-bye\"), Path.Combine(baseDir, @"good-bye\"));
Assert.Equal(Utils.MapPath(@"~\"), baseDir);
Assert.Equal(Utils.MapPath(@"~/"), baseDir);
Assert.Equal(Utils.MapPath(@"~/hello"), Path.Combine(baseDir, @"hello"));
Assert.Equal(Utils.MapPath(@"~\good-bye\"), Path.Combine(baseDir, @"good-bye\"));
}
[TestMethod]
[Fact]
public void Utils_MapPath_AspNet()
{
// Fake running in ASP.Net
@ -36,8 +35,7 @@ namespace Test
// Since HostingEnvironment is not actually loaded, Utils.ServerMapPath should spit our string right back at us.
string badPath = ")*@#__This_is_not_a_valid_Path_and_will_error_Unless_we_Get_into_ServerMapPath()}}}}!";
Assert.AreEqual(Utils.MapPath(badPath), badPath,
$"Utils_MapPath_AspNet: Did not enter ServerMapPath()");
Assert.Equal(Utils.MapPath(badPath), badPath);
// Stop faking ASP.Net
FakeAspNet(false);

Просмотреть файл

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.3.1" targetFramework="net471" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net471" />
<package id="xunit.analyzers" version="0.7.0" targetFramework="net471" />
<package id="xunit.assert" version="2.3.1" targetFramework="net471" />
<package id="xunit.core" version="2.3.1" targetFramework="net471" />
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net471" />
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net471" />
<package id="xunit.runner.msbuild" version="2.3.1" targetFramework="net471" developmentDependency="true" />
<package id="xunit.runner.visualstudio" version="2.3.1" targetFramework="net471" developmentDependency="true" />
</packages>

Просмотреть файл

@ -1,32 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<RepositoryRootEx Condition="'$(RepositoryRootEx)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),MicrosoftConfigurationBuilders.sln))\</RepositoryRootEx>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
<BinPath>$(RepositoryRootEx)bin\</BinPath>
<ObjPath>$(RepositoryRootEx)obj\</ObjPath>
<OutputPath>$(BinPath)$(Configuration)\</OutputPath>
<IntermediateOutputPath>$(ObjPath)$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup>
<TestRoot>$(RepositoryRoot)\test\Microsoft.Configuration.ConfigurationBuilders.Test</TestRoot>
<BuildingTestProject Condition="$(MSBuildProjectDirectory.ToLower().Contains($(TestRoot.ToLower())))">true</BuildingTestProject>
</PropertyGroup>
<!--
<Import Project="$(MSBuildThisFileDirectory)CI\CITask.targets" Condition="Exists('$(MSBuildThisFileDirectory)CI\CITask.targets')"/>
-->
<PropertyGroup>
<AssemblyPath Condition="'$(CodeSignEnabled)' == 'true'">$(CodeSignOutputPath)</AssemblyPath>
<AssemblyPath Condition="'$(AssemblyPath)' == ''">$(OutputPath)</AssemblyPath>
</PropertyGroup>
<PropertyGroup>
<CustomAfterProjectTargets>$(MSBuildThisFileDirectory)MicrosoftConfigurationBuilders.Extensions.targets</CustomAfterProjectTargets>
</PropertyGroup>
</Project>

Просмотреть файл

@ -1,8 +0,0 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Update NuGet Package version for nightly build-->
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.nuproj'">
<NuGetPackageVersion Condition="'$(UpdateNightlyPackages)' == 'true'">$(NuGetPackageVersion)-b$(VersionBuild)</NuGetPackageVersion>
</PropertyGroup>
</Project>

Просмотреть файл

@ -1,59 +1,89 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CustomBeforeProjectTargets>$(MSBuildThisFileDirectory)MicrosoftConfigurationBuilders.Extensions.settings.targets</CustomBeforeProjectTargets>
<CustomAfterMicrosoftCommonTargets>$(MSBuildThisFileDirectory)version.targets;$(MSBuildThisFileDirectory)signing.targets</CustomAfterMicrosoftCommonTargets>
<RepositoryRoot>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'MicrosoftConfigurationBuilders.sln'))\</RepositoryRoot>
<SolutionDir>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'MicrosoftConfigurationBuilders.sln'))\</SolutionDir>
</PropertyGroup>
<Import Project="$(RepositoryRoot)\packages\microbuild.core.0.3.0\build\MicroBuild.Core.props"
Condition="Exists('$(RepositoryRoot)\packages\microbuild.core.0.3.0\build\MicroBuild.Core.props')" />
<Import Project="$(RepositoryRoot)\packages\microbuild.core.0.3.0\build\MicroBuild.Core.targets"
Condition="Exists('$(RepositoryRoot)\packages\microbuild.core.0.3.0\build\MicroBuild.Core.targets')" />
<Import Project="$(CustomBeforeProjectTargets)" Condition="Exists('$(CustomBeforeProjectTargets)')" Label="Pre-targets Build Extensibility Point"/>
<!-- Configurable properties-->
<PropertyGroup>
<!-- Versioning:
Major: 'Major' for Assembly, File, Info, and Package.
Minor: 'Minor' for Assembly, File, Info, and Package.
Build: Third (auto-generated) for File and Info. (Assembly is always 0)
Revision: 'Revision' for Assembly and File.
Release: Third for Info and Package.
Update package and file without touching assembly, except for major releases.
-->
<BuildQuality Condition="'$(BuildQuality)' == ''">rtm</BuildQuality>
<VersionStartYear>2016</VersionStartYear>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionRelease>0</VersionRelease>
<VersionRevision>0</VersionRevision>
<VersionRelease>1</VersionRelease>
<VersionRelease Condition="'$(BuildQuality)' != 'rtm'">$(VersionRelease)-$(BuildQuality)</VersionRelease>
</PropertyGroup>
<PropertyGroup Label="NuGet package dependencies">
<NuGetPackageVersion>$(VersionMajor).$(VersionMinor).1</NuGetPackageVersion>
<MicrosoftConfigurationBuildersNuGetPackageVersion>$(VersionMajor).$(VersionMinor).1</MicrosoftConfigurationBuildersNuGetPackageVersion>
<NuGetPackageVersion>$(VersionMajor).$(VersionMinor).$(VersionRelease)</NuGetPackageVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.nuproj'">
<NuGetPackageVersion Condition="'$(UpdateNightlyPackages)' == 'true'">$(NuGetPackageVersion)-b$(VersionBuild)</NuGetPackageVersion>
</PropertyGroup>
<!-- Default properties -->
<PropertyGroup>
<RepositoryRoot Condition="'$(RepositoryRoot)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), MicrosoftConfigurationBuilders.sln))\</RepositoryRoot>
<SolutionDir>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), MicrosoftConfigurationBuilders.sln))\</SolutionDir>
</PropertyGroup>
<PropertyGroup Label="Common Configuration">
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
<OutputPath>$(RepositoryRoot)bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>$(RepositoryRoot)obj\$(Configuration)\$(MSBuildProjectName)\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup>
<OutputPath>$(RepositoryRoot).binaries\bin\$(Configuration)\</OutputPath>
<IntermediateOutputRoot>$(RepositoryRoot).binaries\obj\$(Configuration)\</IntermediateOutputRoot>
<IntermediateOutputPath>$(IntermediateOutputRoot)$(MSBuildProjectName)\</IntermediateOutputPath>
<AssemblyPath Condition="'$(CodeSignEnabled)' == 'true'">$(CodeSignOutputPath)</AssemblyPath>
<AssemblyPath Condition="'$(AssemblyPath)' == ''">$(OutputPath)</AssemblyPath>
<NuGetOutputPath>$(AssemblyPath)Packages</NuGetOutputPath>
<NuGetSymbolsOutputPath>$(AssemblyPath)\SymbolPackages</NuGetSymbolsOutputPath>
<TestOutputPath>$(OutputPath)test\</TestOutputPath>
</PropertyGroup>
<PropertyGroup>
<ReferencePackagesPath>$(RepositoryRoot)packages\</ReferencePackagesPath>
<PropertyGroup Label="Nuget Configuration">
<NuGetOutputPath>$(RepositoryRoot).binaries\Packages\$(Configuration)</NuGetOutputPath>
<NuGetPackSymbols Condition="'$(NuGetPackSymbols)' == ''">true</NuGetPackSymbols>
<ReferencePackagesPath>$(RepositoryRoot)packages\</ReferencePackagesPath>
<SourceRootFullPath>$(RepositoryRoot)\src\$(MSBuildProjectName)\</SourceRootFullPath>
</PropertyGroup>
<PropertyGroup>
<CustomAfterMicrosoftCommonTargets>$(RepositoryRoot)tools\MicrosoftConfigurationBuilders.targets</CustomAfterMicrosoftCommonTargets>
<CustomAfterNuGetProjTargets>$(CustomAfterMicrosoftCommonTargets)</CustomAfterNuGetProjTargets>
<TestRoot>$(RepositoryRoot)\test\Microsoft.Configuration.ConfigurationBuilders.Test</TestRoot>
<BuildingTestProject Condition="$(MSBuildProjectDirectory.ToLower().Contains($(TestRoot.ToLower())))">true</BuildingTestProject>
</PropertyGroup>
<Target Name="PreventReferenceCopy" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
</ItemGroup>
</Target>
<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuSpecFile">
<PropertyGroup>
<NuSpecProperties>
NuGetPackageVersion=$(NuGetPackageVersion);
NuGetPackageId=$(NuGetPackageId);
</NuSpecProperties>
</PropertyGroup>
</Target>
<Target Name="SuperClean" AfterTargets="Clean" Condition="'$(MSBuildProjectExtension)' != '.nuproj'">
<RemoveDir Directories="$(OutputPath)" />
<RemoveDir Directories="$(IntermediateOutputRoot)" />
</Target>
<Target Name="SuperCleanPackage" AfterTargets="Clean" Condition="'$(MSBuildProjectExtension)' == '.nuproj'">
<RemoveDir Directories="$(NuGetOutputPath)" />
<RemoveDir Directories="$(NuGetSymbolsOutputPath)" />
</Target>
</Project>

Просмотреть файл

@ -1,29 +0,0 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Build order -->
<PropertyGroup>
<BuildDependsOn>SetNuSpecProperties;$(BuildDependsOn)</BuildDependsOn>
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)version.targets"/>
<!-- Post-targets computed properties. -->
<PropertyGroup>
<SatelliteContractVersion Condition="'$(SatelliteContractVersion)' == ''">$(AssemblyVersion)</SatelliteContractVersion>
</PropertyGroup>
<Import Project="$(CustomAfterProjectTargets)" Condition="Exists('$(CustomAfterProjectTargets)')" Label="Post-targets Build Extensibility Point" />
<!-- Target definitions -->
<Target Name="SetNuSpecProperties">
<PropertyGroup>
<NuSpecProperties>
NuGetPackageVersion=$(NuGetPackageVersion);
NuGetPackageId=$(NuGetPackageId);
MicrosoftConfigurationBuildersNuGetPackageVersion=$(MicrosoftConfigurationBuildersNuGetPackageVersion);
</NuSpecProperties>
</PropertyGroup>
</Target>
</Project>

Просмотреть файл

@ -269,7 +269,7 @@ NuGetPack: Creates a nuget package.
<PropertyGroup>
<NuSpecProperties>@(NuSpecProperties)</NuSpecProperties>
<NuGetPackOptions Condition="'$(NuGetPackOptions)' == '' AND '$(NuGetPackSymbols)' != 'true'">-NoPackageAnalysis</NuGetPackOptions>
<NuGetPackOptions Condition="'$(NuGetPackOptions)' == '' AND '$(NuGetPackSymbols)' == 'true'">-NoPackageAnalysis -symbols</NuGetPackOptions>
<NuGetPackOptions Condition="'$(NuGetPackOptions)' == '' AND '$(NuGetPackSymbols)' == 'true'">-NoPackageAnalysis -NoDefaultExcludes -symbols</NuGetPackOptions>
<!-- BuildCommand is defined in nuget.targets file -->
<BuildCommand>$(BuildCommand.Replace('-symbols', ''))</BuildCommand>
<BuildCommand>$(BuildCommand.Replace('/symbols', ''))</BuildCommand>

Просмотреть файл

@ -1,12 +0,0 @@
<Project DefaultTargets="Clean" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="SpicNSpan" AfterTargets="Clean"> <!-- common vars https://msdn.microsoft.com/en-us/library/c02as0cs.aspx?f=255&MSPPError=-2147217396 -->
<!-- Remove bin folder -->
<RemoveDir Directories="$(MSBuildProjectDirectory)\bin" />
<!-- Remove obj folder -->
<RemoveDir Directories="$(MSBuildProjectDirectory)\obj" />
</Target>
</Project>

21
tools/signing.targets Normal file
Просмотреть файл

@ -0,0 +1,21 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetFilesToSign" BeforeTargets="SignFiles" Condition="'$(SignAssembly)' == 'true'">
<ItemGroup Condition="'$(MSBuildProjectExtension)' != '.nuproj'">
<FilesToSign Include="$(TargetPath)">
<Authenticode>Microsoft</Authenticode>
<StrongName>MsSharedLib72</StrongName>
</FilesToSign>
</ItemGroup>
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.nuproj'">
<OutDir>$(PackageOutputDir)</OutDir>
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.nuproj'">
<FilesToSign Include="$(NuGetPackTargetFile)">
<Authenticode>NuGet</Authenticode>
</FilesToSign>
</ItemGroup>
</Target>
</Project>

Просмотреть файл

@ -38,6 +38,10 @@ Project global versioning targets.
<NuGetPackageVersion Condition="'$(NuGetPackageVersion)' == ''">$(VersionMajor).$(VersionMinor).$(VersionRelease)</NuGetPackageVersion>
</PropertyGroup>
<PropertyGroup>
<SatelliteContractVersion Condition="'$(SatelliteContractVersion)' == ''">$(AssemblyVersion)</SatelliteContractVersion>
</PropertyGroup>
<ItemGroup Condition="'$(VersionFileGenerationEnabled)' == 'true'">
<Compile Include="$(AssemblyVersionFile)" />
</ItemGroup>