public override object Evaluate(object arg) { if (string.IsNullOrEmpty(this.Text)) { return(null); } if (this.Text == AutomaticVariableToken) { return(arg); } try { // create the script if not yet created if (_script == null) { _script = CreateScript(this.Text); } // evaluate the test expression var context = new Dictionary <string, object> { { AutomaticVariableToken, arg } }; return(_script.Run(context)); } catch (Exception e) { throw new SpecificationException(string.Format(SR.ExceptionJScriptEvaluation, this.Text), e); } }
public override object Evaluate(object arg) { if (string.IsNullOrEmpty(this.Text)) { return(null); } if (this.Text == AUTOMATIC_VARIABLE_TOKEN) { return(arg); } try { // create the script if not yet created if (_script == null) { _script = CreateScript(this.Text); } // evaluate the test expression Dictionary <string, object> context = new Dictionary <string, object>(); context.Add(AUTOMATIC_VARIABLE_TOKEN, arg); return(_script.Run(context)); } catch (Exception e) { throw new SpecificationException(string.Format(SR.ExceptionJScriptEvaluation, this.Text), e); } }
/// <summary> /// Overload that allows the output of the template evaluation to be written directly to a <see cref="TextWriter"/>. /// </summary> /// <param name="context">A dictionary of objects to pass into the script.</param> /// <param name="output">A text writer to which the output should be written.</param> public void Evaluate(Dictionary <string, object> context, TextWriter output) { try { // add a variable for the output stream to the context context["__out__"] = output; // create executable script if not created if (_script == null) { var variables = CollectionUtils.Map(context.Keys, (string s) => s).ToArray(); _script = ScriptEngineFactory.GetEngine("jscript").CreateScript(_inversion, variables); } _script.Run(context); } catch (Exception e) { throw new ActiveTemplateException(SR.ExceptionTemplateEvaluation, e); } }
/// <summary> /// Overload that allows the output of the template evaluation to be written directly to a <see cref="TextWriter"/>. /// </summary> /// <param name="context">A dictionary of objects to pass into the script.</param> /// <param name="output">A text writer to which the output should be written.</param> public void Evaluate(Dictionary<string, object> context, TextWriter output) { try { // add a variable for the output stream to the context context["__out__"] = output; // create executable script if not created if (_script == null) { var variables = CollectionUtils.Map(context.Keys, (string s) => s).ToArray(); _script = ScriptEngineFactory.GetEngine("jscript").CreateScript(_inversion, variables); } _script.Run(context); } catch (Exception e) { throw new ActiveTemplateException(SR.ExceptionTemplateEvaluation, e); } }
public override object Evaluate(object arg) { if (string.IsNullOrEmpty(this.Text)) return null; if (this.Text == AutomaticVariableToken) return arg; try { // create the script if not yet created if (_script == null) _script = CreateScript(this.Text); // evaluate the test expression var context = new Dictionary<string, object> {{AutomaticVariableToken, arg}}; return _script.Run(context); } catch (Exception e) { throw new SpecificationException(string.Format(SR.ExceptionJScriptEvaluation, this.Text), e); } }
public override object Evaluate(object arg) { if(string.IsNullOrEmpty(this.Text)) return null; if (this.Text == AUTOMATIC_VARIABLE_TOKEN) return arg; try { // create the script if not yet created if (_script == null) _script = CreateScript(this.Text); // evaluate the test expression Dictionary<string, object> context = new Dictionary<string, object>(); context.Add(AUTOMATIC_VARIABLE_TOKEN, arg); return _script.Run(context); } catch (Exception e) { throw new SpecificationException(string.Format(SR.ExceptionJScriptEvaluation, this.Text), e); } }
internal ExecutableScript(IExecutableScript script, object syncLock) { _script = script; _syncLock = syncLock; }
public FileScript(string fileName) { FileName = fileName; script = new DeferredScript(() => File.ReadAllText(FileName)); }
public DbTestingUtility AddTearDownScript(IExecutableScript script) { tearDownScripts.Add(script); return this; }
public DbTestingUtility AddSetUpScript(IExecutableScript script) { setupScripts.Add(script); return this; }
public DbTestingUtility AddSchemaScript(IExecutableScript script) { schemaScripts.Add(script); return this; }
/// <summary> /// Executes a SQL script on the test database /// </summary> protected void RunSqlScript(IExecutableScript script) { logger.Info("Running {0}", script.Name); try { script.Execute(queryExecutor, ConnectionString); } catch (Exception e) { errors.Add(e); } }