├── .gitignore ├── HumbleConfig.png ├── LICENSE ├── README.md ├── appveyor.yml ├── build-before_build.ps1 ├── build-on_finish.ps1 ├── install.ps1 └── src ├── HumbleConfig.Caching.Tests ├── CachingConfigurationSourceDecoratorTests │ ├── CachingConfigurationSourceDecoratorForNoneExistingAppSettingKey.cs │ ├── CachingConfigurationSourceDecoratorForNoneExistingAppSettingKeyWithValueCached.cs │ ├── CachingConfigurationSourceDecoratorTestsForExistingKey.cs │ └── CachingConfigurationSourceDecoratorTestsForExistingKeyWithValueCached.cs ├── HumbleConfig.Caching.Tests.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.Caching ├── CacheKeyCreator.cs ├── CachingConfigurationSourceDecorator.cs ├── CachingExtentions.cs ├── HumbleConfig.Caching.csproj ├── HumbleConfig.Caching.nuspec ├── ICacheKeyCreator.cs └── Properties │ └── AssemblyInfo.cs ├── HumbleConfig.ConfigR.Tests ├── ConfigRSourceTests │ ├── ConfigRSourceTestsForExistingConfigRKey.cs │ └── ConfigRSourceTestsForNoneExistingConfigRKey.cs ├── HumbleConfig.ConfigR.Tests.csproj ├── Properties │ └── AssemblyInfo.cs ├── app.config └── packages.config ├── HumbleConfig.ConfigR ├── ConfigRExtensions.cs ├── ConfigRSource.cs ├── HumbleConfig.ConfigR.csproj ├── HumbleConfig.ConfigR.nuspec ├── Properties │ └── AssemblyInfo.cs ├── app.config └── packages.config ├── HumbleConfig.ConfigurationManager.Tests ├── App.config ├── ConfigurationManagerSourceTests │ ├── ConfigurationManagerSourceTestsForExistingAppSettingKey.cs │ └── ConfigurationManagerSourceTestsForNoneExistingAppSettingKey.cs ├── HumbleConfig.ConfigurationManager.Tests.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.ConfigurationManager ├── ConfigurationManagerExtensions.cs ├── ConfigurationManagerSource.cs ├── HumbleConfig.ConfigurationManager.csproj ├── HumbleConfig.ConfigurationManager.nuspec ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.Credstash.Tests ├── CredstashSourceTests │ ├── CredstashSourceTestsForExistingKey.cs │ └── CredstashSourceTestsForNoneExistingKey.cs ├── HumbleConfig.Credstash.Tests.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.Credstash ├── CredstashExtensions.cs ├── CredstashSource.cs ├── HumbleConfig.Credstash.csproj ├── HumbleConfig.Credstash.nuspec ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.EnvironmentVariables.Tests ├── EnvironmentVariablesSourceTests │ ├── EnvironmentVariablesSourceTestsForExistingEnvironmentVariable.cs │ └── EnvironmentVariablesSourceTestsForNoneExistingEnvironmentVariable.cs ├── HumbleConfig.EnvironmentVariables.Tests.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.EnvironmentVariables ├── EnvironmentVariablesExtensions.cs ├── EnvironmentVariablesSource.cs ├── HumbleConfig.EnvironmentVariables.csproj ├── HumbleConfig.EnvironmentVariables.nuspec └── Properties │ └── AssemblyInfo.cs ├── HumbleConfig.FunctionalTests ├── App.config ├── CacheConfigurationTests.cs ├── ConfigurationTests.cs ├── ConfigurationTestsWithKeyPostfixer.cs ├── ConfigurationTestsWithKeyPrefixer.cs ├── CredstashConfigurationTests.cs ├── ExpiredCacheConfigurationTests.cs ├── HumbleConfig.FunctionalTests.csproj ├── HumbleConfig.FunctionalTests.dll.csx ├── KeyFormatterConfigurationTests.cs ├── MultiCacheConfigurationTests.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.MongoDb.Tests ├── HumbleConfig.MongoDb.Tests.csproj ├── MongoDbSourceTests │ ├── ConfigRSourceTestsForExistingConfigRKey.cs │ └── MongoDbSourceTestsForNoneExistingKey.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.MongoDb ├── AppSetting.cs ├── HumbleConfig.MongoDb.csproj ├── HumbleConfig.MongoDb.nuspec ├── MongoDbExtensions.cs ├── MongoDbSource.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── HumbleConfig.Tests ├── ConfigurationSourceTestsForExistingKey`1.cs ├── ConfigurationSourceTestsForNoneExistingKey`1.cs ├── ConfigurationTests │ ├── ConfigurationTestsForKeyFormatter.cs │ ├── ConfigurationTestsForMultipleSourcesAndAllHaveMatchingKeys.cs │ ├── ConfigurationTestsForMultipleSourcesAndOnlyTheLastHasAMatchingKey.cs │ ├── ConfigurationTestsForNoSourcesForNoneNullableValues.cs │ ├── ConfigurationTestsForNoSourcesForNullableValues.cs │ ├── ConfigurationTestsForOneSourceThatHasAMatchingKey.cs │ ├── ConfigurationTestsForOneSourceThatHasNoMatchingKeyForNoneNullables.cs │ └── ConfigurationTestsForOneSourceThatHasNoMatchingKeyForNullables.cs ├── HumbleConfig.Tests.csproj ├── InMemory │ └── InMemorySourceTests │ │ ├── InMemorySourceTestsForNoneExistingAppSettingKey.cs │ │ └── InMemorySourceTestsSourceTestsForExistingAppSettingKey.cs ├── KeyFormatters │ ├── DefaultKeyFormatterTests.cs │ ├── KeyFormatterConfigurationSourceDecoratorTests.cs │ ├── KeyPostfixerTests.cs │ └── KeyPrefixerTests.cs ├── NonNullableTestFixtureCases.cs ├── NullableTestFixtureCases.cs ├── Properties │ └── AssemblyInfo.cs ├── Stubs │ └── ConfigurationSourceStub.cs ├── TypeArgsTestFixtureData.cs └── packages.config ├── HumbleConfig.sln └── HumbleConfig ├── Configuration.cs ├── ConfigurationSourceResult.cs ├── ConfigurationSourceWrapper.cs ├── HumbleConfig.csproj ├── HumbleConfig.nuspec ├── IConfiguration.cs ├── IConfigurationConfigurator.cs ├── IConfigurationSource.cs ├── IConfigurationSourceConfigurator.cs ├── IKeyFormatter.cs ├── InMemory ├── InMemoryExtensions.cs └── InMemorySource.cs ├── KeyFormatters ├── DefaultKeyFormatter.cs ├── KeyFormatterConfigurationSourceDecorator.cs ├── KeyFormatterExtensions.cs ├── KeyPostfixer.cs └── KeyPrefixer.cs └── Properties └── AssemblyInfo.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /HumbleConfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevbite/HumbleConfig/a0f78e1dec6c2deac0b892e1950835a107c3c1d9/HumbleConfig.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kevin Smith 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HumbleConfig 2 | 3 | *Stop writing boiler plate configuration code to pull from different sources.* 4 | 5 | HumbleConfig allows developers to concentrate on writing the application instead of managing all the configuration locations. 6 | 7 | [![install from nuget](http://img.shields.io/nuget/v/HumbleConfig.svg?style=flat-square)](https://www.nuget.org/packages/HumbleConfig)[![downloads](http://img.shields.io/nuget/dt/HumbleConfig.svg?style=flat-square)](https://www.nuget.org/packages/HumbleConfig) 8 | [![Build status](https://ci.appveyor.com/api/projects/status/bodd6hrcoltpco6i/branch/master?svg=true)](https://ci.appveyor.com/project/kevbite/humbleconfig/branch/master) 9 | 10 | ### Installing packages 11 | 12 | ```powershell 13 | PM> Install-Package HumbleConfig 14 | ``` 15 | ```powershell 16 | PM> Install-Package HumbleConfig.ConfigurationManager 17 | ``` 18 | ```powershell 19 | PM> Install-Package HumbleConfig.EnvironmentVariables 20 | ``` 21 | ```powershell 22 | PM> Install-Package HumbleConfig.ConfigR 23 | ``` 24 | ```powershell 25 | PM> Install-Package HumbleConfig.MongoDb 26 | ``` 27 | ```powershell 28 | PM> Install-Package HumbleConfig.Credstash 29 | ``` 30 | ```powershell 31 | PM> Install-Package HumbleConfig.Caching 32 | ``` 33 | ### How to use it? 34 | First, create an `Configuration` instance: 35 | ```csharp 36 | var configuration = new Configuration(); 37 | ``` 38 | Then, configure the sources for configuration: 39 | ```csharp 40 | configuration.AddEnvironmentVariables() 41 | .AddConfigurationManager() 42 | .AddConfigR() 43 | .AddMongoDb("mongodb://localhost/settings", "appSettings") 44 | .WithDefaultMemoryCache(TimeSpan.FromHours(1)) 45 | .AddCredstash(RegionEndpoint.EUWest1) 46 | .WithCache(MemoryCache.Default, () => new CacheItemPolicy()) 47 | .GetConfiguration(); 48 | ``` 49 | The order in which we add the configuration sources will determine which configuration values will take priority, in the above example environment variables will override any configuration values within mongodb. 50 | 51 | Now knowing the priority of configuration values, we can add some default values by using a InMemory source: 52 | ```csharp 53 | var defaults = new Dictionary() { {"UserName", "Kevin.Smith"} }; 54 | 55 | configuration.AddInMemory(defaults); 56 | ``` 57 | Once we're happy with our configuration we can pull out an app setting: 58 | ```csharp 59 | var value = await configuration.GetAppSettingAysnc("key"); 60 | ``` 61 | ### Key formatters 62 | Ever been in config hell where you don't know what key is used where. 63 | This is where key formatters comes in useful, HumbleConfig has inbuilt support for a few key formatters. 64 | 65 | ##### KeyPrefixer 66 | The key prefixer allows you to specify a prefix that all your config keys should include. 67 | For example having a prefix of `HumbleConfig:` would have the following output: 68 | 69 | | Key | Source Key | 70 | | -------|------------------ | 71 | | Key1 | HumbleConfig:Key1 | 72 | | Key2 | HumbleConfig:Key2 | 73 | | Key3 | HumbleConfig:Key3 | 74 | 75 | To setup this the key prefixer on our configuration object we just call `WithKeyPrefixer`: 76 | ```csharp 77 | configuration.WithKeyPrefixer("HumbleConfig:") 78 | ``` 79 | 80 | ##### KeyPostfixer 81 | The key postfixer allows you to specify a postfix that all your config keys should include. 82 | For example having a postfix of `.HumbleConfig` would have the following output: 83 | 84 | | Key | Source Key | 85 | | -------|------------------ | 86 | | Key1 | Key1.HumbleConfig | 87 | | Key2 | Key2.HumbleConfig | 88 | | Key3 | Key3.HumbleConfig | 89 | 90 | To setup this the key postfixer on our configuration object we just call `WithKeyPostfixer`: 91 | ```csharp 92 | configuration.WithKeyPostfixer(".HumbleConfig") 93 | ``` 94 | 95 | #### Key formatters on sources 96 | 97 | It is also possible to use key formatter on individual sources, for example: 98 | ``` 99 | configuration.AddEnvironmentVariables().WithKeyPostfixer(".production") 100 | ``` 101 | This will only apply the key formatter to the environment variables source. 102 | 103 | ### Contributing 104 | 105 | 1. Fork 106 | 1. Hack! 107 | 1. Pull Request. 108 | 109 | ### 110 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | - 2 | branches: 3 | only: 4 | - master 5 | skip_tags: true 6 | version: 4.2.1 7 | 8 | assembly_info: 9 | assembly_version: '{version}' 10 | assembly_file_version: '{version}' 11 | assembly_informational_version: '{version}' 12 | file: AssemblyInfo.* 13 | patch: true 14 | 15 | os: Visual Studio 2017 16 | 17 | install: 18 | - ps: .\install.ps1 19 | 20 | before_build: 21 | - ps : .\build-before_build.ps1 22 | 23 | build: 24 | verbosity: minimal 25 | parallel: true 26 | publish_nuget: true 27 | 28 | configuration: Release 29 | cache: 30 | - src\packages -> **\packages.config 31 | 32 | services: 33 | - mongodb 34 | 35 | test: 36 | assemblies: 37 | - '**\*.Tests.dll' 38 | - '**\*.FunctionalTests.dll' 39 | categories: 40 | except: 41 | - Credstash 42 | 43 | artifacts: 44 | - path: '*.nupkg' 45 | 46 | on_finish: 47 | - ps : .\build-on_finish.ps1 48 | 49 | deploy: 50 | - provider: Environment 51 | name: NuGet.org 52 | on: 53 | branch: master 54 | 55 | - provider: Environment 56 | name: GitHub 57 | on: 58 | branch: master 59 | 60 | - 61 | skip_tags: true 62 | version: 4.2.1-{branch}{build} 63 | 64 | assembly_info: 65 | assembly_version: '{version}' 66 | assembly_file_version: '{version}' 67 | assembly_informational_version: '{version}' 68 | file: AssemblyInfo.* 69 | patch: true 70 | 71 | os: Visual Studio 2017 72 | 73 | install: 74 | - ps: .\install.ps1 75 | 76 | before_build: 77 | - ps : .\build-before_build.ps1 78 | 79 | build: 80 | verbosity: minimal 81 | parallel: true 82 | publish_nuget: true 83 | 84 | configuration: Release 85 | cache: 86 | - src\packages -> **\packages.config 87 | 88 | services: 89 | - mongodb 90 | 91 | test: 92 | assemblies: 93 | - '**\*.Tests.dll' 94 | - '**\*.FunctionalTests.dll' 95 | categories: 96 | except: 97 | - Credstash 98 | 99 | artifacts: 100 | - path: '*.nupkg' 101 | 102 | on_finish: 103 | - ps : .\build-on_finish.ps1 -------------------------------------------------------------------------------- /build-before_build.ps1: -------------------------------------------------------------------------------- 1 | Write-Host "Restoring nuget packages" 2 | Push-Location -Path src 3 | nuget restore 4 | Pop-Location -------------------------------------------------------------------------------- /build-on_finish.ps1: -------------------------------------------------------------------------------- 1 | if ($env:DebugBuildWorker -like "true") 2 | { 3 | $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) 4 | } -------------------------------------------------------------------------------- /install.ps1: -------------------------------------------------------------------------------- 1 | Write-Host "Checking if pull request" 2 | if ([bool]$env:APPVEYOR_PULL_REQUEST_NUMBER) 3 | { 4 | Write-Host "Build is pull request - updating version" 5 | Update-AppveyorBuild -Version "0.0.0-pull-request-$($env:APPVEYOR_PULL_REQUEST_NUMBER)" 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching.Tests/CachingConfigurationSourceDecoratorTests/CachingConfigurationSourceDecoratorForNoneExistingAppSettingKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Caching; 3 | using System.Threading; 4 | using HumbleConfig.Tests; 5 | using Moq; 6 | using NUnit.Framework; 7 | 8 | namespace HumbleConfig.Caching.Tests.CachingConfigurationSourceDecoratorTests 9 | { 10 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 11 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 12 | public class CachingConfigurationSourceDecoratorForNoneExistingAppSettingKey : ConfigurationSourceTestsForNoneExistingKey 13 | { 14 | protected override IConfigurationSource CreateConfigurationSource() 15 | { 16 | var innerSource = new Mock(); 17 | innerSource.Setup(x => x.GetAppSettingAsync(It.IsAny(), It.IsAny())) 18 | .ReturnsAsync(ConfigurationSourceResult.FailedResult()); 19 | 20 | var source = new CachingConfigurationSourceDecorator(innerSource.Object, new CacheKeyCreator(Guid.NewGuid().ToString()), MemoryCache.Default, () => new CacheItemPolicy()); 21 | 22 | return source; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Caching.Tests/CachingConfigurationSourceDecoratorTests/CachingConfigurationSourceDecoratorForNoneExistingAppSettingKeyWithValueCached.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Caching; 3 | using System.Threading; 4 | using HumbleConfig.Tests; 5 | using Moq; 6 | using NUnit.Framework; 7 | 8 | namespace HumbleConfig.Caching.Tests.CachingConfigurationSourceDecoratorTests 9 | { 10 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 11 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 12 | public class CachingConfigurationSourceDecoratorForNoneExistingAppSettingKeyWithValueCached : ConfigurationSourceTestsForNoneExistingKey 13 | { 14 | protected override IConfigurationSource CreateConfigurationSource() 15 | { 16 | var objectCache = new Mock(); 17 | objectCache.Setup(x => x.Get(It.IsAny(), It.IsAny())) 18 | .Returns(ConfigurationSourceResult.FailedResult()); 19 | 20 | var innerSource = new Mock(); 21 | innerSource.Setup(x => x.GetAppSettingAsync(It.IsAny(), It.IsAny())) 22 | .Throws(new Exception("Should never get here")); 23 | 24 | var source = new CachingConfigurationSourceDecorator(innerSource.Object, new CacheKeyCreator(Guid.NewGuid().ToString()), objectCache.Object, () => new CacheItemPolicy()); 25 | 26 | return source; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Caching.Tests/CachingConfigurationSourceDecoratorTests/CachingConfigurationSourceDecoratorTestsForExistingKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Caching; 3 | using System.Threading; 4 | using HumbleConfig.Tests; 5 | using Moq; 6 | using NUnit.Framework; 7 | 8 | namespace HumbleConfig.Caching.Tests.CachingConfigurationSourceDecoratorTests 9 | { 10 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 11 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 12 | public class CachingConfigurationSourceDecoratorTestsForExistingKey : ConfigurationSourceTestsForExistingKey 13 | { 14 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue expectedValue) 15 | { 16 | var innerSource = new Mock(); 17 | var cancellationToken = new CancellationToken(); 18 | innerSource.Setup(x => x.GetAppSettingAsync(key, cancellationToken)) 19 | .ReturnsAsync(ConfigurationSourceResult.SuccessResult(expectedValue)); 20 | 21 | var source = new CachingConfigurationSourceDecorator(innerSource.Object, new CacheKeyCreator(Guid.NewGuid().ToString()), MemoryCache.Default, () => new CacheItemPolicy()); 22 | 23 | return source; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching.Tests/CachingConfigurationSourceDecoratorTests/CachingConfigurationSourceDecoratorTestsForExistingKeyWithValueCached.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Caching; 3 | using System.Threading; 4 | using HumbleConfig.Tests; 5 | using Moq; 6 | using NUnit.Framework; 7 | 8 | namespace HumbleConfig.Caching.Tests.CachingConfigurationSourceDecoratorTests 9 | { 10 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 11 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 12 | public class CachingConfigurationSourceDecoratorTestsForExistingKeyWithValueCached : ConfigurationSourceTestsForExistingKey 13 | { 14 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue expectedValue) 15 | { 16 | var innerSource = new Mock(); 17 | var cancellationToken = new CancellationToken(); 18 | innerSource.SetupSequence(x => x.GetAppSettingAsync(key, cancellationToken)) 19 | .ReturnsAsync(ConfigurationSourceResult.SuccessResult(expectedValue)) 20 | .Throws(new Exception("Should never get here")); 21 | 22 | var source = new CachingConfigurationSourceDecorator(innerSource.Object, new CacheKeyCreator(Guid.NewGuid().ToString()), MemoryCache.Default, () => new CacheItemPolicy()); 23 | source.GetAppSettingAsync(key, cancellationToken).Wait(); 24 | 25 | return source; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Caching.Tests/HumbleConfig.Caching.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {93E17785-3E7D-42C6-A44E-FAA26A2A5785} 8 | Library 9 | Properties 10 | HumbleConfig.Caching.Tests 11 | HumbleConfig.Caching.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll 35 | 36 | 37 | ..\packages\Moq.4.7.145\lib\net45\Moq.dll 38 | 39 | 40 | ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | {025FC6D3-B42E-4B46-AD36-FA002ED26EA6} 63 | HumbleConfig.Caching 64 | 65 | 66 | {27C04368-FC7A-4D87-8F60-A14FE965FB71} 67 | HumbleConfig.Tests 68 | 69 | 70 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 71 | HumbleConfig 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.Caching.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("HumbleConfig.Caching.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("93e17785-3e7d-42c6-a44e-faa26a2a5785")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching/CacheKeyCreator.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.Caching 2 | { 3 | public class CacheKeyCreator : ICacheKeyCreator 4 | { 5 | private readonly string _keyPrefix; 6 | 7 | public CacheKeyCreator(string keyPrefix) 8 | { 9 | _keyPrefix = keyPrefix; 10 | } 11 | 12 | public string CreateCacheKey(string key) 13 | { 14 | return $"{_keyPrefix}-{key}"; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Caching/CachingConfigurationSourceDecorator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Caching; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace HumbleConfig.Caching 7 | { 8 | public class CachingConfigurationSourceDecorator : IConfigurationSource 9 | { 10 | private readonly IConfigurationSource _innerSource; 11 | private readonly ICacheKeyCreator _cacheKeyCreator; 12 | private readonly ObjectCache _objectCache; 13 | private readonly Func _cacheItemPolicyFactory; 14 | 15 | public CachingConfigurationSourceDecorator(IConfigurationSource innerSource, ICacheKeyCreator cacheKeyCreator, ObjectCache objectCache, Func cacheItemPolicyFactoryFactory) 16 | { 17 | _innerSource = innerSource; 18 | _cacheKeyCreator = cacheKeyCreator; 19 | _objectCache = objectCache; 20 | _cacheItemPolicyFactory = cacheItemPolicyFactoryFactory; 21 | } 22 | 23 | public async Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 24 | { 25 | var appsetting = (ConfigurationSourceResult)_objectCache.Get(_cacheKeyCreator.CreateCacheKey(key)); 26 | 27 | if (appsetting == null) 28 | { 29 | appsetting = await _innerSource.GetAppSettingAsync(key, cancellationToken) 30 | .ConfigureAwait(false); 31 | 32 | var cacheItemPolicy = _cacheItemPolicyFactory(); 33 | _objectCache.Add(CreateCacheItem(key, appsetting), cacheItemPolicy); 34 | } 35 | 36 | return appsetting; 37 | } 38 | 39 | 40 | private CacheItem CreateCacheItem(string key, ConfigurationSourceResult value) 41 | { 42 | return new CacheItem(_cacheKeyCreator.CreateCacheKey(key), value); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching/CachingExtentions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.Caching; 3 | using System.Threading; 4 | 5 | namespace HumbleConfig.Caching 6 | { 7 | public static class CachingExtentions 8 | { 9 | public static IConfigurationSourceConfigurator WithCache(this IConfigurationSourceConfigurator configurationSourceConfigurator, ICacheKeyCreator cacheKeyCreator, ObjectCache objectCache, Func cacheItemPolicyFactory) 10 | { 11 | return configurationSourceConfigurator.WrapSource(x => new CachingConfigurationSourceDecorator(x, cacheKeyCreator, objectCache, cacheItemPolicyFactory)); 12 | } 13 | 14 | public static IConfigurationSourceConfigurator WithCache(this IConfigurationSourceConfigurator configurationSourceConfigurator, ObjectCache objectCache, Func cacheItemPolicyFactory) 15 | { 16 | var cacheKeyCreator = new CacheKeyCreator(Guid.NewGuid().ToString()); 17 | 18 | return WithCache(configurationSourceConfigurator, cacheKeyCreator, objectCache, cacheItemPolicyFactory); 19 | } 20 | 21 | public static IConfigurationSourceConfigurator WithDefaultMemoryCache(this IConfigurationSourceConfigurator configurationSourceConfigurator, Func cacheItemPolicyFactory) 22 | { 23 | return WithCache(configurationSourceConfigurator, MemoryCache.Default, cacheItemPolicyFactory); 24 | } 25 | 26 | public static IConfigurationSourceConfigurator WithDefaultMemoryCache(this IConfigurationSourceConfigurator configurationSourceConfigurator, TimeSpan expiresAfter) 27 | { 28 | return WithDefaultMemoryCache(configurationSourceConfigurator, () => new CacheItemPolicy() 29 | { 30 | AbsoluteExpiration = DateTimeOffset.UtcNow.Add(expiresAfter) 31 | }); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Caching/HumbleConfig.Caching.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {025FC6D3-B42E-4B46-AD36-FA002ED26EA6} 8 | Library 9 | Properties 10 | HumbleConfig.Caching 11 | HumbleConfig.Caching 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 53 | HumbleConfig 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching/HumbleConfig.Caching.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | false 10 | HumbleConfig is a simple abstraction on top of multiple config sources 11 | https://github.com/kevbite/HumbleConfig/ 12 | https://raw.githubusercontent.com/kevbite/HumbleConfig/master/HumbleConfig.png 13 | Caching for Humble Config 14 | Copyright HumbleConfig 2017 15 | Humble Config MongoDB Caching 16 | 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.Caching/ICacheKeyCreator.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.Caching 2 | { 3 | public interface ICacheKeyCreator 4 | { 5 | string CreateCacheKey(string key); 6 | } 7 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Caching/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.Caching")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.Caching")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("025fc6d3-b42e-4b46-ad36-fa002ed26ea6")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR.Tests/ConfigRSourceTests/ConfigRSourceTestsForExistingConfigRKey.cs: -------------------------------------------------------------------------------- 1 | using ConfigR; 2 | using HumbleConfig.Tests; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.ConfigR.Tests.ConfigRSourceTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 9 | public class ConfigRSourceTestsForExistingConfigRKey : ConfigurationSourceTestsForExistingKey 10 | { 11 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue value) 12 | { 13 | var config = Config.Global; 14 | config.Add(key, value); 15 | return new ConfigRSource(config); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR.Tests/ConfigRSourceTests/ConfigRSourceTestsForNoneExistingConfigRKey.cs: -------------------------------------------------------------------------------- 1 | using ConfigR; 2 | using HumbleConfig.Tests; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.ConfigR.Tests.ConfigRSourceTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 9 | public class ConfigRSourceTestsForNoneExistingConfigRKey : ConfigurationSourceTestsForNoneExistingKey 10 | { 11 | protected override IConfigurationSource CreateConfigurationSource() 12 | { 13 | return new ConfigRSource(Config.Global); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR.Tests/HumbleConfig.ConfigR.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {EBF29DE1-1998-4E51-AF84-4D76F969E7F5} 8 | Library 9 | Properties 10 | HumbleConfig.ConfigR.Tests 11 | HumbleConfig.ConfigR.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\Common.Logging.3.3.1\lib\net40\Common.Logging.dll 35 | True 36 | 37 | 38 | ..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll 39 | True 40 | 41 | 42 | ..\packages\ConfigR.0.14.1\lib\net45\ConfigR.dll 43 | True 44 | 45 | 46 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.dll 47 | True 48 | 49 | 50 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll 51 | True 52 | 53 | 54 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll 55 | True 56 | 57 | 58 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Desktop.dll 59 | True 60 | 61 | 62 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Scripting.dll 63 | True 64 | 65 | 66 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Scripting.CSharp.dll 67 | True 68 | 69 | 70 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Scripting.VisualBasic.dll 71 | True 72 | 73 | 74 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 75 | True 76 | 77 | 78 | ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll 79 | 80 | 81 | ..\packages\AutoFixture.3.49.0\lib\net40\Ploeh.AutoFixture.dll 82 | True 83 | 84 | 85 | ..\packages\Roslyn.Compilers.Common.1.2.20906.2\lib\net45\Roslyn.Compilers.dll 86 | True 87 | 88 | 89 | ..\packages\Roslyn.Compilers.CSharp.1.2.20906.2\lib\net45\Roslyn.Compilers.CSharp.dll 90 | True 91 | 92 | 93 | ..\packages\ScriptCs.Contracts.0.16.1\lib\net45\ScriptCs.Contracts.dll 94 | True 95 | 96 | 97 | ..\packages\ScriptCs.Core.0.16.1\lib\net45\ScriptCs.Core.dll 98 | True 99 | 100 | 101 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\ScriptCs.Engine.Roslyn.dll 102 | True 103 | 104 | 105 | 106 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\System.Collections.Immutable.dll 107 | True 108 | 109 | 110 | 111 | 112 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\System.Reflection.Metadata.dll 113 | True 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | {D0E7A0E1-B3B7-4B09-8AE7-C971A87638E4} 130 | HumbleConfig.ConfigR 131 | 132 | 133 | {27C04368-FC7A-4D87-8F60-A14FE965FB71} 134 | HumbleConfig.Tests 135 | 136 | 137 | {b04cb40d-08d8-44c6-b66e-f1ed0e97e507} 138 | HumbleConfig 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 153 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.ConfigR.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.ConfigR.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ebf29de1-1998-4e51-af84-4d76f969e7f5")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR.Tests/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR/ConfigRExtensions.cs: -------------------------------------------------------------------------------- 1 | using ConfigR; 2 | 3 | namespace HumbleConfig.ConfigR 4 | { 5 | public static class ConfigRExtensions 6 | { 7 | public static IConfigurationSourceConfigurator AddConfigR(this IConfigurationConfigurator configuration) 8 | { 9 | return configuration.AddConfigR(Config.Global); 10 | } 11 | 12 | public static IConfigurationSourceConfigurator AddConfigR(this IConfigurationConfigurator configuration, IConfig config) 13 | { 14 | return configuration.AddConfigurationSource(new ConfigRSource(config)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR/ConfigRSource.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using ConfigR; 4 | 5 | namespace HumbleConfig.ConfigR 6 | { 7 | public class ConfigRSource : IConfigurationSource 8 | { 9 | private readonly IConfig _config; 10 | 11 | public ConfigRSource(IConfig config) 12 | { 13 | _config = config; 14 | } 15 | 16 | public Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 17 | { 18 | object temp; 19 | var result = _config.TryGetValue(key, out temp); 20 | 21 | var sourceResult = result ? ConfigurationSourceResult.SuccessResult((TValue)temp) 22 | : ConfigurationSourceResult.FailedResult(); 23 | 24 | return Task.FromResult(sourceResult); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR/HumbleConfig.ConfigR.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D0E7A0E1-B3B7-4B09-8AE7-C971A87638E4} 8 | Library 9 | Properties 10 | HumbleConfig.ConfigR 11 | HumbleConfig.ConfigR 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\Common.Logging.3.3.1\lib\net40\Common.Logging.dll 35 | True 36 | 37 | 38 | ..\packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll 39 | True 40 | 41 | 42 | ..\packages\ConfigR.0.14.1\lib\net45\ConfigR.dll 43 | True 44 | 45 | 46 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.dll 47 | True 48 | 49 | 50 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.CSharp.dll 51 | True 52 | 53 | 54 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.CSharp.Desktop.dll 55 | True 56 | 57 | 58 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Desktop.dll 59 | True 60 | 61 | 62 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Scripting.dll 63 | True 64 | 65 | 66 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Scripting.CSharp.dll 67 | True 68 | 69 | 70 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\Microsoft.CodeAnalysis.Scripting.VisualBasic.dll 71 | True 72 | 73 | 74 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 75 | True 76 | 77 | 78 | ..\packages\Roslyn.Compilers.Common.1.2.20906.2\lib\net45\Roslyn.Compilers.dll 79 | True 80 | 81 | 82 | ..\packages\Roslyn.Compilers.CSharp.1.2.20906.2\lib\net45\Roslyn.Compilers.CSharp.dll 83 | True 84 | 85 | 86 | ..\packages\ScriptCs.Contracts.0.16.1\lib\net45\ScriptCs.Contracts.dll 87 | True 88 | 89 | 90 | ..\packages\ScriptCs.Core.0.16.1\lib\net45\ScriptCs.Core.dll 91 | True 92 | 93 | 94 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\ScriptCs.Engine.Roslyn.dll 95 | True 96 | 97 | 98 | 99 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\System.Collections.Immutable.dll 100 | True 101 | 102 | 103 | 104 | 105 | ..\packages\ScriptCs.Engine.Roslyn.0.16.1\lib\net45\System.Reflection.Metadata.dll 106 | True 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 128 | HumbleConfig 129 | 130 | 131 | 132 | 139 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR/HumbleConfig.ConfigR.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | false 10 | HumbleConfig is a simple abstraction on top of multiple config sources. This package includes the config source of ConfigR 11 | https://github.com/kevbite/HumbleConfig/ 12 | https://raw.githubusercontent.com/kevbite/HumbleConfig/master/HumbleConfig.png 13 | ConfigR Source for Humble Config 14 | Copyright HumbleConfig 2015 15 | Humble Config ConfigR 16 | 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.ConfigR")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.ConfigR")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d0e7a0e1-b3b7-4b09-8ae7-c971a87638e4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigR/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager.Tests/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager.Tests/ConfigurationManagerSourceTests/ConfigurationManagerSourceTestsForExistingAppSettingKey.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | using HumbleConfig.Tests; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.ConfigurationManager.Tests.ConfigurationManagerSourceTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 9 | public class ConfigurationManagerSourceTestsForExistingAppSettingKey : ConfigurationSourceTestsForExistingKey 10 | { 11 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue value) 12 | { 13 | var config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 14 | var appSettingsSection = (AppSettingsSection)config.GetSection("appSettings"); 15 | appSettingsSection.Settings.Clear(); 16 | appSettingsSection.Settings.Add(key, value.ToString()); 17 | config.Save(); 18 | System.Configuration.ConfigurationManager.RefreshSection("appSettings"); 19 | 20 | return new ConfigurationManagerSource(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager.Tests/ConfigurationManagerSourceTests/ConfigurationManagerSourceTestsForNoneExistingAppSettingKey.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.Tests; 2 | using NUnit.Framework; 3 | 4 | namespace HumbleConfig.ConfigurationManager.Tests.ConfigurationManagerSourceTests 5 | { 6 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 7 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 8 | public class ConfigurationManagerSourceTestsForNoneExistingAppSettingKey : ConfigurationSourceTestsForNoneExistingKey 9 | { 10 | protected override IConfigurationSource CreateConfigurationSource() 11 | { 12 | return new ConfigurationManagerSource(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager.Tests/HumbleConfig.ConfigurationManager.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7D9C2A7B-75F2-483C-8DA7-9C6D5250BC8B} 8 | Library 9 | Properties 10 | HumbleConfig.ConfigurationManager.Tests 11 | HumbleConfig.ConfigurationManager.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | {A1CA7848-F8B5-41AE-9AE8-19D1030B926B} 59 | HumbleConfig.ConfigurationManager 60 | 61 | 62 | {27C04368-FC7A-4D87-8F60-A14FE965FB71} 63 | HumbleConfig.Tests 64 | 65 | 66 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 67 | HumbleConfig 68 | 69 | 70 | 71 | 78 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.ConfigurationManager.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.ConfigurationManager.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7d9c2a7b-75f2-483c-8da7-9c6d5250bc8b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager/ConfigurationManagerExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.ConfigurationManager 2 | { 3 | public static class ConfigurationManagerExtensions 4 | { 5 | public static IConfigurationSourceConfigurator AddConfigurationManager(this IConfigurationConfigurator configuration) 6 | { 7 | return configuration.AddConfigurationSource(new ConfigurationManagerSource()); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager/ConfigurationManagerSource.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Linq; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace HumbleConfig.ConfigurationManager 8 | { 9 | public class ConfigurationManagerSource : IConfigurationSource 10 | { 11 | public Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 12 | { 13 | var configValue = System.Configuration.ConfigurationManager.AppSettings[key]; 14 | 15 | if (configValue == null) 16 | { 17 | return Task.FromResult(ConfigurationSourceResult.FailedResult()); 18 | } 19 | else 20 | { 21 | var valueType = typeof(TValue); 22 | valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; 23 | 24 | var value = (TValue)Convert.ChangeType(configValue, valueType); 25 | return Task.FromResult(ConfigurationSourceResult.SuccessResult(value)); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager/HumbleConfig.ConfigurationManager.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {A1CA7848-F8B5-41AE-9AE8-19D1030B926B} 8 | Library 9 | Properties 10 | HumbleConfig.ConfigurationManager 11 | HumbleConfig.ConfigurationManager 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | false 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 56 | HumbleConfig 57 | 58 | 59 | 60 | 67 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager/HumbleConfig.ConfigurationManager.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | false 10 | HumbleConfig is a simple abstraction on top of multiple config sources 11 | https://github.com/kevbite/HumbleConfig/ 12 | https://raw.githubusercontent.com/kevbite/HumbleConfig/master/HumbleConfig.png 13 | Configuration Manager Source for Humble Config 14 | Copyright HumbleConfig 2015 15 | Humble Config Configuration Manager 16 | 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.ConfigurationManager")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.ConfigurationManager")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a1ca7848-f8b5-41ae-9ae8-19d1030b926b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.ConfigurationManager/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash.Tests/CredstashSourceTests/CredstashSourceTestsForExistingKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Threading.Tasks; 5 | using Amazon; 6 | using Amazon.DynamoDBv2; 7 | using Amazon.DynamoDBv2.Model; 8 | using Amazon.KeyManagementService; 9 | using HumbleConfig.Tests; 10 | using Moq; 11 | using Narochno.Credstash; 12 | using Narochno.Primitives; 13 | using NUnit.Framework; 14 | 15 | namespace HumbleConfig.Credstash.Tests.CredstashSourceTests 16 | { 17 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 18 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 19 | public class CredstashSourceTestsForExistingKey : ConfigurationSourceTestsForExistingKey 20 | { 21 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue value) 22 | { 23 | var mock = new Mock(); 24 | mock.Setup(x => x.GetSecretAsync(key, null, null, true)) 25 | .ReturnsAsync(new Optional(value.ToString())); 26 | 27 | return new CredstashSource(mock.Object); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash.Tests/CredstashSourceTests/CredstashSourceTestsForNoneExistingKey.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.Tests; 2 | using Moq; 3 | using Narochno.Credstash; 4 | using Narochno.Primitives; 5 | using NUnit.Framework; 6 | 7 | namespace HumbleConfig.Credstash.Tests.CredstashSourceTests 8 | { 9 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 10 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 11 | public class CredstashSourceTestsForNoneExistingKey : ConfigurationSourceTestsForNoneExistingKey 12 | { 13 | protected override IConfigurationSource CreateConfigurationSource() 14 | { 15 | var credstash = new Mock(); 16 | credstash.Setup(x => x.GetSecretAsync(It.IsAny(), null, null, true)) 17 | .ReturnsAsync(new Optional(null)); 18 | 19 | return new CredstashSource(credstash.Object); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash.Tests/HumbleConfig.Credstash.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {904F63FC-EF8E-4451-B5AC-9DCD0803B915} 8 | Library 9 | Properties 10 | HumbleConfig.Credstash.Tests 11 | HumbleConfig.Credstash.Tests 12 | v4.6.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\AWSSDK.Core.3.3.17.9\lib\net45\AWSSDK.Core.dll 35 | 36 | 37 | ..\packages\AWSSDK.DynamoDBv2.3.3.4.17\lib\net45\AWSSDK.DynamoDBv2.dll 38 | 39 | 40 | ..\packages\AWSSDK.KeyManagementService.3.3.3.1\lib\net45\AWSSDK.KeyManagementService.dll 41 | 42 | 43 | ..\packages\Portable.BouncyCastle.1.8.1.3\lib\net40\BouncyCastle.Crypto.dll 44 | 45 | 46 | ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll 47 | 48 | 49 | ..\packages\Moq.4.7.145\lib\net45\Moq.dll 50 | 51 | 52 | ..\packages\Narochno.Credstash.2.1.1\lib\netstandard2.0\Narochno.Credstash.dll 53 | 54 | 55 | ..\packages\Narochno.Primitives.2.6.6\lib\net45\Narochno.Primitives.dll 56 | 57 | 58 | ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | {71683C23-7D6E-45F8-A2B4-D2078C2DA011} 78 | HumbleConfig.Credstash 79 | 80 | 81 | {27C04368-FC7A-4D87-8F60-A14FE965FB71} 82 | HumbleConfig.Tests 83 | 84 | 85 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 86 | HumbleConfig 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.Credstash.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("HumbleConfig.Credstash.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("904f63fc-ef8e-4451-b5ac-9dcd0803b915")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash/CredstashExtensions.cs: -------------------------------------------------------------------------------- 1 | using Amazon.DynamoDBv2; 2 | using Amazon.Internal; 3 | using Amazon.KeyManagementService; 4 | using Narochno.Credstash; 5 | 6 | namespace HumbleConfig.Credstash 7 | { 8 | public static class CredstashExtensions 9 | { 10 | public static IConfigurationSourceConfigurator AddCredstash(this IConfigurationConfigurator configuration, CredstashOptions options, IAmazonKeyManagementService amazonKeyManagementService, IAmazonDynamoDB amazonDynamoDb) 11 | { 12 | var credstash = new Narochno.Credstash.Credstash(options, amazonKeyManagementService, amazonDynamoDb); 13 | 14 | return configuration.AddConfigurationSource(new CredstashSource(credstash)); 15 | 16 | 17 | } 18 | 19 | public static IConfigurationSourceConfigurator AddCredstash(this IConfigurationConfigurator configuration, Amazon.RegionEndpoint region, string table) 20 | { 21 | var credstashOptions = new CredstashOptions() 22 | { 23 | Region = region, 24 | Table = table 25 | }; 26 | 27 | var amazonKeyManagementServiceClient = new AmazonKeyManagementServiceClient(region); 28 | var amazonDynamoDbClient = new AmazonDynamoDBClient(region); 29 | 30 | return AddCredstash(configuration, credstashOptions, amazonKeyManagementServiceClient, amazonDynamoDbClient); 31 | } 32 | 33 | public static IConfigurationSourceConfigurator AddCredstash(this IConfigurationConfigurator configuration, Amazon.RegionEndpoint region) 34 | { 35 | var credstashOptions = new CredstashOptions() 36 | { 37 | Region = region 38 | }; 39 | 40 | var amazonKeyManagementServiceClient = new AmazonKeyManagementServiceClient(region); 41 | var amazonDynamoDbClient = new AmazonDynamoDBClient(region); 42 | 43 | return AddCredstash(configuration, credstashOptions, amazonKeyManagementServiceClient, amazonDynamoDbClient); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash/CredstashSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Narochno.Credstash; 5 | 6 | namespace HumbleConfig.Credstash 7 | { 8 | public class CredstashSource : IConfigurationSource 9 | { 10 | private readonly ICredstash _credstash; 11 | 12 | public CredstashSource(ICredstash credstash) 13 | { 14 | _credstash = credstash; 15 | } 16 | 17 | public async Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 18 | { 19 | var credstashValue = await _credstash.GetSecretAsync(key) 20 | .ConfigureAwait(false); 21 | 22 | if (credstashValue.HasNoValue) 23 | { 24 | return ConfigurationSourceResult.FailedResult(); 25 | } 26 | else 27 | { 28 | var valueType = typeof(TValue); 29 | valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; 30 | 31 | var value = (TValue)Convert.ChangeType(credstashValue.Value, valueType); 32 | 33 | return ConfigurationSourceResult.SuccessResult(value); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash/HumbleConfig.Credstash.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {71683C23-7D6E-45F8-A2B4-D2078C2DA011} 8 | Library 9 | Properties 10 | HumbleConfig.Credstash 11 | HumbleConfig.Credstash 12 | v4.6.2 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\AWSSDK.Core.3.3.17.9\lib\net45\AWSSDK.Core.dll 36 | 37 | 38 | ..\packages\AWSSDK.DynamoDBv2.3.3.4.17\lib\net45\AWSSDK.DynamoDBv2.dll 39 | 40 | 41 | ..\packages\AWSSDK.KeyManagementService.3.3.3.1\lib\net45\AWSSDK.KeyManagementService.dll 42 | 43 | 44 | ..\packages\Portable.BouncyCastle.1.8.1.3\lib\net40\BouncyCastle.Crypto.dll 45 | 46 | 47 | ..\packages\Narochno.Credstash.2.1.1\lib\netstandard2.0\Narochno.Credstash.dll 48 | 49 | 50 | ..\packages\Narochno.Primitives.2.6.6\lib\net45\Narochno.Primitives.dll 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 77 | HumbleConfig 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash/HumbleConfig.Credstash.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | false 10 | HumbleConfig is a simple abstraction on top of multiple config sources 11 | https://github.com/kevbite/HumbleConfig/ 12 | https://raw.githubusercontent.com/kevbite/HumbleConfig/master/HumbleConfig.png 13 | Credstash Source for Humble Config 14 | Copyright HumbleConfig 2015 15 | Humble Config Credstash KMS AWS 16 | 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.Credstash")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.MongoDb")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("71683c23-7d6e-45f8-a2b4-d2078c2da011")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] -------------------------------------------------------------------------------- /src/HumbleConfig.Credstash/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables.Tests/EnvironmentVariablesSourceTests/EnvironmentVariablesSourceTestsForExistingEnvironmentVariable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http.Headers; 3 | using HumbleConfig.Tests; 4 | using NUnit.Framework; 5 | using Ploeh.AutoFixture; 6 | 7 | namespace HumbleConfig.EnvironmentVariables.Tests.EnvironmentVariablesSourceTests 8 | { 9 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 10 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 11 | public class EnvironmentVariablesSourceTestsForExistingEnvironmentVariable : ConfigurationSourceTestsForExistingKey 12 | { 13 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue value) 14 | { 15 | Environment.SetEnvironmentVariable(key, value.ToString()); 16 | 17 | return new EnvironmentVariablesSource(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables.Tests/EnvironmentVariablesSourceTests/EnvironmentVariablesSourceTestsForNoneExistingEnvironmentVariable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using HumbleConfig.Tests; 3 | using HumbleConfig.Tests.Stubs; 4 | using NUnit.Framework; 5 | using Ploeh.AutoFixture; 6 | 7 | namespace HumbleConfig.EnvironmentVariables.Tests.EnvironmentVariablesSourceTests 8 | { 9 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 10 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 11 | public class EnvironmentVariablesSourceTestsForNoneExistingEnvironmentVariable : ConfigurationSourceTestsForNoneExistingKey 12 | { 13 | protected override IConfigurationSource CreateConfigurationSource() 14 | { 15 | return new EnvironmentVariablesSource(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables.Tests/HumbleConfig.EnvironmentVariables.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7660560D-727C-4ABE-B741-94D2265417FB} 8 | Library 9 | Properties 10 | HumbleConfig.EnvironmentVariables.Tests 11 | HumbleConfig.EnvironmentVariables.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll 36 | 37 | 38 | ..\packages\AutoFixture.3.49.0\lib\net40\Ploeh.AutoFixture.dll 39 | True 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | {8C21C807-5FBB-46A6-AFE3-15028D257BAB} 58 | HumbleConfig.EnvironmentVariables 59 | 60 | 61 | {27C04368-FC7A-4D87-8F60-A14FE965FB71} 62 | HumbleConfig.Tests 63 | 64 | 65 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 66 | HumbleConfig 67 | 68 | 69 | 70 | 71 | 72 | 73 | 80 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.EnvironmentVariables.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.EnvironmentVariables.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7660560d-727c-4abe-b741-94d2265417fb")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables/EnvironmentVariablesExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.EnvironmentVariables 2 | { 3 | public static class EnvironmentVariablesExtensions 4 | { 5 | public static IConfigurationSourceConfigurator AddEnvironmentVariables(this IConfigurationConfigurator configuration) 6 | { 7 | return configuration.AddConfigurationSource(new EnvironmentVariablesSource()); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables/EnvironmentVariablesSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace HumbleConfig.EnvironmentVariables 6 | { 7 | public class EnvironmentVariablesSource : IConfigurationSource 8 | { 9 | public Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 10 | { 11 | var environmentValue = Environment.GetEnvironmentVariable(key); 12 | 13 | if (environmentValue == null) 14 | { 15 | return Task.FromResult(ConfigurationSourceResult.FailedResult()); 16 | } 17 | else 18 | { 19 | var valueType = typeof (TValue); 20 | valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; 21 | 22 | var value = (TValue) Convert.ChangeType(environmentValue, valueType); 23 | 24 | return Task.FromResult(ConfigurationSourceResult.SuccessResult(value)); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables/HumbleConfig.EnvironmentVariables.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8C21C807-5FBB-46A6-AFE3-15028D257BAB} 8 | Library 9 | Properties 10 | HumbleConfig.EnvironmentVariables 11 | HumbleConfig.EnvironmentVariables 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | false 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 51 | HumbleConfig 52 | 53 | 54 | 55 | 56 | 57 | 58 | 65 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables/HumbleConfig.EnvironmentVariables.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | false 10 | HumbleConfig is a simple abstraction on top of multiple config sources 11 | https://github.com/kevbite/HumbleConfig/ 12 | https://raw.githubusercontent.com/kevbite/HumbleConfig/master/HumbleConfig.png 13 | Environment Variables Source for Humble Config 14 | Copyright HumbleConfig 2015 15 | Humble Config Environment Variables 16 | 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.EnvironmentVariables/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.EnvironmentVariables")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.EnvironmentVariables")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("8c21c807-5fbb-46a6-afe3-15028d257bab")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/CacheConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using HumbleConfig.Caching; 5 | using HumbleConfig.InMemory; 6 | using NUnit.Framework; 7 | using Ploeh.AutoFixture; 8 | 9 | namespace HumbleConfig.FunctionalTests 10 | { 11 | [TestFixture] 12 | public class CacheConfigurationTests 13 | { 14 | private IConfiguration _configuration; 15 | 16 | private string key1; 17 | private Dictionary _inMemory; 18 | private Fixture _fixture; 19 | 20 | [OneTimeSetUp] 21 | public void GivenConfigurationWithEnvironmentVaribleAndConfigurationManager() 22 | { 23 | _fixture = new Fixture(); 24 | key1 = _fixture.Create("key1"); 25 | _inMemory = new Dictionary() 26 | { 27 | { key1, "InMemory1"}, 28 | }; 29 | 30 | _configuration = new Configuration() 31 | .AddInMemory(_inMemory).WithDefaultMemoryCache(TimeSpan.FromSeconds(1)) 32 | .GetConfiguration(); 33 | } 34 | 35 | [Test] 36 | public async Task WhenChangingValueStillReturnsTheSameValue() 37 | { 38 | var value1 = await _configuration.GetAppSettingAsync(key1); 39 | 40 | _inMemory[key1] = _fixture.Create("key1"); 41 | 42 | var value2 = await _configuration.GetAppSettingAsync(key1); 43 | 44 | Assert.AreEqual(value1, value2); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/ConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using ConfigR; 5 | using HumbleConfig.ConfigR; 6 | using HumbleConfig.ConfigurationManager; 7 | using HumbleConfig.EnvironmentVariables; 8 | using HumbleConfig.InMemory; 9 | using HumbleConfig.MongoDb; 10 | using MongoDB.Bson; 11 | using MongoDB.Driver; 12 | using NUnit.Framework; 13 | 14 | namespace HumbleConfig.FunctionalTests 15 | { 16 | [TestFixture] 17 | public class ConfigurationTests 18 | { 19 | private IConfiguration _configuration; 20 | 21 | private string key1 = "key1"; 22 | private string key2 = "key2"; 23 | private string key3 = "key3"; 24 | private string key4 = "key4"; 25 | private string key5 = "key5"; 26 | private string key6 = "key6"; 27 | private string key7 = "key7"; 28 | 29 | private string _key1Actual; 30 | private string _key2Actual; 31 | private string _key3Actual; 32 | private string _key4Actual; 33 | private string _key5Actual; 34 | private string _key6Actual; 35 | private string _key7Actual; 36 | 37 | private readonly IMongoCollection _mongoCollection = new MongoClient().GetDatabase(Guid.NewGuid().ToString()) 38 | .GetCollection("appSettings"); 39 | 40 | [OneTimeSetUp] 41 | public void GivenConfigurationWithEnvironmentVaribleAndConfigurationManager() 42 | { 43 | Environment.SetEnvironmentVariable(key1, "EnvironmentVariable"); 44 | Environment.SetEnvironmentVariable(key2, "EnvironmentVariable"); 45 | 46 | _mongoCollection 47 | .InsertOneAsync(new AppSetting() {Id = key7, Value = "MongoDB"}) 48 | .Wait(); 49 | 50 | _configuration = new Configuration() 51 | .AddEnvironmentVariables() 52 | .AddConfigurationManager() 53 | .AddInMemory(new Dictionary() { {key5, "InMemory"} }) 54 | .AddConfigR(Config.Global.LoadScriptFile(new Uri(Assembly.GetExecutingAssembly().CodeBase + ".csx").LocalPath)) 55 | .AddMongoDb($"mongodb://localhost/{_mongoCollection.Database.DatabaseNamespace}", "appSettings") 56 | .GetConfiguration(); 57 | } 58 | 59 | [SetUp] 60 | public void WhenGettingAppSettings() 61 | { 62 | _key1Actual = _configuration.GetAppSettingAsync(key1).Result; 63 | _key2Actual = _configuration.GetAppSettingAsync(key2).Result; 64 | _key3Actual = _configuration.GetAppSettingAsync(key3).Result; 65 | _key4Actual = _configuration.GetAppSettingAsync(key4).Result; 66 | _key5Actual = _configuration.GetAppSettingAsync(key5).Result; 67 | _key6Actual = _configuration.GetAppSettingAsync(key6).Result; 68 | _key7Actual = _configuration.GetAppSettingAsync(key7).Result; 69 | } 70 | 71 | [Test] 72 | public void ThenKey1PullsValueFromEnvironmentVariable() 73 | { 74 | Assert.That(_key1Actual, Is.EqualTo("EnvironmentVariable")); 75 | } 76 | 77 | [Test] 78 | public void ThenKey2PullsValueFromEnvironmentVariable() 79 | { 80 | Assert.That(_key2Actual, Is.EqualTo("EnvironmentVariable")); 81 | } 82 | 83 | [Test] 84 | public void ThenKey3PullsValueFromAppConfig() 85 | { 86 | Assert.That(_key3Actual, Is.EqualTo("App.Config")); 87 | } 88 | 89 | [Test] 90 | public void ThenKey4IsNull() 91 | { 92 | Assert.That(_key4Actual, Is.Null); 93 | } 94 | 95 | [Test] 96 | public void ThenKey5PullsFromInMemory() 97 | { 98 | Assert.That(_key5Actual, Is.EqualTo("InMemory")); 99 | } 100 | 101 | [Test] 102 | public void ThenKey6PullsFromConfigR() 103 | { 104 | Assert.That(_key6Actual, Is.EqualTo("ConfigR")); 105 | } 106 | 107 | [Test] 108 | public void ThenKey7PullsFromMongoDb() 109 | { 110 | Assert.That(_key7Actual, Is.EqualTo("MongoDB")); 111 | } 112 | 113 | [OneTimeTearDown] 114 | public void DestroyEvidence() 115 | { 116 | _mongoCollection.DeleteOneAsync(new BsonDocument("_id", key7)).Wait(); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/ConfigurationTestsWithKeyPostfixer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using HumbleConfig.InMemory; 4 | using HumbleConfig.KeyFormatters; 5 | using NUnit.Framework; 6 | 7 | namespace HumbleConfig.FunctionalTests 8 | { 9 | [TestFixture] 10 | public class ConfigurationTestsWithKeyPostfixer 11 | { 12 | private IConfiguration _configuration; 13 | 14 | private string _key1Actual; 15 | 16 | [OneTimeSetUp] 17 | public void GivenConfigurationWithKeyPostfixer() 18 | { 19 | _configuration = new Configuration() 20 | .WithKeyPostfixer(".production") 21 | .AddInMemory(new Dictionary() { { "Key1.production", "InMemory" } }) 22 | .GetConfiguration(); 23 | } 24 | 25 | [SetUp] 26 | public async Task WhenGettingAppSettings() 27 | { 28 | _key1Actual = await _configuration.GetAppSettingAsync("Key1"); 29 | } 30 | 31 | [Test] 32 | public void ThenKey1PullsValueFromEnvironmentVariable() 33 | { 34 | Assert.That(_key1Actual, Is.EqualTo("InMemory")); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/ConfigurationTestsWithKeyPrefixer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using HumbleConfig.InMemory; 4 | using HumbleConfig.KeyFormatters; 5 | using NUnit.Framework; 6 | 7 | namespace HumbleConfig.FunctionalTests 8 | { 9 | [TestFixture] 10 | public class ConfigurationTestsWithKeyPrefixer 11 | { 12 | private IConfiguration _configuration; 13 | 14 | private string _key1Actual; 15 | 16 | [OneTimeSetUp] 17 | public void GivenConfigurationWithKeyPrefixer() 18 | { 19 | _configuration = new Configuration() 20 | .WithKeyPrefixer("HumbleConfig:") 21 | .AddInMemory(new Dictionary() { { "HumbleConfig:Key1", "InMemory"} }) 22 | .GetConfiguration(); 23 | } 24 | 25 | [SetUp] 26 | public async Task WhenGettingAppSettings() 27 | { 28 | _key1Actual = await _configuration.GetAppSettingAsync("Key1"); 29 | } 30 | 31 | [Test] 32 | public void ThenKey1PullsValueFromEnvironmentVariable() 33 | { 34 | Assert.That(_key1Actual, Is.EqualTo("InMemory")); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/CredstashConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Threading.Tasks; 5 | using Amazon; 6 | using ConfigR; 7 | using HumbleConfig.ConfigR; 8 | using HumbleConfig.ConfigurationManager; 9 | using HumbleConfig.Credstash; 10 | using HumbleConfig.EnvironmentVariables; 11 | using HumbleConfig.InMemory; 12 | using HumbleConfig.MongoDb; 13 | using NUnit.Framework; 14 | 15 | namespace HumbleConfig.FunctionalTests 16 | { 17 | 18 | [TestFixture] 19 | [Category("Credstash")] 20 | public class CredstashConfigurationTests 21 | { 22 | private IConfiguration _configuration; 23 | 24 | private string key1 = "key1"; 25 | private string key2 = "key2"; 26 | 27 | private string _key1Actual; 28 | private string _key2Actual; 29 | 30 | [OneTimeSetUp] 31 | public void GivenConfigurationWithEnvironmentVaribleAndConfigurationManager() 32 | { 33 | // This test requires the following commands to be run: 34 | // $ credstash --table credstash-test-2E24F0AC-DD37-4DE1-939E-E2D1ADF66149 setup 35 | // $ credstash --table credstash-test-2E24F0AC-DD37-4DE1-939E-E2D1ADF66149 put key1 Credstash 36 | _configuration = new Configuration() 37 | .AddCredstash(RegionEndpoint.EUWest1, "credstash-test-2E24F0AC-DD37-4DE1-939E-E2D1ADF66149") 38 | .AddInMemory(new Dictionary() {{key2, "InMemory"}}) 39 | .GetConfiguration(); 40 | } 41 | 42 | [SetUp] 43 | public async Task WhenGettingAppSettings() 44 | { 45 | _key1Actual = await _configuration.GetAppSettingAsync(key1); 46 | _key2Actual = await _configuration.GetAppSettingAsync(key2); 47 | } 48 | 49 | 50 | [Test] 51 | public void ThenKey5PullsFromCredstash() 52 | { 53 | Assert.That(_key1Actual, Is.EqualTo("Credstash")); 54 | } 55 | 56 | [Test] 57 | public void ThenKey5PullsFromInMemory() 58 | { 59 | Assert.That(_key2Actual, Is.EqualTo("InMemory")); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/ExpiredCacheConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Caching; 3 | using System.Threading.Tasks; 4 | using HumbleConfig.Caching; 5 | using HumbleConfig.InMemory; 6 | using NUnit.Framework; 7 | using Ploeh.AutoFixture; 8 | 9 | namespace HumbleConfig.FunctionalTests 10 | { 11 | [TestFixture] 12 | public class ExpiredCacheConfigurationTests 13 | { 14 | private IConfiguration _configuration; 15 | 16 | private string _key1; 17 | private string _key2; 18 | private Dictionary _inMemory; 19 | private Fixture _fixture; 20 | private readonly List _changeMonitors = new List(); 21 | 22 | [OneTimeSetUp] 23 | public void GivenConfigurationWithEnvironmentVaribleAndConfigurationManager() 24 | { 25 | _fixture = new Fixture(); 26 | _key1 = _fixture.Create("key1"); 27 | _key2 = _fixture.Create("key2"); 28 | _inMemory = new Dictionary() 29 | { 30 | { _key1, "InMemory1"}, 31 | { _key2, "InMemory2"}, 32 | }; 33 | 34 | CacheItemPolicy CreateCacheItemPolicy() 35 | { 36 | var changeMonitor = new TestChangeMonitor(); 37 | _changeMonitors.Add(changeMonitor); 38 | var cacheItemPolicy = new CacheItemPolicy(); 39 | cacheItemPolicy.ChangeMonitors.Add(changeMonitor); 40 | 41 | return cacheItemPolicy; 42 | } 43 | 44 | _configuration = new Configuration() 45 | .AddInMemory(_inMemory) 46 | .WithDefaultMemoryCache(CreateCacheItemPolicy) 47 | .GetConfiguration(); 48 | } 49 | 50 | [Test] 51 | public async Task WhenChangingValueStillReturnsTheSameValue() 52 | { 53 | var key1Value1 = await _configuration.GetAppSettingAsync(_key1); 54 | var key2Value1 = await _configuration.GetAppSettingAsync(_key2); 55 | Assert.AreEqual("InMemory1", key1Value1); 56 | Assert.AreEqual("InMemory2", key2Value1); 57 | 58 | var key1Expected = _fixture.Create("key1"); 59 | _inMemory[_key1] = key1Expected; 60 | var key2Expected = _fixture.Create("key2"); 61 | _inMemory[_key2] = key2Expected; 62 | 63 | _changeMonitors.ForEach(monitor => monitor.TriggerChange()); 64 | 65 | var key1Value2 = await _configuration.GetAppSettingAsync(_key1); 66 | var key2Value2 = await _configuration.GetAppSettingAsync(_key2); 67 | 68 | Assert.AreEqual(key1Expected, key1Value2); 69 | Assert.AreEqual(key2Expected, key2Value2); 70 | } 71 | 72 | public class TestChangeMonitor : ChangeMonitor 73 | { 74 | public TestChangeMonitor() 75 | { 76 | InitializationComplete(); 77 | } 78 | protected override void Dispose(bool disposing) { } 79 | 80 | public override string UniqueId { get; } 81 | 82 | public void TriggerChange() 83 | { 84 | OnChanged(null); 85 | } 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/HumbleConfig.FunctionalTests.dll.csx: -------------------------------------------------------------------------------- 1 | Add("key6", "ConfigR") -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/KeyFormatterConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using HumbleConfig.Caching; 5 | using HumbleConfig.InMemory; 6 | using HumbleConfig.KeyFormatters; 7 | using HumbleConfig.MongoDb; 8 | using MongoDB.Driver; 9 | using Moq; 10 | using NUnit.Framework; 11 | 12 | namespace HumbleConfig.FunctionalTests 13 | { 14 | [TestFixture] 15 | class KeyFormatterConfigurationTests 16 | { 17 | private IConfiguration _configuration; 18 | 19 | private string key1 = "key1"; 20 | private string key2 = "key2"; 21 | private string key3 = "key3"; 22 | 23 | private string _key1Actual; 24 | private string _key2Actual; 25 | private string _key3Actual; 26 | 27 | [OneTimeSetUp] 28 | public void GivenConfigurationWithEnvironmentVaribleAndConfigurationManager() 29 | { 30 | var newKey3 = "key3.new"; 31 | var keyFormatter = new Mock(); 32 | keyFormatter.Setup(x => x.FormatKey(key3)) 33 | .Returns(newKey3); 34 | 35 | _configuration = new Configuration() 36 | .AddInMemory(new Dictionary(){{"pre." + key1, "InMemory1"}}).WithKeyPrefixer("pre.") 37 | .AddInMemory(new Dictionary(){{key2 + ".post", "InMemory2"}}).WithKeyPostfixer(".post") 38 | .AddInMemory(new Dictionary(){{newKey3, "InMemory3"}}).WithKeyFormatter(keyFormatter.Object) 39 | .GetConfiguration(); 40 | } 41 | 42 | [SetUp] 43 | public async Task WhenGettingAppSettings() 44 | { 45 | _key1Actual = await _configuration.GetAppSettingAsync(key1); 46 | _key2Actual = await _configuration.GetAppSettingAsync(key2); 47 | _key3Actual = await _configuration.GetAppSettingAsync(key3); 48 | } 49 | 50 | [Test] 51 | public void ThenTheCorrectValueIsPullWithPrefix() 52 | { 53 | Assert.That(_key1Actual, Is.EqualTo("InMemory1")); 54 | } 55 | 56 | [Test] 57 | public void ThenTheCorrectValueIsPullWithPostfix() 58 | { 59 | Assert.That(_key2Actual, Is.EqualTo("InMemory2")); 60 | } 61 | 62 | [Test] 63 | public void ThenTheCorrectValueIsPullWithCustomFormatter() 64 | { 65 | Assert.That(_key3Actual, Is.EqualTo("InMemory3")); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/MultiCacheConfigurationTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.Caching; 3 | using System.Threading.Tasks; 4 | using HumbleConfig.Caching; 5 | using HumbleConfig.InMemory; 6 | using NUnit.Framework; 7 | using Ploeh.AutoFixture; 8 | 9 | namespace HumbleConfig.FunctionalTests 10 | { 11 | [TestFixture] 12 | public class MultiCacheConfigurationTests 13 | { 14 | private IConfiguration _configuration; 15 | 16 | private string _key1; 17 | private Dictionary _inMemory; 18 | private Fixture _fixture; 19 | 20 | [OneTimeSetUp] 21 | public void GivenConfigurationWithEnvironmentVaribleAndConfigurationManager() 22 | { 23 | _fixture = new Fixture(); 24 | _key1 = _fixture.Create("key1"); 25 | _inMemory = new Dictionary() 26 | { 27 | { _key1, "InMemory1"}, 28 | }; 29 | 30 | _configuration = new Configuration() 31 | .AddInMemory(new Dictionary()).WithDefaultMemoryCache(() => new CacheItemPolicy()) 32 | .AddInMemory(new Dictionary{{ _key1, "InMemory1"}}).WithDefaultMemoryCache(() => new CacheItemPolicy()) 33 | .GetConfiguration(); 34 | } 35 | 36 | [Test] 37 | public async Task WhenChangingValueStillReturnsTheSameValue() 38 | { 39 | var value1 = await _configuration.GetAppSettingAsync(_key1); 40 | var value2 = await _configuration.GetAppSettingAsync(_key1); 41 | 42 | Assert.AreEqual(value1, "InMemory1"); 43 | Assert.AreEqual(value2, "InMemory1"); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.FunctionalTests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("HumbleConfig.FunctionalTests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("19879791-bb47-4e82-8276-402990317e1e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/HumbleConfig.FunctionalTests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb.Tests/HumbleConfig.MongoDb.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {14D4655C-8E01-4D90-A774-52F37361B041} 8 | Library 9 | Properties 10 | HumbleConfig.MongoDb.Tests 11 | HumbleConfig.MongoDb.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\MongoDB.Bson.2.2.4\lib\net45\MongoDB.Bson.dll 35 | True 36 | 37 | 38 | ..\packages\MongoDB.Driver.2.2.4\lib\net45\MongoDB.Driver.dll 39 | True 40 | 41 | 42 | ..\packages\MongoDB.Driver.Core.2.2.4\lib\net45\MongoDB.Driver.Core.dll 43 | True 44 | 45 | 46 | ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | {C0FFC254-2495-483A-AA70-1E592148D03E} 65 | HumbleConfig.MongoDb 66 | 67 | 68 | {27C04368-FC7A-4D87-8F60-A14FE965FB71} 69 | HumbleConfig.Tests 70 | 71 | 72 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 73 | HumbleConfig 74 | 75 | 76 | 77 | 78 | 79 | 80 | 87 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb.Tests/MongoDbSourceTests/ConfigRSourceTestsForExistingConfigRKey.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.Tests; 2 | using MongoDB.Bson; 3 | using MongoDB.Driver; 4 | using NUnit.Framework; 5 | 6 | namespace HumbleConfig.MongoDb.Tests.MongoDbSourceTests 7 | { 8 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 9 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 10 | public class MongoDbSourceTestsForExistingKey : ConfigurationSourceTestsForExistingKey 11 | { 12 | private readonly IMongoCollection _collection = new MongoClient().GetDatabase("test").GetCollection("appSettings"); 13 | 14 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue value) 15 | { 16 | _collection.InsertOneAsync(new AppSetting() 17 | { 18 | Id = key, 19 | Value = value 20 | }).Wait(); 21 | 22 | return new MongoDbSource(_collection); 23 | } 24 | 25 | protected override void DestroyEvidence(string key) 26 | { 27 | _collection.DeleteOneAsync(new BsonDocument("_id", key)).Wait(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb.Tests/MongoDbSourceTests/MongoDbSourceTestsForNoneExistingKey.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.Tests; 2 | using MongoDB.Driver; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.MongoDb.Tests.MongoDbSourceTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 9 | public class MongoDbSourceTestsForNoneExistingKey : ConfigurationSourceTestsForNoneExistingKey 10 | { 11 | protected override IConfigurationSource CreateConfigurationSource() 12 | { 13 | var collection = new MongoClient().GetDatabase("test").GetCollection("appSettings"); 14 | 15 | return new MongoDbSource(collection); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.MongoDb.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.MongoDb.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("14d4655c-8e01-4d90-a774-52f37361b041")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb/AppSetting.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.MongoDb 2 | { 3 | public sealed class AppSetting 4 | { 5 | public string Id { get; set; } 6 | 7 | public dynamic Value { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb/HumbleConfig.MongoDb.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {C0FFC254-2495-483A-AA70-1E592148D03E} 8 | Library 9 | Properties 10 | HumbleConfig.MongoDb 11 | HumbleConfig.MongoDb 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\MongoDB.Bson.2.2.4\lib\net45\MongoDB.Bson.dll 35 | True 36 | 37 | 38 | ..\packages\MongoDB.Driver.2.2.4\lib\net45\MongoDB.Driver.dll 39 | True 40 | 41 | 42 | ..\packages\MongoDB.Driver.Core.2.2.4\lib\net45\MongoDB.Driver.Core.dll 43 | True 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 63 | HumbleConfig 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 78 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb/HumbleConfig.MongoDb.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | false 10 | HumbleConfig is a simple abstraction on top of multiple config sources 11 | https://github.com/kevbite/HumbleConfig/ 12 | https://raw.githubusercontent.com/kevbite/HumbleConfig/master/HumbleConfig.png 13 | MongoDB Source for Humble Config 14 | Copyright HumbleConfig 2015 15 | Humble Config MongoDB Mongo Database 16 | 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb/MongoDbExtensions.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Driver; 2 | 3 | namespace HumbleConfig.MongoDb 4 | { 5 | public static class MongoDbExtensions 6 | { 7 | public static IConfigurationSourceConfigurator AddMongoDb(this IConfigurationConfigurator configuration, MongoUrl mongoUrl, string collectionName) 8 | { 9 | var mongoClient = new MongoClient(mongoUrl); 10 | var database = mongoClient.GetDatabase(mongoUrl.DatabaseName); 11 | var collection = database.GetCollection(collectionName); 12 | 13 | return configuration.AddConfigurationSource(new MongoDbSource(collection)); 14 | } 15 | 16 | public static IConfigurationSourceConfigurator AddMongoDb(this IConfigurationConfigurator configuration, string url, string collectionName) 17 | { 18 | var mongoUrl = new MongoUrl(url); 19 | 20 | return configuration.AddMongoDb(mongoUrl, collectionName); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb/MongoDbSource.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http.Headers; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using MongoDB.Bson; 5 | using MongoDB.Bson.Serialization; 6 | using MongoDB.Driver; 7 | 8 | namespace HumbleConfig.MongoDb 9 | { 10 | public class MongoDbSource : IConfigurationSource 11 | { 12 | private readonly IMongoCollection _collection; 13 | 14 | public MongoDbSource(IMongoCollection collection) 15 | { 16 | _collection = collection; 17 | } 18 | 19 | public async Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 20 | { 21 | var document = await _collection.Find(new BsonDocument("_id", key)) 22 | .SingleOrDefaultAsync(cancellationToken) 23 | .ConfigureAwait(false); 24 | 25 | if (document == null) 26 | { 27 | return ConfigurationSourceResult.FailedResult(); 28 | } 29 | 30 | return 31 | ConfigurationSourceResult.SuccessResult( 32 | (TValue) document.Value); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.MongoDb")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.MongoDb")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c0ffc254-2495-483a-aa70-1e592148d03e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.MongoDb/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationSourceTestsForExistingKey`1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using NUnit.Framework; 7 | using Ploeh.AutoFixture; 8 | 9 | namespace HumbleConfig.Tests 10 | { 11 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 12 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 13 | public abstract class ConfigurationSourceTestsForExistingKey 14 | { 15 | private IConfigurationSource _source; 16 | private ConfigurationSourceResult _result; 17 | private readonly Fixture _fixture = new Fixture(); 18 | private string _key; 19 | private TValue _expectedValue; 20 | 21 | [OneTimeSetUp] 22 | public void GivenConfigurationSourceWithExistingRKey() 23 | { 24 | _key = _fixture.Create(); 25 | _expectedValue = _fixture.Create(); 26 | 27 | _source = GivenConfigurationSourceWithExistingRKey(_key, _expectedValue); 28 | } 29 | 30 | protected abstract IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue expectedValue); 31 | 32 | [SetUp] 33 | public void WhenTryingToGetTheAppSettings() 34 | { 35 | _result = _source.GetAppSettingAsync(_key).Result; 36 | } 37 | 38 | [Test] 39 | public void ThenTheCorrectValueIsReturned() 40 | { 41 | Assert.That(_result.Value, Is.EqualTo(_expectedValue)); 42 | } 43 | 44 | [Test] 45 | public void ThenTheResultKeyExistsIsTrue() 46 | { 47 | Assert.That(_result.KeyExists, Is.True); 48 | } 49 | 50 | [OneTimeTearDown] 51 | public void DestroyEvidence() 52 | { 53 | DestroyEvidence(_key); 54 | } 55 | 56 | protected virtual void DestroyEvidence(string key) 57 | { 58 | 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationSourceTestsForNoneExistingKey`1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using NUnit.Framework; 7 | using Ploeh.AutoFixture; 8 | 9 | namespace HumbleConfig.Tests 10 | { 11 | public abstract class ConfigurationSourceTestsForNoneExistingKey 12 | { 13 | private IConfigurationSource _source; 14 | private ConfigurationSourceResult _result; 15 | 16 | [OneTimeSetUp] 17 | public void GivenConfigurationSourceWithNoneExistingKey() 18 | { 19 | _source = CreateConfigurationSource(); 20 | } 21 | 22 | protected abstract IConfigurationSource CreateConfigurationSource(); 23 | 24 | [SetUp] 25 | public void WhenTryingToGetTheAppSettings() 26 | { 27 | var key = new Fixture().Create(); 28 | _result = _source.GetAppSettingAsync(key).Result; 29 | } 30 | 31 | [Test] 32 | public void ThenNullIsReturned() 33 | { 34 | Assert.That(_result.Value, Is.EqualTo(default(TValue))); 35 | } 36 | 37 | [Test] 38 | public void ThenTheResultKeyExistsIsFalse() 39 | { 40 | Assert.That(_result.KeyExists, Is.False); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForKeyFormatter.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using Moq; 3 | using NUnit.Framework; 4 | using Ploeh.AutoFixture; 5 | 6 | namespace HumbleConfig.Tests.ConfigurationTests 7 | { 8 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 9 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 10 | public class ConfigurationTestsForKeyFormatter 11 | { 12 | private readonly Fixture _fixture = new Fixture(); 13 | private string _formattedKey; 14 | private Mock _source; 15 | private Configuration _configuration; 16 | private string _key; 17 | 18 | [OneTimeSetUp] 19 | public void GivenAnConfigurationWithACustomKeyFormatter() 20 | { 21 | _key = _fixture.Create(); 22 | _formattedKey = _fixture.Create(); 23 | var value = _fixture.Create(); 24 | var keyFormatter = new Mock(); 25 | keyFormatter.Setup(x => x.FormatKey(_key)) 26 | .Returns(_formattedKey); 27 | 28 | _source = new Mock(); 29 | _source.Setup(x => x.GetAppSettingAsync(_formattedKey, default(CancellationToken))) 30 | .ReturnsAsync(ConfigurationSourceResult.SuccessResult(value)); 31 | 32 | _configuration = new Configuration(); 33 | _configuration.AddConfigurationSource(_source.Object); 34 | _configuration.SetKeyFormatter(keyFormatter.Object); 35 | } 36 | 37 | [SetUp] 38 | public void WhenGettingAnAppSetting() 39 | { 40 | _configuration.GetAppSettingAsync(_key).Wait(); 41 | } 42 | 43 | [Test] 44 | public void ThenTheSourceIsCalledWithTheFormattedKey() 45 | { 46 | _source.Verify(x => x.GetAppSettingAsync(_formattedKey, default(CancellationToken)), Times.Once); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForMultipleSourcesAndAllHaveMatchingKeys.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.Tests.Stubs; 2 | using NUnit.Framework; 3 | using Ploeh.AutoFixture; 4 | 5 | namespace HumbleConfig.Tests.ConfigurationTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 9 | public class ConfigurationTestsForMultipleSourcesAndAllHaveMatchingKeys 10 | { 11 | private Configuration _configuration; 12 | private TValue _value; 13 | 14 | private ConfigurationSourceStub _source1; 15 | private ConfigurationSourceStub _source2; 16 | private string _key; 17 | 18 | [OneTimeSetUp] 19 | public void GivenAConfigurationWithMultipleSourcesAndAllHaveMatchingKeys() 20 | { 21 | var fixture = new Fixture(); 22 | _key = fixture.Create(); 23 | _configuration = new Configuration(); 24 | 25 | _source1 = new ConfigurationSourceStub(); 26 | _source1.AppSettings.Add(_key, fixture.Create()); 27 | 28 | _source2 = new ConfigurationSourceStub(); 29 | _source2.AppSettings.Add(_key, fixture.Create()); 30 | 31 | _configuration.AddConfigurationSource(_source1); 32 | _configuration.AddConfigurationSource(_source2); 33 | } 34 | 35 | [SetUp] 36 | public void WhenGettingAnAppSetting() 37 | { 38 | _value = _configuration.GetAppSettingAsync(_key).Result; 39 | } 40 | 41 | [Test] 42 | public void ThenTheValueReturnedMatchesTheFirstSource() 43 | { 44 | Assert.That(_value, Is.EqualTo(_source1.AppSettings[_key])); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForMultipleSourcesAndOnlyTheLastHasAMatchingKey.cs: -------------------------------------------------------------------------------- 1 |  2 | using HumbleConfig.Tests.Stubs; 3 | using NUnit.Framework; 4 | using Ploeh.AutoFixture; 5 | 6 | namespace HumbleConfig.Tests.ConfigurationTests 7 | { 8 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 9 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 10 | public class ConfigurationTestsForMultipleSourcesAndOnlyTheLastHasAMatchingKey 11 | { 12 | private Configuration _configuration; 13 | private TValue _value; 14 | 15 | private ConfigurationSourceStub _source1; 16 | private ConfigurationSourceStub _source2; 17 | private string _key; 18 | 19 | [OneTimeSetUp] 20 | public void GivenAConfigurationWithTwoSourcesAndOnlyTheLastHasAMatchingKey() 21 | { 22 | var fixture = new Fixture(); 23 | _key = fixture.Create(); 24 | _configuration = new Configuration(); 25 | 26 | _source1 = new ConfigurationSourceStub(); 27 | 28 | _source2 = new ConfigurationSourceStub(); 29 | _source2.AppSettings.Add(_key, fixture.Create()); 30 | 31 | _configuration.AddConfigurationSource(_source1); 32 | _configuration.AddConfigurationSource(_source2); 33 | } 34 | 35 | [SetUp] 36 | public void WhenGettingAnAppSetting() 37 | { 38 | _value = _configuration.GetAppSettingAsync(_key).Result; 39 | } 40 | 41 | [Test] 42 | public void ThenTheValueReturnedMatchesTheLastSource() 43 | { 44 | Assert.That(_value, Is.EqualTo(_source2.AppSettings[_key])); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForNoSourcesForNoneNullableValues.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework; 3 | 4 | namespace HumbleConfig.Tests.ConfigurationTests 5 | { 6 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 7 | public class ConfigurationTestsForNoSourcesForNoneNullableValues 8 | { 9 | private Configuration _configuration; 10 | private TValue _value; 11 | private ArgumentException _exception; 12 | 13 | [OneTimeSetUp] 14 | public void GivenAConfigurationWithNoSourcesLoaded() 15 | { 16 | _configuration = new Configuration(); 17 | } 18 | 19 | [SetUp] 20 | public void WhenGettingAnAppSetting() 21 | { 22 | try 23 | { 24 | _value = _configuration.GetAppSettingAsync("key").Result; 25 | } 26 | catch (ArgumentException ex) 27 | { 28 | _exception = ex; 29 | } 30 | catch (AggregateException ex) 31 | { 32 | var argumentException = ex.InnerException as ArgumentException; 33 | if (argumentException != null) 34 | { 35 | _exception = argumentException; 36 | 37 | } 38 | } 39 | } 40 | 41 | [Test] 42 | public void ThenAnExceptionIsThrown() 43 | { 44 | Assert.That(_exception, Is.Not.Null); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForNoSourcesForNullableValues.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | namespace HumbleConfig.Tests.ConfigurationTests 4 | { 5 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 6 | public class ConfigurationTestsForNoSourcesForNullableValues 7 | { 8 | private Configuration _configuration; 9 | private TValue _value; 10 | 11 | [OneTimeSetUp] 12 | public void GivenAConfigurationWithNoSourcesLoaded() 13 | { 14 | _configuration = new Configuration(); 15 | } 16 | 17 | [SetUp] 18 | public void WhenGettingAnAppSetting() 19 | { 20 | _value = _configuration.GetAppSettingAsync("key").Result; 21 | } 22 | 23 | [Test] 24 | public void ThenTheReturnValueIsNull() 25 | { 26 | Assert.That(_value, Is.Null); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForOneSourceThatHasAMatchingKey.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.Tests.Stubs; 2 | using NUnit.Framework; 3 | using Ploeh.AutoFixture; 4 | 5 | namespace HumbleConfig.Tests.ConfigurationTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 9 | public class ConfigurationTestsForOneSourceThatHasAMatchingKey 10 | { 11 | private string _key; 12 | private Configuration _configuration; 13 | private ConfigurationSourceStub _source; 14 | private TValue _value; 15 | 16 | 17 | [OneTimeSetUp] 18 | public void GivenAConfigurationWithOneSourceThatHasAMatchingKey() 19 | { 20 | var fixture = new Fixture(); 21 | _key = fixture.Create(); 22 | _configuration = new Configuration(); 23 | 24 | _source = new ConfigurationSourceStub(); 25 | _source.AppSettings.Add(_key, fixture.Create()); 26 | _configuration.AddConfigurationSource(_source); 27 | } 28 | 29 | [SetUp] 30 | public void WhenGettingAnAppSetting() 31 | { 32 | _value = _configuration.GetAppSettingAsync(_key).Result; 33 | } 34 | 35 | [Test] 36 | public void ThenTheValueReturnedMatchesSource() 37 | { 38 | Assert.That(_value, Is.EqualTo(_source.AppSettings[_key])); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForOneSourceThatHasNoMatchingKeyForNoneNullables.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using HumbleConfig.Tests.Stubs; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.Tests.ConfigurationTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | public class ConfigurationTestsForOneSourceThatHasNoMatchingKeyForNoneNullables 9 | { 10 | private Configuration _configuration; 11 | private TValue _value; 12 | private ArgumentException _exception; 13 | 14 | [OneTimeSetUp] 15 | public void GivenAConfigurationWithOneSourceThatHasNoMatchingKey() 16 | { 17 | _configuration = new Configuration(); 18 | 19 | var source = new ConfigurationSourceStub(); 20 | _configuration.AddConfigurationSource(source); 21 | } 22 | 23 | [SetUp] 24 | public void WhenGettingAnAppSetting() 25 | { 26 | try 27 | { 28 | _value = _configuration.GetAppSettingAsync("key").Result; 29 | 30 | } 31 | catch (ArgumentException ex) 32 | { 33 | _exception = ex; 34 | } 35 | catch (AggregateException ex) 36 | { 37 | var argumentException = ex.InnerException as ArgumentException; 38 | if (argumentException != null) 39 | { 40 | _exception = argumentException; 41 | 42 | } 43 | } 44 | } 45 | 46 | [Test] 47 | public void ThenAnExceptionIsThrown() 48 | { 49 | Assert.That(_exception, Is.Not.Null); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/ConfigurationTests/ConfigurationTestsForOneSourceThatHasNoMatchingKeyForNullables.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using HumbleConfig.Tests.Stubs; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.Tests.ConfigurationTests 6 | { 7 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 8 | public class ConfigurationTestsForOneSourceThatHasNoMatchingKeyForNullables 9 | { 10 | private Configuration _configuration; 11 | private TValue _value; 12 | 13 | [OneTimeSetUp] 14 | public void GivenAConfigurationWithOneSourceThatHasNoMatchingKey() 15 | { 16 | _configuration = new Configuration(); 17 | 18 | var source = new ConfigurationSourceStub(); 19 | _configuration.AddConfigurationSource(source); 20 | } 21 | 22 | [SetUp] 23 | public void WhenGettingAnAppSetting() 24 | { 25 | _value = _configuration.GetAppSettingAsync("key").Result; 26 | } 27 | 28 | [Test] 29 | public void ThenTheReturnValueIsNull() 30 | { 31 | Assert.That(_value, Is.Null); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/HumbleConfig.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {27C04368-FC7A-4D87-8F60-A14FE965FB71} 8 | Library 9 | Properties 10 | HumbleConfig.Tests 11 | HumbleConfig.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll 36 | 37 | 38 | ..\packages\Moq.4.7.145\lib\net45\Moq.dll 39 | 40 | 41 | ..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll 42 | 43 | 44 | ..\packages\AutoFixture.3.49.0\lib\net40\Ploeh.AutoFixture.dll 45 | True 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 83 | HumbleConfig 84 | 85 | 86 | 87 | 88 | 89 | 90 | 97 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/InMemory/InMemorySourceTests/InMemorySourceTestsForNoneExistingAppSettingKey.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using HumbleConfig.InMemory; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.Tests.InMemory.InMemorySourceTests 6 | { 7 | [TestFixtureSource(typeof(NonNullableTestFixtureCases))] 8 | [TestFixtureSource(typeof(NullableTestFixtureCases))] 9 | public class InMemorySourceTestsForNoneExistingAppSettingKey : ConfigurationSourceTestsForNoneExistingKey 10 | { 11 | protected override IConfigurationSource CreateConfigurationSource() 12 | { 13 | return new InMemorySource(new Dictionary()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/InMemory/InMemorySourceTests/InMemorySourceTestsSourceTestsForExistingAppSettingKey.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using HumbleConfig.InMemory; 3 | using NUnit.Framework; 4 | 5 | namespace HumbleConfig.Tests.InMemory.InMemorySourceTests 6 | { 7 | public class InMemorySourceTestsSourceTestsForExistingAppSettingKey : ConfigurationSourceTestsForExistingKey 8 | { 9 | protected override IConfigurationSource GivenConfigurationSourceWithExistingRKey(string key, TValue value) 10 | { 11 | var appSettings = new Dictionary() 12 | { 13 | {key, value} 14 | }; 15 | 16 | return new InMemorySource(appSettings); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/KeyFormatters/DefaultKeyFormatterTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using HumbleConfig.KeyFormatters; 7 | using NUnit.Framework; 8 | using Ploeh.AutoFixture; 9 | 10 | namespace HumbleConfig.Tests.KeyFormatters 11 | { 12 | [TestFixture] 13 | public class DefaultKeyFormatterTests 14 | { 15 | private DefaultKeyFormatter _formatter; 16 | private string _key; 17 | private string _formattedKey; 18 | 19 | [OneTimeSetUp] 20 | public void GivenADefaultKeyFormatter() 21 | { 22 | _formatter = new DefaultKeyFormatter(); 23 | } 24 | 25 | [SetUp] 26 | public void WhenFormattingTheKey() 27 | { 28 | _key = new Fixture().Create(); 29 | _formattedKey = _formatter.FormatKey(_key); 30 | } 31 | 32 | [Test] 33 | public void ThenTheSameKeyIsReturned() 34 | { 35 | Assert.That(_formattedKey, Is.EqualTo(_key)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/KeyFormatters/KeyFormatterConfigurationSourceDecoratorTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using HumbleConfig.KeyFormatters; 4 | using Moq; 5 | using NUnit.Framework; 6 | using Ploeh.AutoFixture; 7 | 8 | namespace HumbleConfig.Tests.KeyFormatters 9 | { 10 | [TestFixture] 11 | public class KeyFormatterConfigurationSourceDecoratorTests 12 | { 13 | private KeyFormatterConfigurationSourceDecorator _decorator; 14 | private Mock _keyFormatter; 15 | private Mock _configurationSource; 16 | private Fixture _fixture; 17 | 18 | [OneTimeSetUp] 19 | public void GivenAKeyFormatterConfigurationSourceDecorator() 20 | { 21 | _fixture = new Fixture(); 22 | _keyFormatter = new Mock(); 23 | _configurationSource = new Mock(); 24 | _decorator = new KeyFormatterConfigurationSourceDecorator(_configurationSource.Object, _keyFormatter.Object); 25 | } 26 | 27 | [Test] 28 | public async Task WhenGettingValue_ThenConfigurationSourceIsCalledWithNewKeyAndCorrectValueReturned() 29 | { 30 | var key = _fixture.Create("key"); 31 | var newKey = _fixture.Create("newKey"); 32 | _keyFormatter.Setup(x => x.FormatKey(key)) 33 | .Returns(newKey); 34 | 35 | var cancellationToken = new CancellationToken(); 36 | var value = _fixture.Create("value"); 37 | _configurationSource.Setup(x => x.GetAppSettingAsync(newKey, cancellationToken)) 38 | .ReturnsAsync(ConfigurationSourceResult.SuccessResult(value)); 39 | 40 | var actual = await _decorator.GetAppSettingAsync(key, cancellationToken); 41 | 42 | Assert.IsTrue(actual.KeyExists); 43 | Assert.AreEqual(value, actual.Value); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/KeyFormatters/KeyPostfixerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using HumbleConfig.KeyFormatters; 7 | using NUnit.Framework; 8 | using Ploeh.AutoFixture; 9 | 10 | namespace HumbleConfig.Tests.KeyFormatters 11 | { 12 | [TestFixture] 13 | public class KeyPostfixerTests 14 | { 15 | private KeyPostfixer _formatter; 16 | private string _key; 17 | private string _formattedKey; 18 | private string _postfix; 19 | 20 | [OneTimeSetUp] 21 | public void GivenAKeyPrefixer() 22 | { 23 | _postfix = new Fixture().Create(); 24 | _formatter = new KeyPostfixer(_postfix); 25 | } 26 | 27 | [SetUp] 28 | public void WhenFormattingTheKey() 29 | { 30 | _key = new Fixture().Create(); 31 | _formattedKey = _formatter.FormatKey(_key); 32 | } 33 | 34 | [Test] 35 | public void ThenTheKeyIsPrefixed() 36 | { 37 | Assert.That(_formattedKey, Does.EndWith(_postfix)); 38 | } 39 | 40 | [Test] 41 | public void ThenTheFormattedKeyEndWithTheKey() 42 | { 43 | Assert.That(_formattedKey, Does.StartWith(_key)); 44 | } 45 | 46 | [Test] 47 | public void ThenTheFormattedKeyIsTheCorrectLength() 48 | { 49 | var expectedLength = _key.Length + _postfix.Length; 50 | 51 | Assert.That(_formattedKey.Length, Is.EqualTo(expectedLength)); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/KeyFormatters/KeyPrefixerTests.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.KeyFormatters; 2 | using NUnit.Framework; 3 | using Ploeh.AutoFixture; 4 | 5 | namespace HumbleConfig.Tests.KeyFormatters 6 | { 7 | [TestFixture] 8 | public class KeyPrefixerTests 9 | { 10 | private KeyPrefixer _formatter; 11 | private string _key; 12 | private string _formattedKey; 13 | private string _prefix; 14 | 15 | [OneTimeSetUp] 16 | public void GivenAKeyPrefixer() 17 | { 18 | _prefix = new Fixture().Create(); 19 | _formatter = new KeyPrefixer(_prefix); 20 | } 21 | 22 | [SetUp] 23 | public void WhenFormattingTheKey() 24 | { 25 | _key = new Fixture().Create(); 26 | _formattedKey = _formatter.FormatKey(_key); 27 | } 28 | 29 | [Test] 30 | public void ThenTheKeyIsPrefixed() 31 | { 32 | Assert.That(_formattedKey, Does.StartWith(_prefix)); 33 | } 34 | 35 | [Test] 36 | public void ThenTheFormattedKeyEndWithTheKey() 37 | { 38 | Assert.That(_formattedKey, Does.EndWith(_key)); 39 | } 40 | 41 | [Test] 42 | public void ThenTheFormattedKeyIsTheCorrectLength() 43 | { 44 | var expectedLength = _key.Length + _prefix.Length; 45 | 46 | Assert.That(_formattedKey.Length, Is.EqualTo(expectedLength)); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/NonNullableTestFixtureCases.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using NUnit.Framework; 6 | using NUnit.Framework.Internal; 7 | 8 | namespace HumbleConfig.Tests 9 | { 10 | public class NonNullableTestFixtureCases : IEnumerable 11 | { 12 | public IEnumerable GetTypes() 13 | { 14 | yield return typeof(bool); 15 | yield return typeof(byte); 16 | yield return typeof(char); 17 | yield return typeof(decimal); 18 | yield return typeof(double); 19 | yield return typeof(float); 20 | yield return typeof(int); 21 | yield return typeof(long); 22 | yield return typeof(sbyte); 23 | yield return typeof(short); 24 | } 25 | 26 | public IEnumerator GetEnumerator() 27 | { 28 | return GetTypes().Select(type => new TestFixtureParameters(new TypeArgsTestFixtureData(type))).GetEnumerator(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/NullableTestFixtureCases.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using NUnit.Framework.Internal; 6 | 7 | namespace HumbleConfig.Tests 8 | { 9 | public class NullableTestFixtureCases : IEnumerable 10 | { 11 | public IEnumerable GetTypes() 12 | { 13 | yield return typeof(bool?); 14 | yield return typeof(byte?); 15 | yield return typeof(char?); 16 | yield return typeof(decimal?); 17 | yield return typeof(double?); 18 | yield return typeof(float?); 19 | yield return typeof(int?); 20 | yield return typeof(long?); 21 | yield return typeof(sbyte?); 22 | yield return typeof(short?); 23 | yield return typeof(string); 24 | } 25 | 26 | public IEnumerator GetEnumerator() 27 | { 28 | return GetTypes().Select(type => new TestFixtureParameters(new TypeArgsTestFixtureData(type))).GetEnumerator(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("27c04368-fc7a-4d87-8f60-a14fe965fb71")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/Stubs/ConfigurationSourceStub.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace HumbleConfig.Tests.Stubs 6 | { 7 | public class ConfigurationSourceStub : IConfigurationSource 8 | { 9 | public IDictionary AppSettings { get; } = new Dictionary(); 10 | 11 | 12 | public Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 13 | { 14 | object temp; 15 | var result = AppSettings.TryGetValue(key, out temp); 16 | 17 | var sourceResult = result ? ConfigurationSourceResult.SuccessResult((TValue)temp) 18 | : ConfigurationSourceResult.FailedResult(); 19 | 20 | return Task.FromResult(sourceResult); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/TypeArgsTestFixtureData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using NUnit.Framework.Interfaces; 3 | using NUnit.Framework.Internal; 4 | 5 | namespace HumbleConfig.Tests 6 | { 7 | public class TypeArgsTestFixtureData : ITestFixtureData 8 | { 9 | public TypeArgsTestFixtureData(params Type[] typeArgs) 10 | { 11 | TypeArgs = typeArgs; 12 | } 13 | 14 | public string TestName { get; } = null; 15 | 16 | public RunState RunState { get; } = RunState.Runnable; 17 | 18 | public object[] Arguments { get; } = {}; 19 | 20 | public IPropertyBag Properties { get; } = new PropertyBag(); 21 | 22 | public Type[] TypeArgs { get; } 23 | } 24 | } -------------------------------------------------------------------------------- /src/HumbleConfig.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/HumbleConfig.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2002 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig", "HumbleConfig\HumbleConfig.csproj", "{B04CB40D-08D8-44C6-B66E-F1ED0E97E507}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.Tests", "HumbleConfig.Tests\HumbleConfig.Tests.csproj", "{27C04368-FC7A-4D87-8F60-A14FE965FB71}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.ConfigurationManager", "HumbleConfig.ConfigurationManager\HumbleConfig.ConfigurationManager.csproj", "{A1CA7848-F8B5-41AE-9AE8-19D1030B926B}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.ConfigurationManager.Tests", "HumbleConfig.ConfigurationManager.Tests\HumbleConfig.ConfigurationManager.Tests.csproj", "{7D9C2A7B-75F2-483C-8DA7-9C6D5250BC8B}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.EnvironmentVariables", "HumbleConfig.EnvironmentVariables\HumbleConfig.EnvironmentVariables.csproj", "{8C21C807-5FBB-46A6-AFE3-15028D257BAB}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.EnvironmentVariables.Tests", "HumbleConfig.EnvironmentVariables.Tests\HumbleConfig.EnvironmentVariables.Tests.csproj", "{7660560D-727C-4ABE-B741-94D2265417FB}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.FunctionalTests", "HumbleConfig.FunctionalTests\HumbleConfig.FunctionalTests.csproj", "{19879791-BB47-4E82-8276-402990317E1E}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{0BB7FB26-150B-44B4-B29E-3C6DAC32D1A4}" 21 | ProjectSection(SolutionItems) = preProject 22 | ..\appveyor.yml = ..\appveyor.yml 23 | ..\build-before_build.ps1 = ..\build-before_build.ps1 24 | ..\build-on_finish.ps1 = ..\build-on_finish.ps1 25 | EndProjectSection 26 | EndProject 27 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A41A1D5-5FCE-4261-AA40-70D01D7D280C}" 28 | ProjectSection(SolutionItems) = preProject 29 | ..\LICENSE = ..\LICENSE 30 | ..\README.md = ..\README.md 31 | EndProjectSection 32 | EndProject 33 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.ConfigR", "HumbleConfig.ConfigR\HumbleConfig.ConfigR.csproj", "{D0E7A0E1-B3B7-4B09-8AE7-C971A87638E4}" 34 | EndProject 35 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.ConfigR.Tests", "HumbleConfig.ConfigR.Tests\HumbleConfig.ConfigR.Tests.csproj", "{EBF29DE1-1998-4E51-AF84-4D76F969E7F5}" 36 | EndProject 37 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.MongoDb", "HumbleConfig.MongoDb\HumbleConfig.MongoDb.csproj", "{C0FFC254-2495-483A-AA70-1E592148D03E}" 38 | EndProject 39 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.MongoDb.Tests", "HumbleConfig.MongoDb.Tests\HumbleConfig.MongoDb.Tests.csproj", "{14D4655C-8E01-4D90-A774-52F37361B041}" 40 | EndProject 41 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.Credstash", "HumbleConfig.Credstash\HumbleConfig.Credstash.csproj", "{71683C23-7D6E-45F8-A2B4-D2078C2DA011}" 42 | EndProject 43 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.Credstash.Tests", "HumbleConfig.Credstash.Tests\HumbleConfig.Credstash.Tests.csproj", "{904F63FC-EF8E-4451-B5AC-9DCD0803B915}" 44 | EndProject 45 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.Caching", "HumbleConfig.Caching\HumbleConfig.Caching.csproj", "{025FC6D3-B42E-4B46-AD36-FA002ED26EA6}" 46 | EndProject 47 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HumbleConfig.Caching.Tests", "HumbleConfig.Caching.Tests\HumbleConfig.Caching.Tests.csproj", "{93E17785-3E7D-42C6-A44E-FAA26A2A5785}" 48 | EndProject 49 | Global 50 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 51 | Debug|Any CPU = Debug|Any CPU 52 | Release|Any CPU = Release|Any CPU 53 | EndGlobalSection 54 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 55 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 56 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507}.Debug|Any CPU.Build.0 = Debug|Any CPU 57 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507}.Release|Any CPU.ActiveCfg = Release|Any CPU 58 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507}.Release|Any CPU.Build.0 = Release|Any CPU 59 | {27C04368-FC7A-4D87-8F60-A14FE965FB71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 60 | {27C04368-FC7A-4D87-8F60-A14FE965FB71}.Debug|Any CPU.Build.0 = Debug|Any CPU 61 | {27C04368-FC7A-4D87-8F60-A14FE965FB71}.Release|Any CPU.ActiveCfg = Release|Any CPU 62 | {27C04368-FC7A-4D87-8F60-A14FE965FB71}.Release|Any CPU.Build.0 = Release|Any CPU 63 | {A1CA7848-F8B5-41AE-9AE8-19D1030B926B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 64 | {A1CA7848-F8B5-41AE-9AE8-19D1030B926B}.Debug|Any CPU.Build.0 = Debug|Any CPU 65 | {A1CA7848-F8B5-41AE-9AE8-19D1030B926B}.Release|Any CPU.ActiveCfg = Release|Any CPU 66 | {A1CA7848-F8B5-41AE-9AE8-19D1030B926B}.Release|Any CPU.Build.0 = Release|Any CPU 67 | {7D9C2A7B-75F2-483C-8DA7-9C6D5250BC8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 68 | {7D9C2A7B-75F2-483C-8DA7-9C6D5250BC8B}.Debug|Any CPU.Build.0 = Debug|Any CPU 69 | {7D9C2A7B-75F2-483C-8DA7-9C6D5250BC8B}.Release|Any CPU.ActiveCfg = Release|Any CPU 70 | {7D9C2A7B-75F2-483C-8DA7-9C6D5250BC8B}.Release|Any CPU.Build.0 = Release|Any CPU 71 | {8C21C807-5FBB-46A6-AFE3-15028D257BAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 72 | {8C21C807-5FBB-46A6-AFE3-15028D257BAB}.Debug|Any CPU.Build.0 = Debug|Any CPU 73 | {8C21C807-5FBB-46A6-AFE3-15028D257BAB}.Release|Any CPU.ActiveCfg = Release|Any CPU 74 | {8C21C807-5FBB-46A6-AFE3-15028D257BAB}.Release|Any CPU.Build.0 = Release|Any CPU 75 | {7660560D-727C-4ABE-B741-94D2265417FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 76 | {7660560D-727C-4ABE-B741-94D2265417FB}.Debug|Any CPU.Build.0 = Debug|Any CPU 77 | {7660560D-727C-4ABE-B741-94D2265417FB}.Release|Any CPU.ActiveCfg = Release|Any CPU 78 | {7660560D-727C-4ABE-B741-94D2265417FB}.Release|Any CPU.Build.0 = Release|Any CPU 79 | {19879791-BB47-4E82-8276-402990317E1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 80 | {19879791-BB47-4E82-8276-402990317E1E}.Debug|Any CPU.Build.0 = Debug|Any CPU 81 | {19879791-BB47-4E82-8276-402990317E1E}.Release|Any CPU.ActiveCfg = Release|Any CPU 82 | {19879791-BB47-4E82-8276-402990317E1E}.Release|Any CPU.Build.0 = Release|Any CPU 83 | {D0E7A0E1-B3B7-4B09-8AE7-C971A87638E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 84 | {D0E7A0E1-B3B7-4B09-8AE7-C971A87638E4}.Debug|Any CPU.Build.0 = Debug|Any CPU 85 | {D0E7A0E1-B3B7-4B09-8AE7-C971A87638E4}.Release|Any CPU.ActiveCfg = Release|Any CPU 86 | {D0E7A0E1-B3B7-4B09-8AE7-C971A87638E4}.Release|Any CPU.Build.0 = Release|Any CPU 87 | {EBF29DE1-1998-4E51-AF84-4D76F969E7F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 88 | {EBF29DE1-1998-4E51-AF84-4D76F969E7F5}.Debug|Any CPU.Build.0 = Debug|Any CPU 89 | {EBF29DE1-1998-4E51-AF84-4D76F969E7F5}.Release|Any CPU.ActiveCfg = Release|Any CPU 90 | {EBF29DE1-1998-4E51-AF84-4D76F969E7F5}.Release|Any CPU.Build.0 = Release|Any CPU 91 | {C0FFC254-2495-483A-AA70-1E592148D03E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 92 | {C0FFC254-2495-483A-AA70-1E592148D03E}.Debug|Any CPU.Build.0 = Debug|Any CPU 93 | {C0FFC254-2495-483A-AA70-1E592148D03E}.Release|Any CPU.ActiveCfg = Release|Any CPU 94 | {C0FFC254-2495-483A-AA70-1E592148D03E}.Release|Any CPU.Build.0 = Release|Any CPU 95 | {14D4655C-8E01-4D90-A774-52F37361B041}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 96 | {14D4655C-8E01-4D90-A774-52F37361B041}.Debug|Any CPU.Build.0 = Debug|Any CPU 97 | {14D4655C-8E01-4D90-A774-52F37361B041}.Release|Any CPU.ActiveCfg = Release|Any CPU 98 | {14D4655C-8E01-4D90-A774-52F37361B041}.Release|Any CPU.Build.0 = Release|Any CPU 99 | {71683C23-7D6E-45F8-A2B4-D2078C2DA011}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 100 | {71683C23-7D6E-45F8-A2B4-D2078C2DA011}.Debug|Any CPU.Build.0 = Debug|Any CPU 101 | {71683C23-7D6E-45F8-A2B4-D2078C2DA011}.Release|Any CPU.ActiveCfg = Release|Any CPU 102 | {71683C23-7D6E-45F8-A2B4-D2078C2DA011}.Release|Any CPU.Build.0 = Release|Any CPU 103 | {904F63FC-EF8E-4451-B5AC-9DCD0803B915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 104 | {904F63FC-EF8E-4451-B5AC-9DCD0803B915}.Debug|Any CPU.Build.0 = Debug|Any CPU 105 | {904F63FC-EF8E-4451-B5AC-9DCD0803B915}.Release|Any CPU.ActiveCfg = Release|Any CPU 106 | {904F63FC-EF8E-4451-B5AC-9DCD0803B915}.Release|Any CPU.Build.0 = Release|Any CPU 107 | {025FC6D3-B42E-4B46-AD36-FA002ED26EA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 108 | {025FC6D3-B42E-4B46-AD36-FA002ED26EA6}.Debug|Any CPU.Build.0 = Debug|Any CPU 109 | {025FC6D3-B42E-4B46-AD36-FA002ED26EA6}.Release|Any CPU.ActiveCfg = Release|Any CPU 110 | {025FC6D3-B42E-4B46-AD36-FA002ED26EA6}.Release|Any CPU.Build.0 = Release|Any CPU 111 | {93E17785-3E7D-42C6-A44E-FAA26A2A5785}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 112 | {93E17785-3E7D-42C6-A44E-FAA26A2A5785}.Debug|Any CPU.Build.0 = Debug|Any CPU 113 | {93E17785-3E7D-42C6-A44E-FAA26A2A5785}.Release|Any CPU.ActiveCfg = Release|Any CPU 114 | {93E17785-3E7D-42C6-A44E-FAA26A2A5785}.Release|Any CPU.Build.0 = Release|Any CPU 115 | EndGlobalSection 116 | GlobalSection(SolutionProperties) = preSolution 117 | HideSolutionNode = FALSE 118 | EndGlobalSection 119 | GlobalSection(ExtensibilityGlobals) = postSolution 120 | SolutionGuid = {ED37B15D-29C0-4297-9633-06E23E40182A} 121 | EndGlobalSection 122 | EndGlobal 123 | -------------------------------------------------------------------------------- /src/HumbleConfig/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using HumbleConfig.KeyFormatters; 6 | 7 | namespace HumbleConfig 8 | { 9 | public class Configuration : IConfigurationConfigurator, IConfiguration 10 | { 11 | private readonly List _configurationSources = new List(); 12 | private IKeyFormatter _keyFormatter = new DefaultKeyFormatter(); 13 | 14 | public async Task GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 15 | { 16 | var formattedKey = _keyFormatter.FormatKey(key); 17 | foreach (var configurationSource in _configurationSources) 18 | { 19 | var result = await configurationSource.Source.GetAppSettingAsync(formattedKey, cancellationToken).ConfigureAwait(false); 20 | if (result.KeyExists) 21 | { 22 | return result.Value; 23 | } 24 | } 25 | 26 | var valueType = typeof (TValue); 27 | 28 | if(valueType.IsClass || valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof (Nullable<>)) 29 | { 30 | return default(TValue); 31 | } 32 | 33 | throw new ArgumentException($"No value could be found for the given key of {key}", nameof(key)); 34 | } 35 | 36 | public IConfigurationSourceConfigurator AddConfigurationSource(IConfigurationSource configurationSource) 37 | { 38 | var wrapper = new ConfigurationSourceWrapper(this, configurationSource); 39 | 40 | _configurationSources.Add(wrapper); 41 | 42 | return wrapper; 43 | } 44 | 45 | public IConfiguration GetConfiguration() 46 | { 47 | return this; 48 | } 49 | 50 | public void SetKeyFormatter(IKeyFormatter keyFormatter) 51 | { 52 | _keyFormatter = keyFormatter; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/HumbleConfig/ConfigurationSourceResult.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig 2 | { 3 | public class ConfigurationSourceResult 4 | { 5 | private ConfigurationSourceResult() 6 | { 7 | } 8 | 9 | public static ConfigurationSourceResult SuccessResult(TValue value) 10 | { 11 | return new ConfigurationSourceResult() 12 | { 13 | KeyExists = true, 14 | Value = value 15 | }; 16 | } 17 | 18 | public static ConfigurationSourceResult FailedResult() 19 | { 20 | return new ConfigurationSourceResult() 21 | { 22 | KeyExists = false, 23 | Value = default(TValue) 24 | }; 25 | } 26 | 27 | public bool KeyExists { get; private set; } 28 | 29 | public TValue Value { get; private set; } 30 | } 31 | } -------------------------------------------------------------------------------- /src/HumbleConfig/ConfigurationSourceWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | namespace HumbleConfig 6 | { 7 | public class ConfigurationSourceWrapper : IConfigurationSourceConfigurator 8 | { 9 | private readonly Configuration _configuration; 10 | 11 | public ConfigurationSourceWrapper(Configuration configuration, IConfigurationSource configurationSource) 12 | { 13 | _configuration = configuration; 14 | Source = configurationSource; 15 | } 16 | 17 | public IConfigurationSource Source { get; private set; } 18 | 19 | public IConfigurationSourceConfigurator WrapSource(Func func) 20 | { 21 | Source = func(Source); 22 | 23 | return this; 24 | } 25 | 26 | public IConfigurationSourceConfigurator AddConfigurationSource(IConfigurationSource configurationSource) 27 | { 28 | return _configuration.AddConfigurationSource(configurationSource); 29 | } 30 | 31 | public Task GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 32 | { 33 | return _configuration.GetAppSettingAsync(key, cancellationToken); 34 | } 35 | 36 | public IConfiguration GetConfiguration() 37 | { 38 | return _configuration; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/HumbleConfig/HumbleConfig.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {B04CB40D-08D8-44C6-B66E-F1ED0E97E507} 8 | Library 9 | Properties 10 | HumbleConfig 11 | HumbleConfig 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | false 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 72 | -------------------------------------------------------------------------------- /src/HumbleConfig/HumbleConfig.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | false 10 | HumbleConfig is a simple abstraction on top of multiple config sources 11 | https://github.com/kevbite/HumbleConfig/ 12 | https://raw.githubusercontent.com/kevbite/HumbleConfig/master/HumbleConfig.png 13 | Humble Config 14 | Copyright HumbleConfig 2015 15 | Humble Config Configuration Management 16 | 17 | -------------------------------------------------------------------------------- /src/HumbleConfig/IConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace HumbleConfig 5 | { 6 | public interface IConfiguration 7 | { 8 | Task GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)); 9 | } 10 | } -------------------------------------------------------------------------------- /src/HumbleConfig/IConfigurationConfigurator.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig 2 | { 3 | public interface IConfigurationConfigurator 4 | { 5 | IConfigurationSourceConfigurator AddConfigurationSource(IConfigurationSource configurationSource); 6 | 7 | IConfiguration GetConfiguration(); 8 | } 9 | } -------------------------------------------------------------------------------- /src/HumbleConfig/IConfigurationSource.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | namespace HumbleConfig 5 | { 6 | public interface IConfigurationSource 7 | { 8 | Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)); 9 | } 10 | } -------------------------------------------------------------------------------- /src/HumbleConfig/IConfigurationSourceConfigurator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace HumbleConfig 4 | { 5 | public interface IConfigurationSourceConfigurator : IConfigurationConfigurator 6 | { 7 | IConfigurationSourceConfigurator WrapSource(Func func); 8 | } 9 | } -------------------------------------------------------------------------------- /src/HumbleConfig/IKeyFormatter.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig 2 | { 3 | public interface IKeyFormatter 4 | { 5 | string FormatKey(string key); 6 | } 7 | } -------------------------------------------------------------------------------- /src/HumbleConfig/InMemory/InMemoryExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace HumbleConfig.InMemory 4 | { 5 | public static class InMemoryExtensions 6 | { 7 | public static IConfigurationSourceConfigurator AddInMemory(this IConfigurationConfigurator configuration, IDictionary appSettings) 8 | { 9 | return configuration.AddConfigurationSource(new InMemorySource(appSettings)); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/HumbleConfig/InMemory/InMemorySource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace HumbleConfig.InMemory 7 | { 8 | public class InMemorySource : IConfigurationSource 9 | { 10 | private readonly IDictionary _appSettings; 11 | 12 | public InMemorySource(IDictionary appSettings) 13 | { 14 | _appSettings = appSettings; 15 | } 16 | 17 | public Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 18 | { 19 | object temp; 20 | var result = _appSettings.TryGetValue(key, out temp); 21 | 22 | var sourceResult = result ? ConfigurationSourceResult.SuccessResult((TValue) temp) 23 | : ConfigurationSourceResult.FailedResult(); 24 | 25 | return Task.FromResult(sourceResult); 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /src/HumbleConfig/KeyFormatters/DefaultKeyFormatter.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.KeyFormatters 2 | { 3 | public class DefaultKeyFormatter : IKeyFormatter 4 | { 5 | public string FormatKey(string key) 6 | { 7 | return key; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/HumbleConfig/KeyFormatters/KeyFormatterConfigurationSourceDecorator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace HumbleConfig.KeyFormatters 9 | { 10 | public class KeyFormatterConfigurationSourceDecorator : IConfigurationSource 11 | { 12 | private readonly IConfigurationSource _inner; 13 | private readonly IKeyFormatter _keyFormatter; 14 | 15 | public KeyFormatterConfigurationSourceDecorator(IConfigurationSource inner, IKeyFormatter keyFormatter) 16 | { 17 | _inner = inner; 18 | _keyFormatter = keyFormatter; 19 | } 20 | public async Task> GetAppSettingAsync(string key, CancellationToken cancellationToken = default(CancellationToken)) 21 | { 22 | key = _keyFormatter.FormatKey(key); 23 | 24 | return await _inner.GetAppSettingAsync(key, cancellationToken).ConfigureAwait(false); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/HumbleConfig/KeyFormatters/KeyFormatterExtensions.cs: -------------------------------------------------------------------------------- 1 | using HumbleConfig.InMemory; 2 | 3 | namespace HumbleConfig.KeyFormatters 4 | { 5 | public static class KeyFormatterExtensions 6 | { 7 | public static Configuration WithKeyPrefixer(this Configuration configuration, string prefix) 8 | { 9 | configuration.SetKeyFormatter(new KeyPrefixer(prefix)); 10 | 11 | return configuration; 12 | } 13 | 14 | public static Configuration WithKeyPostfixer(this Configuration configuration, string postfix) 15 | { 16 | configuration.SetKeyFormatter(new KeyPostfixer(postfix)); 17 | 18 | return configuration; 19 | } 20 | 21 | public static IConfigurationConfigurator WithKeyFormatter(this IConfigurationSourceConfigurator configuration, IKeyFormatter keyFormatter) 22 | { 23 | return configuration.WrapSource(x => new KeyFormatterConfigurationSourceDecorator(x, keyFormatter)); 24 | } 25 | 26 | public static IConfigurationConfigurator WithKeyPrefixer(this IConfigurationSourceConfigurator configuration, string prefix) 27 | { 28 | return WithKeyFormatter(configuration, new KeyPrefixer(prefix)); 29 | } 30 | 31 | public static IConfigurationConfigurator WithKeyPostfixer(this IConfigurationSourceConfigurator configuration, string postfix) 32 | { 33 | return WithKeyFormatter(configuration, new KeyPostfixer(postfix)); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/HumbleConfig/KeyFormatters/KeyPostfixer.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.KeyFormatters 2 | { 3 | public class KeyPostfixer : IKeyFormatter 4 | { 5 | private readonly string _keyPostfix; 6 | 7 | public KeyPostfixer(string keyPostfix) 8 | { 9 | _keyPostfix = keyPostfix; 10 | } 11 | 12 | public string FormatKey(string key) 13 | { 14 | return string.Format($"{key}{_keyPostfix}"); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/HumbleConfig/KeyFormatters/KeyPrefixer.cs: -------------------------------------------------------------------------------- 1 | namespace HumbleConfig.KeyFormatters 2 | { 3 | public class KeyPrefixer : IKeyFormatter 4 | { 5 | private readonly string _keyPrefix; 6 | 7 | public KeyPrefixer(string keyPrefix) 8 | { 9 | _keyPrefix = keyPrefix; 10 | } 11 | 12 | public string FormatKey(string key) 13 | { 14 | return string.Format($"{_keyPrefix}{key}"); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/HumbleConfig/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("HumbleConfig")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HumbleConfig")] 12 | [assembly: AssemblyProduct("HumbleConfig")] 13 | [assembly: AssemblyCopyright("Copyright © HumbleConfig 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b04cb40d-08d8-44c6-b66e-f1ed0e97e507")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: AssemblyInformationalVersion("1.0.0.0")] 38 | --------------------------------------------------------------------------------