#region ========================================================================= USING ===================================================================================== using System; using System.Diagnostics.CodeAnalysis; using System.IO; #endregion namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup; /// /// Locates the files and directories used by the bundled plugin manifest tests. /// /// /// The tests run from a configuration and target framework folder under bin/tests, so the repository root is found by walking up to the solution instead of hardcoding a machine-specific path. /// [ExcludeFromCodeCoverage] public static class BundledPluginManifestTestPaths { /// /// The name of the directory that holds the build scripts. /// public const string BUILD_DIRECTORY_NAME = "build"; /// /// The name of the directory that holds the build outputs. /// public const string BIN_DIRECTORY_NAME = "bin"; /// /// The name of the directory that holds the solution. /// public const string SOLUTION_DIRECTORY_NAME = "src"; /// /// The file name of the solution. /// public const string SOLUTION_FILE_NAME = "Nemera.slnx"; /// /// The name of the append-only bundled plugin trust manifest. /// public const string BUNDLED_PLUGINS_MANIFEST_FILE_NAME = "BundledPlugins.manifest"; /// /// The name of the bundled plugin revocation manifest. /// public const string BUNDLED_PLUGINS_DENY_MANIFEST_FILE_NAME = "BundledPlugins.deny.manifest"; /// /// The name of the bundled plugin release catalog. /// public const string BUNDLED_PLUGINS_PROPS_FILE_NAME = "BundledPlugins.props"; /// /// The name of the directory that holds the plugin projects. /// public const string PLUGINS_PROJECT_DIRECTORY_NAME = "plugins"; /// /// The name of the API output directory under the repository bin directory. /// public const string API_OUTPUT_DIRECTORY_NAME = "api"; /// /// The name of the directory that holds the deployed plugin assemblies. /// public const string PLUGINS_DIRECTORY_NAME = "plugins"; /// /// The file name of the published API assembly. /// public const string PUBLISHED_API_ASSEMBLY_FILE_NAME = "Nemera.Presentation.Api.dll"; /// /// The search pattern of the bundled plugin assemblies. /// public const string PLUGIN_ASSEMBLY_SEARCH_PATTERN = "Nemera.Plugins.*.dll"; /// /// The search pattern of the plugin project files. /// public const string PLUGIN_PROJECT_SEARCH_PATTERN = "*.csproj"; /// /// The extension of the bundled plugin assemblies. /// public const string PLUGIN_ASSEMBLY_EXTENSION = ".dll"; /// /// Locates the repository root from the test output directory. /// /// The absolute path of the repository root. public static string GetRepositoryRoot() { // Walk up from the test output directory until the solution file is found. This works regardless of how many folders the output is nested under bin. DirectoryInfo? directory = new(AppContext.BaseDirectory); while (directory is not null) { if (File.Exists(Path.Combine(directory.FullName, SOLUTION_DIRECTORY_NAME, SOLUTION_FILE_NAME))) return directory.FullName; directory = directory.Parent; } throw new InvalidOperationException("The repository root could not be located from the test output directory."); } /// /// Locates the append-only bundled plugin trust manifest. /// /// The absolute path of the repository root. /// The absolute path of the trust manifest. public static string GetBundledPluginsManifestPath(string repositoryRoot) { return Path.Combine(repositoryRoot, BUILD_DIRECTORY_NAME, BUNDLED_PLUGINS_MANIFEST_FILE_NAME); } /// /// Locates the bundled plugin revocation manifest. /// /// The absolute path of the repository root. /// The absolute path of the revocation manifest. public static string GetBundledPluginsDenyManifestPath(string repositoryRoot) { return Path.Combine(repositoryRoot, BUILD_DIRECTORY_NAME, BUNDLED_PLUGINS_DENY_MANIFEST_FILE_NAME); } /// /// Locates the bundled plugin release catalog. /// /// The absolute path of the repository root. /// The absolute path of the release catalog. public static string GetBundledPluginsPropsPath(string repositoryRoot) { return Path.Combine(repositoryRoot, BUILD_DIRECTORY_NAME, BUNDLED_PLUGINS_PROPS_FILE_NAME); } /// /// Locates the solution file. /// /// The absolute path of the repository root. /// The absolute path of the solution file. public static string GetSolutionPath(string repositoryRoot) { return Path.Combine(repositoryRoot, SOLUTION_DIRECTORY_NAME, SOLUTION_FILE_NAME); } /// /// Locates the directory that holds the plugin projects. /// /// The absolute path of the repository root. /// The absolute path of the plugin project directory. public static string GetPluginsProjectDirectory(string repositoryRoot) { return Path.Combine(repositoryRoot, PLUGINS_PROJECT_DIRECTORY_NAME); } /// /// Locates the plugins directory of the API build output for the current test configuration. /// /// The absolute path of the repository root. /// The absolute path of the deployed plugins directory, whether or not it exists. public static string GetDeployedPluginsDirectory(string repositoryRoot) { // The test output folder is bin/tests///, so its parent names the configuration // and its own name is the target framework. The API output mirrors that layout under bin/api. DirectoryInfo testOutputDirectory = new(AppContext.BaseDirectory); string configuration = testOutputDirectory.Parent?.Name ?? throw new InvalidOperationException("The test configuration could not be determined from the test output directory."); string targetFramework = testOutputDirectory.Name; return Path.Combine(repositoryRoot, BIN_DIRECTORY_NAME, API_OUTPUT_DIRECTORY_NAME, configuration, targetFramework, PLUGINS_DIRECTORY_NAME); } /// /// Locates the published API assembly in the publish output directory. /// /// The absolute path of the publish output directory. /// The absolute path of the published API assembly. public static string GetPublishedApiAssemblyPath(string publishDirectory) { return Path.Combine(publishDirectory, PUBLISHED_API_ASSEMBLY_FILE_NAME); } /// /// Locates the published plugins directory in the publish output directory. /// /// The absolute path of the publish output directory. /// The absolute path of the published plugins directory. public static string GetPublishedPluginsDirectory(string publishDirectory) { return Path.Combine(publishDirectory, PLUGINS_DIRECTORY_NAME); } }