#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics.CodeAnalysis;
using Xunit;
#endregion
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
///
/// Marks a test that only runs when the named environment variable is set.
///
[AttributeUsage(AttributeTargets.Method)]
[ExcludeFromCodeCoverage]
public sealed class EnvironmentVariableFactAttribute : FactAttribute
{
///
/// The name of the environment variable that must be set for the test to run.
///
///
/// The name is stored because Skip is evaluated later, during test discovery.
///
private readonly string _environmentVariableName;
///
/// Initializes a new instance of the class.
///
/// The name of the environment variable that must be set for the test to run.
public EnvironmentVariableFactAttribute(string environmentVariableName)
{
_environmentVariableName = environmentVariableName;
}
///
/// Gets the reason to skip the test. If set, the test will be skipped instead of executed.
///
///
/// The published-artifact verification is opt-in: build/build.proj sets the variable only when it checks a publish output. Without it, the test would inspect a directory that does not exist, so it is skipped with a reason instead.
///
public override string Skip => string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(_environmentVariableName))
? $"The environment variable '{_environmentVariableName}' is not set."
: string.Empty;
}