Allows using TestContext for asp.net core configuration.. It is built on top of the Microsoft.Extensions.Configuration nuget package and supports .NET Core 2.0+ and .Net Framework 4.7+.
- Create your runsettings file and fill it with properties. Note that ":" is used as the delimiter.
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<TestRunParameters>
<Parameter name="NormalSetting" value="Value1" />
<Parameter name="ComplexObject:PropertyOnObject" value="VarValueInProperty" />
</TestRunParameters>
</RunSettings>
- Add TestContext configuration
var builder = new ConfigurationBuilder()
.AddTestContext(testContext);
Configuration = builder.Build();
- Use it like any other configuration source.
// Like this
Assert.AreEqual("Value1", Configuration["NormalSetting"]);
// Or this
var appConfig = Configuration.GetSection("ComplexObject").Get<MyPoco>();
Assert.AreEqual("VarValueInProperty", appConfig.PropertyOnObject);
.netcore 2.0+ OR .NET 4.7+
Nuget:
PM> Install-Package Contrib.Microsoft.Extensions.Configuration.TestContext