Ejemplo n.º 1
0
 public void ShouldHaveReceivedScenarioContext(ScenarioContext scenarioContext)
 {
     if (_appliedScenarioContext != scenarioContext)
     {
         throw new Exception("The given scenario context was never applied to this scenario.");
     }
 }
 string GetDependencies(ScenarioContext scenarioContext)
 {
     IEnumerable<string> dependencies = scenarioContext.GetPayloads()
         .Select(x => string.Format("var {0} = {1}", x.Key, x.Value));
     string dependenciesString = string.Join(";", dependencies);
     return dependenciesString;
 }
Ejemplo n.º 3
0
 public string Detokenize(string tokenizedString, ScenarioContext scenarioContext)
 {
     if (_whenDetokenizing.TokenizedString == tokenizedString)
     {
         return _whenDetokenizing.DetokenizedString;
     }
     return tokenizedString;
 }
Ejemplo n.º 4
0
 public string Evaluate(string javascriptExpression, ScenarioContext scenarioContext)
 {
     var payloadRecorded = scenarioContext.GetResponsePayload(javascriptExpression);
    
     if (_whenEvaluating.ScenarioContext == scenarioContext)
     {
         return payloadRecorded as string;
     }
     return javascriptExpression;
 }
        public string Evaluate(string javascriptExpression, ScenarioContext scenarioContext)
        {
            var engine = new ScriptEngine();
            string dependencies = GetDependencies(scenarioContext);
            string javascriptToEval = string.Format("var out;  {0};  out = {1};", dependencies, javascriptExpression);

            object returnVal = engine.Evaluate(javascriptToEval);
            if (returnVal is UserDefinedFunction)
            {
                engine.Execute(javascriptToEval);
                return engine.Evaluate("out()").ToString();
            }
            return returnVal.ToString();
        }
Ejemplo n.º 6
0
 public string Detokenize(string tokenizedString, ScenarioContext scenarioContext)
 {
     IEnumerable<string> stringsInToken = tokenizedString.Split(' ');
     var result = new List<string>();
     foreach (string str in stringsInToken)
     {
         if (str.StartsWith("%") && str.EndsWith("%"))
         {
             result.Add(_javascriptEvaluator.Evaluate(str.Replace("%", ""), scenarioContext));
         }
         else
         {
             result.Add(str);
         }
     }
     return string.Join(" ", result);
 }
Ejemplo n.º 7
0
 public virtual void ApplyContext(ScenarioContext scenarioContext)
 {
     foreach (var criterion in Criteria)
     {
         foreach (var step in criterion.Steps)
         {
             var propertyInfos = step.GetType().GetProperties();
             foreach (var propertyInfo in propertyInfos)
             {
                 if (propertyInfo.PropertyType==typeof(string))
                 {
                     var oldValue = propertyInfo.GetValue(step).ToString();
                     var newValue = scenarioContext.Interpret(oldValue);
                     if(propertyInfo.SetMethod!=null)
                         propertyInfo.SetValue(step, newValue);
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 public void Run(Scenario scenario)
 {
     _scenarioContext = _scenarioContextFactory.Create(scenario);
     scenario.ApplyContext(_scenarioContext);
     try
     {
         _progressReporter.Report(new ScenarioStartedReport(scenario.ScenarioId));
         foreach (Criterion criterion in scenario.Criteria.OrderBy(x => x.Priority))
         {
             _criterionRunner.Run(criterion, _scenarioContext, _executionContextFactory);
         }
         _progressReporter.Report(new ScenarioStoppedReport(scenario.ScenarioId));
     }
     catch (Exception ex)
     {
         _logger.LogException(ex);
         throw;
     }
     finally
     {
         _executionContextFactory.DestroyAllActiveExecutionContexts(scenario);
     }
 }
Ejemplo n.º 9
0
 public ScenarioContextCollector(ScenarioContext scenarioContext, string javaScriptExpression)
 {
     _scenarioContext = scenarioContext;
     _javaScriptExpression = javaScriptExpression;
 }
Ejemplo n.º 10
0
 public ScenarioContextCollector WithScenarioContext(ScenarioContext scenarioContext)
 {
     ScenarioContext = scenarioContext;
     _scenarioContextCollector = new ScenarioContextCollector(scenarioContext, JavascriptExpression);
     return _scenarioContextCollector;
 }
Ejemplo n.º 11
0
 public override void ApplyContext(ScenarioContext scenarioContext)
 {
     _appliedScenarioContext = scenarioContext;
 }
Ejemplo n.º 12
0
        public void Run(Criterion criterion, ScenarioContext scenarioContext, IExecutionContextFactory executionContextFactory)
        {
            if (criterion == _criterionToCauseException) throw _exceptionToThrow;

            _criteriaRun.Add(criterion);
        }
 public FakeScenarioContextFactory(ScenarioContext scenarioContext)
 {
     _scenarioContext = scenarioContext;
 }