using System.Reflection;
namespace MiniTestRunner;
///
/// Represents a setup method bound to a specific test instance.
/// Used to invoke setup logic before or after test execution.
///
/// The method information representing the setup method.
public sealed record TestSetup(MethodInfo MethodInfo)
{
///
/// Gets or sets the bound delegate for invoking the setup method.
///
private Action? Method { get; set; }
///
/// Binds the setup method to the specified test class instance.
///
/// The instance of the test class to bind the method to.
/// An delegate that can invoke the setup method.
private Action Bind(object instance)
{
return (Action)Delegate.CreateDelegate(typeof(Action), instance, MethodInfo);
}
///
/// Executes the setup method on the specified test class instance.
///
/// The instance of the test class on which to run the setup method.
public void Run(object instance)
{
this.Method ??= this.Bind(instance);
this.Method();
}
}