TestHelper.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.IO;
  3. using Microsoft.Extensions.Configuration;
  4. namespace Padi.RedmineApi.Tests
  5. {
  6. internal static class TestHelper
  7. {
  8. public static IConfigurationRoot GetIConfigurationRoot(string outputPath)
  9. {
  10. var environment = Environment.GetEnvironmentVariable("Environment");
  11. return new ConfigurationBuilder()
  12. .SetBasePath(outputPath)
  13. .AddJsonFile("appsettings.json", optional: true)
  14. .AddJsonFile($"appsettings.{environment}.json", optional: true)
  15. .AddUserSecrets("f8b9e946-b547-42f1-861c-f719dca00a84")
  16. .AddEnvironmentVariables()
  17. .Build();
  18. }
  19. public static RedmineCredentials GetApplicationConfiguration(string outputPath = "")
  20. {
  21. if (string.IsNullOrWhiteSpace(outputPath))
  22. {
  23. outputPath = Directory.GetCurrentDirectory();
  24. }
  25. var credentials = new RedmineCredentials();
  26. var iConfig = GetIConfigurationRoot(outputPath);
  27. iConfig
  28. .GetSection("Credentials-Local")
  29. .Bind(credentials);
  30. return credentials;
  31. }
  32. }
  33. }