mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
e6bfc51367
* Add additional integration tests and add OpenAIAssistant integration tests project. * Address PR comments. * Address PR comments.
41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace AgentConformance.IntegrationTests.Support;
|
|
|
|
/// <summary>
|
|
/// Helper for loading test configuration settings.
|
|
/// </summary>
|
|
public sealed class TestConfiguration
|
|
{
|
|
private static readonly IConfiguration s_configuration = new ConfigurationBuilder()
|
|
.AddJsonFile(path: "testsettings.json", optional: true)
|
|
.AddJsonFile(path: "testsettings.development.json", optional: true)
|
|
.AddEnvironmentVariables()
|
|
.AddUserSecrets<TestConfiguration>()
|
|
.Build();
|
|
|
|
/// <summary>
|
|
/// Loads the type of configuration using a section name based on the type name.
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of config to load.</typeparam>
|
|
/// <returns>The loaded configuration section of the specified type.</returns>
|
|
/// <exception cref="InvalidOperationException">Thrown if the configuration section cannot be loaded.</exception>
|
|
public static T LoadSection<T>()
|
|
{
|
|
var configType = typeof(T);
|
|
var configTypeName = configType.Name;
|
|
|
|
var trimText = "Configuration";
|
|
if (configTypeName.EndsWith(trimText, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
configTypeName = configTypeName.Substring(0, configTypeName.Length - trimText.Length);
|
|
}
|
|
|
|
return s_configuration.GetRequiredSection(configTypeName).Get<T>() ??
|
|
throw new InvalidOperationException($"Could not load config for {configTypeName}.");
|
|
}
|
|
}
|