Using user secrets in integration test
To use user secrets in an integration test, do the following:
- install Microsoft.Extensions.Configuration.UserSecrets in the test project.
- copy the UserSecretsId from the startup project.
- build a new Configuration in the test Setup().
- use the Configuration as usual in the test(s).
<PropertyGroup>
<UserSecretsId>B4C6D3C1-2DE0-44B6-AFA8-8891DC665913</UserSecretsId>
</PropertyGroup>
[SetUp]
public void Setup()
{
// Needs Microsoft.Extensions.Configuration.UserSecrets NuGet package.
// To use the same secrets file as the main application, copy
// the <UserSecretsId> from the startup projects .csproj file to the
// .csproj file for this test assembly.
var builder = new ConfigurationBuilder()
.AddUserSecrets<SmsServiceIntegrationTests>();
Configuration = builder.Build();
}
var integrationTestPhoneNumber = Configuration["AppSettings:SmsMessaging:IntegrationTestPhoneNumber"];