예제 #1
0
        private GherkinStep SearchStepInOptimizedSteps(string Name)
        {
            // TODO: go RegEx Search
            GherkinStep GH = (from x in mOptimizedSteps where x.Text.ToUpper() == Name.ToUpper() select x).FirstOrDefault();

            return(GH);
        }
예제 #2
0
 public override Style SelectStyle(object item, DependencyObject container)
 {
     if (mStyles == null)
     {
         CreateStyles();
     }
     if (item is GherkinStep)
     {
         GherkinStep step = (GherkinStep)item;
         return(mStyles[step.ColorIndex]);
     }
     return(null);
 }
예제 #3
0
        public bool Optimize()
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            mErrorsList.ClearAll();
            ShowErros(false);

            ColorIndex = 0;

            mGherkinScenarioDefinition.ClearAll();
            mGherkinSteps.ClearAll();
            mTags.ClearAll();

            mOptimizedSteps.ClearAll();
            OptimizedStepsGrid.DataSourceList = mOptimizedSteps;

            var parser = new Parser();

            try
            {
                string     txt             = GherkinTextEditor.GetText();
                TextReader sr              = new StringReader(txt);
                var        gherkinDocument = parser.Parse(sr);

                if (gherkinDocument.Feature == null || gherkinDocument.Feature.Children == null)
                {
                    Mouse.OverrideCursor = null;
                    return(false);
                }


                foreach (ScenarioDefinition SD in gherkinDocument.Feature.Children)
                {
                    mGherkinScenarioDefinition.Add(new GherkinScenarioDefinition(SD));
                }


                FeatureName = System.IO.Path.GetFileName(GherkinTextEditor.FileName).Replace(".feature", "");
                foreach (var c in gherkinDocument.Comments)
                {
                    WriteTXT("Comments:" + c.Text);
                }

                foreach (Tag t in gherkinDocument.Feature.Tags)
                {
                    mTags.Add(new GherkinTag(t));
                }

                mSolTags.ClearAll();
                foreach (GherkinTag tag in mTags)
                {
                    Guid guid = GetTagInSolution(tag.Name.Substring(1));
                    if (guid != Guid.Empty && !mSolTags.Contains(guid))
                    {
                        mSolTags.Add(guid);
                    }
                }
                foreach (var c in gherkinDocument.Feature.Children)
                {
                    if (c.Keyword == "Scenario" || c.Keyword == "Scenario Outline")
                    {
                        WriteTXT("Keyword:" + c.Keyword);
                        WriteTXT("Name:" + c.Name);

                        if (c is Scenario)
                        {
                            foreach (Tag t in ((Gherkin.Ast.Scenario)c).Tags)
                            {
                                mTags.Add(new GherkinTag(t));
                                Guid guid = GetTagInSolution(t.Name.Substring(1));
                                if (guid != Guid.Empty && !mSolTags.Contains(guid))
                                {
                                    mSolTags.Add(guid);
                                }
                            }
                        }

                        if (c is ScenarioOutline)
                        {
                            foreach (Tag t in ((Gherkin.Ast.ScenarioOutline)c).Tags)
                            {
                                mTags.Add(new GherkinTag(t));
                                Guid guid = GetTagInSolution(t.Name.Substring(1));
                                if (guid != Guid.Empty && !mSolTags.Contains(guid))
                                {
                                    mSolTags.Add(guid);
                                }
                            }
                        }
                    }
                }
                foreach (var c in gherkinDocument.Feature.Children)
                {
                    if (c.Keyword == "Scenario" || c.Keyword == "Scenario Outline")
                    {
                        foreach (var step in c.Steps)
                        {
                            WriteTXT("Keyword:" + step.Keyword);
                            WriteTXT("Text:" + step.Text);

                            GherkinStep GS = new GherkinStep();
                            GS.Text = step.Text;
                            GS.Step = step;
                            mGherkinSteps.Add(GS);

                            String GherkingActivityName = GherkinGeneral.GetActivityGherkinName(step.Text);

                            GherkinStep OptimizedStep = SearchStepInOptimizedSteps(GherkingActivityName);
                            if (OptimizedStep == null)
                            {
                                GherkinStep NewOptimizedStep = new GherkinStep();
                                NewOptimizedStep.Text       = GherkingActivityName;
                                NewOptimizedStep.Counter    = 1;
                                NewOptimizedStep.ColorIndex = ColorIndex;
                                ColorIndex++;
                                NewOptimizedStep.AutomationStatus = GetStepAutomationStatus(GherkingActivityName);
                                GS.AutomationStatus = NewOptimizedStep.AutomationStatus;
                                mOptimizedSteps.Add(NewOptimizedStep);
                            }
                            else
                            {
                                OptimizedStep.Counter++;
                                GS.ColorIndex       = OptimizedStep.ColorIndex;
                                GS.AutomationStatus = OptimizedStep.AutomationStatus;
                            }
                        }
                    }
                }

                // Warnings - TODO check other possible warnings
                // Check Dups Scenario names
                var query = mGherkinScenarioDefinition.GroupBy(x => x.Name)
                            .Where(g => g.Count() > 1)
                            .Select(y => y.Key)
                            .ToList();
                foreach (var v in query)
                {
                    IEnumerable <GherkinScenarioDefinition> SCS = from x in mGherkinScenarioDefinition where x.Name == v select x;
                    foreach (GherkinScenarioDefinition sc in SCS)
                    {
                        GherkinParserException PE = new GherkinParserException(sc.ScenarioDefintion.Location.Line, sc.ScenarioDefintion.Location.Column, "Duplicate Scenario Name: " + sc.Name);
                        mErrorsList.Add(PE);
                    }
                }
            }
            catch (CompositeParserException ex)
            {
                // we show the errors in the grid + mark in the textEditor
                GherkinTextEditor.BackgroundRenderer.Segments.Clear();
                foreach (ParserException PE in ex.Errors)
                {
                    mErrorsList.Add(new GherkinParserException(PE));
                    if (PE.Location.Line > GherkinTextEditor.textEditor.Document.LineCount)
                    {
                        continue;
                    }
                    var line = GherkinTextEditor.textEditor.Document.GetLineByNumber(PE.Location.Line);
                    GherkinTextEditor.BackgroundRenderer.Segments.Add(line);
                }
            }

            if (mErrorsList.Count > 0)
            {
                ShowErros(true);
                GherkinTextEditor.Focus();
            }
            else
            {
                GherkinTextEditor.BackgroundRenderer.Segments.Clear();
            }


            ARP.xActivitiesRepositoryGrid.Tags = mSolTags;
            SharedActivitiesFrame.Content      = ARP;

            foreach (GherkinStep gStep in mOptimizedSteps)
            {
            }

            OptimizedStepsGrid.DataSourceList = mOptimizedSteps;
            Mouse.OverrideCursor = null;
            List <GherkinParserException> Errors = mErrorsList.Where(x => x.ErrorType == GherkinParserException.eErrorType.Error).ToList();
            bool result = mOptimizedSteps.Count > 0 && Errors.Count == 0;

            return(result);
        }