using DynamicExpresso;
|
using OpenTap;
|
using OpenTap.Addin.Util;
|
using System;
|
|
namespace AddInPlugin.Util
|
{
|
public class DefaultVariableResolver : IVariableResolver
|
{
|
|
private Interpreter GetInterpreter(TestPlanRun run, ITestStep step)
|
{
|
var target = new Interpreter();
|
target.SetVariable("this", MethodUtil.Instance);
|
target.SetVariable("FileGlobals", run?.FileGlobalsRuntime);
|
target.SetVariable("StationGlobals", run?.StationGlobalsRuntime);
|
target.SetVariable("Parameters", run?.ParametersRuntime);
|
|
var context = step?.GetParent<ContextStep>();
|
if (context != null)
|
{
|
target.SetVariable("Context", context.GetContextVariables());
|
}
|
return target;
|
}
|
|
public dynamic Resolve(TestPlanRun run, ITestStep step, string expr)
|
{
|
return Resolve(run, step, expr, typeof(void));
|
}
|
|
public T Resolve<T>(TestPlanRun run, ITestStep step, string expr)
|
{
|
return Resolve(run, step, expr, typeof(T));
|
}
|
|
public dynamic Resolve(TestPlanRun run, ITestStep step, string expr, Type targetType)
|
{
|
if (expr == null) return null;
|
var target = GetInterpreter(run, step);
|
if (targetType == typeof(string))
|
{
|
return target.Eval(expr)?.ToString();
|
}
|
return target.Eval(expr, targetType);
|
}
|
}
|
}
|