7

I'm currently working on a .net core solution (multiple projects) that uses Microsoft's app secrets management. I can pull secrets back in my runtime project (e.g. Console app), but when it comes to leveraging user secrets for integration tests in a separate project (e.g. Model.Test project), what's the right approach?

I can think of a few options:

  1. Give each project the same UserSecretsId: This seems like it'd made sense for test projects that may leverage the same secrets that the runtime project uses.

  2. Let each project have unique UserSecretsId: This would require that the secrets be manually kept in sync on the development machine

It seems like even between .net core 1.0 and 2.0 user secrets has changed somewhat and I don't have a lot of familiarity with this system in general. Thanks!

Killnine
  • 5,487
  • 7
  • 36
  • 64

1 Answers1

7

I’m still learning about configuration in .NET Core 2 myself. When I set up my API project I shared the user secrets tag between the project and the unit test project by copying it between them. Meaning they both had the same user secrets guid, like your option 1. My rationale is that it would be the easiest way to maintain secrets between the two projects for the development team.

This article from Patrick Huber shows how to reference User Secrets in the config builder which was key for me - https://patrickhuber.github.io/2017/07/26/avoid-secrets-in-dot-net-core-tests.html

This article from Rick Strahl was also useful it shows how to configure a test helper in your unit tests for accessing the user secrets: https://weblog.west-wind.com/posts/2018/Feb/18/Accessing-Configuration-in-NET-Core-Test-Projects

Related implementation question - How to use user secrets in a dotnet core test project

Question related to referencing the config file - AppSettings.json for Integration Test in ASP.NET Core

Dale C
  • 431
  • 6
  • 9