示例#1
0
        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);
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
		/// <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);
			}
		}
示例#5
0
		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);
			}
		}
示例#6
0
        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);
            }
        }
示例#7
0
 internal ExecutableScript(IExecutableScript script, object syncLock)
 {
     _script   = script;
     _syncLock = syncLock;
 }
示例#8
0
 public FileScript(string fileName)
 {
     FileName = fileName;
     script = new DeferredScript(() => File.ReadAllText(FileName));
 }
			internal ExecutableScript(IExecutableScript script, object syncLock)
			{
				_script = script;
				_syncLock = syncLock;
			}
示例#10
0
 public DbTestingUtility AddTearDownScript(IExecutableScript script)
 {
     tearDownScripts.Add(script);
     return this;
 }
示例#11
0
 public DbTestingUtility AddSetUpScript(IExecutableScript script)
 {
     setupScripts.Add(script);
     return this;
 }
示例#12
0
 public DbTestingUtility AddSchemaScript(IExecutableScript script)
 {
     schemaScripts.Add(script);
     return this;
 }
示例#13
0
        /// <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);
            }
        }