예제 #1
0
            public StepScope Copy()
            {
                StepScope copy = new StepScope(ScopeName, ClassName, CacheKey, RootBranch);

                copy.VariableList.AddRange(VariableList);
                return(copy);
            }
예제 #2
0
        private void zRemoveCurrentScope()
        {
            m_ScopeList.Remove(m_CurrentScope.ScopeName);
            m_ScopeDictionary.Remove(m_CurrentScope.ScopeName);
            m_CurrentScope.VariableList.Clear();
            m_CurrentScope.RootBranch = null;

            m_CurrentScope = m_ScopeList.Count > 0 ? m_ScopeDictionary[m_ScopeList.Last()] : null;
        }
예제 #3
0
        private string zResolveCacheKeyFromScopeCacheList(StepScope scope, string variableNamePart)
        {
            List <StateVariableInfo> scopeCache = m_ElementSetVariableListCache[scope.CacheKey];

            foreach (StateVariableInfo scopeCacheVariable in scopeCache)
            {
                string tmpScopeNamePart, tmpVariableNamePart;
                DataUtils.ParseStateVariableName(scope.ScopeName, scopeCacheVariable.StateVariableName, out tmpScopeNamePart, out tmpVariableNamePart);
                if (tmpVariableNamePart == variableNamePart)
                {
                    return(scopeCacheVariable.StateVariableName);
                }
            }
            return(null);
        }
        private Scope ParseScope(StepScope bindingScope)
        {
            if (bindingScope == null)
            {
                return(null);
            }

            return(new Scope
            {
                FeatureTitle = bindingScope.FeatureTitle,
                ScenarioTitle = bindingScope.ScenarioTitle,
                Tag = string.IsNullOrWhiteSpace(bindingScope.Tag)
                    ? null
                    : _tagExpressionParser.Parse(bindingScope.Tag)
            });
        }
예제 #5
0
        public void Step(string keyword, StepKeyword stepKeyword, Parser.Gherkin.ScenarioBlock scenarioBlock, string text, GherkinBufferSpan stepSpan)
        {
            ColorizeKeywordLine(keyword, stepSpan, classifications.StepText);

            if (CurrentFileBlockBuilder.BlockType == typeof(IScenarioOutlineBlock))
            {
                var matches = placeholderRe.Matches(text);
                foreach (Match match in matches)
                {
                    ColorizeLinePart(match.Value, stepSpan, classifications.Placeholder);
                }
            }

            var editorLine = stepSpan.StartPosition.Line;
            var tags       = FeatureTags.Concat(CurrentFileBlockBuilder.Tags).Distinct();
            var stepScope  = new StepScope(FeatureTitle, CurrentFileBlockBuilder.BlockType == typeof(IBackgroundBlock) ? null : CurrentFileBlockBuilder.Title, tags.ToArray());

            currentStep = new GherkinStep((BindingType)scenarioBlock, (StepDefinitionKeyword)stepKeyword, text, stepScope, keyword, editorLine - CurrentFileBlockBuilder.KeywordLine);
            CurrentFileBlockBuilder.Steps.Add(currentStep);
        }
예제 #6
0
        private void zAddVariablesToScopeFromDatabaseStep(DatabaseStep databaseStep)
        {
            foreach (OutputParameterMap parameterMap in databaseStep.OutputParameterMapping)
            {
                zAddVariableToScope(m_CurrentScope.ScopeName,
                                    new StateVariableInfo(parameterMap.StateVariable, DataType.String, parameterMap.PersistenceMode)); //TODO: get actual datatype
            }
            if (databaseStep.ResultMapping is ScalarResultMapping)
            {
                ScalarResultMapping scalarResultMapping = (ScalarResultMapping)databaseStep.ResultMapping;
                zAddVariableToScope(m_CurrentScope.ScopeName,
                                    new StateVariableInfo(scalarResultMapping.StateVariable, DataType.String, scalarResultMapping.PersistenceMode)); //TODO: get actual datatype
            }
            if (databaseStep.ResultMapping is TableResultMapping)
            {
                TableResultMapping tableResultMapping       = (TableResultMapping)databaseStep.ResultMapping;
                StepScope          tempScopeForTableResults = null;
                if (tableResultMapping.ObjectSetClassName != null && tableResultMapping.ObjectSetListName != null)
                {
                    zAddVariableToScope(m_CurrentScope.ScopeName,
                                        new StateVariableInfo(tableResultMapping.ObjectSetListName, DataType.List, tableResultMapping.PersistenceMode));

                    string tempScopeCacheKey = zGetCacheKey(m_CurrentScope.ScopeName, tableResultMapping.ObjectSetListName);
                    tempScopeForTableResults = new StepScope(Guid.NewGuid().ToString(),
                                                             tableResultMapping.ObjectSetClassName,
                                                             tempScopeCacheKey,
                                                             null);
                    zSetCurrentScope(tempScopeForTableResults);
                }
                foreach (TableResultMap tableResultMap in tableResultMapping.TableMapping)
                {
                    zAddVariableToScope(m_CurrentScope.ScopeName,
                                        new StateVariableInfo(tableResultMap.StateVariable, DataType.String, tableResultMapping.PersistenceMode)); //TODO: get actual datatype
                }
                if (tempScopeForTableResults != null)
                {
                    zRemoveCurrentScope();
                }
            }
        }
예제 #7
0
 protected bool Equals(StepScope other)
 {
     return(string.Equals(Tag, other.Tag) && string.Equals(FeatureTitle, other.FeatureTitle) && string.Equals(ScenarioTitle, other.ScenarioTitle));
 }
예제 #8
0
 private StepDefinition CreateStepDefinition(string regex = null, string type = null, string sourceLocation = null, StepScope scope = null, string paramTypes = null, string method = null, string expression = null, string error = null)
 {
     return(new StepDefinition
     {
         Method = method ?? "M1",
         Type = type ?? "Given",
         Regex = regex ?? "regex",
         SourceLocation = sourceLocation,
         Scope = scope,
         ParamTypes = paramTypes,
         Expression = expression,
         Error = error
     });
 }
예제 #9
0
 public GherkinStep(BindingType bindingType, StepDefinitionKeyword stepDefinitionKeyword, string stepText, StepScope stepScope, string keyword, int blockRelativeLine)
     : base(bindingType, stepDefinitionKeyword, keyword, stepText, stepScope)
 {
     BlockRelativeLine = blockRelativeLine;
     BindingStatus     = BindingStatus.UnknownBindingStatus;
 }
예제 #10
0
 public StepInstance(ScenarioStep step, StepScope stepScope, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory, int level = 1)
     : base((BindingType)step.ScenarioBlock, (StepDefinitionKeyword)step.StepKeyword, step.Keyword, step.Text, stepScope)
 {
     this.NativeSuggestionItem = nativeSuggestionItemFactory.Create(step.Text, GetInsertionText(step), level, BindingType.ToString().Substring(0, 1), this);
 }
예제 #11
0
 private void zSetCurrentScope(StepScope newScope)
 {
     m_CurrentScope = newScope;
     m_ScopeDictionary.Add(newScope.ScopeName, newScope);
     m_ScopeList.Add(newScope.ScopeName);
 }
예제 #12
0
        /// <summary>
        /// Main sequence analysis loop, or an "Analysis Pass". This method "passes" through the sequence step by step,
        /// keeps track of the sequence structurally (scope list, scope dictionary),
        /// and fires delegates for each step and for completion.
        /// </summary>
        /// <param name="sequence"></param>
        /// <param name="onStepScope"></param>
        /// <param name="onSequenceComplete"></param>
        private void zAnalyzeSequence(List <Step> sequence, Func <Step, bool> onStepScope, Action onSequenceComplete)
        {
            //Make sure this SequenceAnalyzer is not being used by another thread. It is not thread safe! All concurrent usage must be done on separate instances.
            if (m_ExecutionStack != null)
            {
                throw new InvalidOperationException("A zAnalyzeSequence call is already in progress. If you need to use this method concurrently, use a separate SequenceAnalyzer instance for each concurrent call.");
            }

            try
            {
                if (sequence.Count > 0)
                {
                    m_ExecutionStack              = new ExecutionStack();
                    m_ExecutionStack.BranchEnded += m_ExecutionStack_BranchEnded;
                    m_ExecutionStack.SetSequence(sequence);

                    zSetCurrentScope(new StepScope(DataScope.RootScopeName,
                                                   DataScope.RootScopeName,
                                                   null,
                                                   m_ExecutionStack.CurrentBranch));

                    do
                    {
                        if (onStepScope != null && !onStepScope(m_ExecutionStack.CurrentStep))
                        {
                            break;
                        }

                        if (m_ExecutionStack.CurrentStep is GetValueStep)
                        {
                            GetValueStep getValueStep = (GetValueStep)m_ExecutionStack.CurrentStep;
                            zAddVariableToScopeFromGetValueStep(getValueStep);
                        }

                        if (m_ExecutionStack.CurrentStep is DatabaseStep)
                        {
                            DatabaseStep databaseStep = (DatabaseStep)m_ExecutionStack.CurrentStep;
                            zAddVariablesToScopeFromDatabaseStep(databaseStep);
                        }

                        if (m_ExecutionStack.CurrentStep is GroupStep)
                        {
                            GroupStep groupStep = (GroupStep)m_ExecutionStack.CurrentStep;
                            if (groupStep.Steps.Count > 0)
                            {
                                m_ExecutionStack.SetNewBranch(groupStep.Steps);
                            }

                            if (groupStep.Iteration is ObjectSetIteration && groupStep.Iteration.IsSetIteration)
                            {
                                ObjectSetIteration objectSetIteration = (ObjectSetIteration)groupStep.Iteration;

                                if (objectSetIteration is ElementSetIteration)
                                {
                                    ElementSetIteration elementSetIteration = (ElementSetIteration)objectSetIteration;
                                    zAddVariableToScopeFromElementSetIteration(elementSetIteration);
                                }

                                if (groupStep.Steps.Count > 0)
                                {
                                    string    newScopeCacheKey = zGetCacheKey(m_CurrentScope.ScopeName, objectSetIteration.ObjectSetListName);
                                    StepScope newScope         = new StepScope(objectSetIteration.ObjectSetScopeName,
                                                                               objectSetIteration.ObjectSetClassName,
                                                                               newScopeCacheKey,
                                                                               m_ExecutionStack.PendingBranch);

                                    if (objectSetIteration is DataSetIteration)
                                    {
                                        List <StateVariableInfo> cacheList;
                                        if (newScope.CacheKey != null && m_ElementSetVariableListCache.TryGetValue(newScope.CacheKey, out cacheList))
                                        {
                                            foreach (StateVariableInfo cachedVariable in cacheList)
                                            {
                                                if (newScope.ClassName == null || DataUtils.GetVariableNameScope(cachedVariable.StateVariableName) == newScope.ClassName)
                                                {
                                                    StateVariableInfo variableForNewScope = zRescopeVariable(cachedVariable, objectSetIteration.ObjectSetScopeName);
                                                    if (!newScope.VariableList.Contains(variableForNewScope))
                                                    {
                                                        newScope.VariableList.Add(variableForNewScope);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    zSetCurrentScope(newScope);
                                }
                            }
                        }
                    } while (m_ExecutionStack.MoveNext());
                }

                if (onSequenceComplete != null)
                {
                    onSequenceComplete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                zCleanup();
            }
        }
예제 #13
0
        public StepInstanceTemplate(ScenarioStep scenarioStep, ScenarioOutline scenarioOutline, StepScope stepScope, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory)
        {
            BindingType = (BindingType)scenarioStep.ScenarioBlock;

            NativeSuggestionItem = nativeSuggestionItemFactory.Create(scenarioStep.Text, StepInstance <TNativeSuggestionItem> .GetInsertionText(scenarioStep), 1, BindingType.ToString().Substring(0, 1) + "-t", this);
            instances            = new StepSuggestionList <TNativeSuggestionItem>(nativeSuggestionItemFactory);
            AddInstances(scenarioStep, scenarioOutline, stepScope, nativeSuggestionItemFactory);

            var match = paramRe.Match(scenarioStep.Text);

            StepPrefix = match.Success ? scenarioStep.Text.Substring(0, match.Index) : scenarioStep.Text;
        }
예제 #14
0
        private void AddInstances(ScenarioStep scenarioStep, ScenarioOutline scenarioOutline, StepScope stepScope, INativeSuggestionItemFactory <TNativeSuggestionItem> nativeSuggestionItemFactory)
        {
            foreach (var exampleSet in scenarioOutline.Examples.ExampleSets)
            {
                foreach (var row in exampleSet.Table.Body)
                {
                    var replacedText = paramRe.Replace(scenarioStep.Text,
                                                       match =>
                    {
                        string param    = match.Groups["param"].Value;
                        int headerIndex = Array.FindIndex(exampleSet.Table.Header.Cells, c => c.Value.Equals(param));
                        if (headerIndex < 0)
                        {
                            return(match.Value);
                        }
                        return(row.Cells[headerIndex].Value);
                    });

                    var newStep = scenarioStep.Clone();
                    newStep.Text = replacedText;
                    instances.Add(new StepInstance <TNativeSuggestionItem>(newStep, stepScope, nativeSuggestionItemFactory, 2)
                    {
                        ParentTemplate = this
                    });
                }
            }
        }