#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Xunit;
#endregion
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
///
/// Marks a test that only runs when the API assembly was produced by an official release build and the deployed bundled plugins are present.
///
[AttributeUsage(AttributeTargets.Method)]
[ExcludeFromCodeCoverage]
public sealed class DeployedBundledPluginsFactAttribute : FactAttribute
{
///
/// Gets the reason to skip the test. If set, the test will be skipped instead of executed.
///
public override string Skip
{
get
{
// xUnit evaluates Skip during discovery. Missing deployed plugins mean the solution was not built, which is normal locally,
// so the test is skipped with a reason instead of failing.
if (!OfficialReleaseBuildDetector.IsOfficialReleaseBuild())
return "The API assembly was not produced by an official release build.";
try
{
string repositoryRoot = BundledPluginManifestTestPaths.GetRepositoryRoot();
string pluginsDirectory = BundledPluginManifestTestPaths.GetDeployedPluginsDirectory(repositoryRoot);
// The deployed folder is produced by the solution build. If it is missing or empty there is no artifact to verify,
// so the test is skipped and the reason points at the path that was expected.
if (!Directory.Exists(pluginsDirectory))
return $"The deployed bundled plugins directory '{pluginsDirectory}' does not exist.";
if (!Directory.EnumerateFiles(pluginsDirectory, BundledPluginManifestTestPaths.PLUGIN_ASSEMBLY_SEARCH_PATTERN).Any())
return $"The deployed bundled plugins directory '{pluginsDirectory}' does not contain any bundled plugin assemblies.";
return string.Empty;
}
catch (InvalidOperationException exception)
{
return exception.Message;
}
}
}
}