I have a test project with ASP.NET Core and trying to read the appsettings values.
Created an appsetting.test.json file in the test project with below configuration
{
"baseUrl": "https://xxxxx.io/",
"user": {
"username": "[email protected]",
"password": "xxxxxxx@1xx7"
}
}
Created a helper class to read the json file
public interface IAppSettingConfiguration
{
public static IConfiguration InitConfiguration()
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.test.json")
.Build();
return config;
}
}
To read the baseurl I am using the below code
private IConfiguration _iAppSettingConfiguration;
private static string _readonlypageUrl;
public GivenAccount(PlaywrightFixture playwrightFixture)
{
_iAppSettingConfiguration = IAppSettingConfiguration.InitConfiguration();
_readonlypageUrl = _iAppSettingConfiguration["baseUrl"];
}
This is working fine I am able to get the value for base URL. How can use IOption<> to read whole object. In my case I want to read user
Not able to find the bind method from Microsoft.Extensions.Configuration namespace
namespace Microsoft.Extensions.Configuration
{
/// <summary>Represents a set of key/value application configuration properties.</summary>
public interface IConfiguration
{
/// <summary>Gets or sets a configuration value.</summary>
/// <param name="key">The configuration key.</param>
/// <returns>The configuration value.</returns>
string this[string key] { get; set; }
/// <summary>Gets a configuration sub-section with the specified key.</summary>
/// <param name="key">The key of the configuration section.</param>
/// <returns>The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationSection" />.</returns>
IConfigurationSection GetSection(string key);
/// <summary>Gets the immediate descendant configuration sub-sections.</summary>
/// <returns>The configuration sub-sections.</returns>
IEnumerable<IConfigurationSection> GetChildren();
/// <summary>Returns a <see cref="T:Microsoft.Extensions.Primitives.IChangeToken" /> that can be used to observe when this configuration is reloaded.</summary>
/// <returns>A <see cref="T:Microsoft.Extensions.Primitives.IChangeToken" />.</returns>
IChangeToken GetReloadToken();
}
}
