Ejemplo n.º 1
0
        public static string WriteMethod(this ITestScenarioElement element, ALParserConfig config = null)
        {
            var prefix = "";

            switch (element.Type)
            {
            case ScenarioElementType.GIVEN:
                prefix = config != null ? config.GivenFunctionPrefix : "Create";
                break;

            case
                ScenarioElementType.WHEN:
                prefix = config != null ? config.WhenFunctionPrefix : "Assign";
                break;

            case ScenarioElementType.THEN:
                prefix = config != null ? config.ThenFunctionPrefix : "Verify";
                break;

            default:
                break;
            }

            return($"{prefix}{element.Value.SanitizeName()}");
        }
        public static int FindLineToInsertElement(TestALMethod testALMethod, List <string> fileContent, int scenarioLine, ScenarioElementType elementToAdd)
        {
            int lineToInsert = 0;
            IEnumerable <ITestScenarioElement> elementsOfType = testALMethod.Scenario.Elements.Where(e => e.Type == elementToAdd);

            if (elementsOfType.Count() == 0)
            {
                if (elementToAdd == ScenarioElementType.GIVEN)
                {
                    IEnumerable <ITestScenarioElement> otherElements = testALMethod.Scenario.Elements.Where(e => e.Type == ScenarioElementType.WHEN || e.Type == ScenarioElementType.THEN);
                    if (otherElements.Count() > 0)
                    {
                        ITestScenarioElement element = otherElements.First();
                        for (int lineNo = scenarioLine; lineNo < fileContent.Count; lineNo++)
                        {
                            if (fileContent[lineNo].Trim() == element.LineText.Trim())
                            {
                                return(lineNo);
                            }
                            if (Regex.IsMatch(fileContent[lineNo], @"\s{4}end;", RegexOptions.IgnoreCase))
                            {
                                return(lineNo);
                            }
                        }
                    }
                }
                if (elementToAdd == ScenarioElementType.WHEN)
                {
                    return(FindLineToInsertElement(testALMethod, fileContent, scenarioLine, ScenarioElementType.GIVEN));
                }
                if (elementToAdd == ScenarioElementType.THEN)
                {
                    return(FindLineToInsertElement(testALMethod, fileContent, scenarioLine, ScenarioElementType.WHEN));
                }
            }
            else
            {
                int countElementsOfType = elementsOfType.Count();
                int lineNo = scenarioLine;
                for (; lineNo < fileContent.Count && countElementsOfType > 0; lineNo++)
                {
                    if (Regex.IsMatch(fileContent[lineNo], @"\s+//\s*\[\s*" + elementToAdd.ToString() + @"\s*\].*", RegexOptions.IgnoreCase))
                    {
                        countElementsOfType--;
                    }
                }

                for (; lineNo < fileContent.Count; lineNo++)
                {
                    if (fileContent[lineNo].Trim() == "" || Regex.IsMatch(fileContent[lineNo], @"\s+//\s*\[[^]]*\].*") || Regex.IsMatch(fileContent[lineNo], @"\s{4}end;", RegexOptions.IgnoreCase))
                    {
                        lineToInsert = lineNo;
                        break;
                    }
                }
            }

            return(lineToInsert);
        }
        public static void DeleteElementWithProcedureCall(ref List <string> fileContent, string procedureNameOfElement, int elementLine)
        {
            TestALCodeunit       codeunit        = (TestALCodeunit) new ALTestCodeunitReader().Read(fileContent);
            TestALMethod         method          = ALTestCodeunitHelper.GetMethodAtLine(codeunit, elementLine);
            string               commentLineText = fileContent[elementLine];
            ITestScenarioElement element         = method.Scenario.Elements.First(element => element.LineText.Trim() == commentLineText.Trim());
            int deleteRange = 1;

            for (int line = elementLine + 1; line < fileContent.Count; line++)
            {
                if (Regex.IsMatch(fileContent[line], @"\s*//\s*\[.+\].*"))
                {
                    deleteRange = line - elementLine;
                    break;
                }
                if (Regex.IsMatch(fileContent[line], "^    end;", RegexOptions.IgnoreCase))
                {
                    deleteRange = line - elementLine;
                    break;
                }
            }

            fileContent.RemoveRange(elementLine, deleteRange);
        }
 public static string Write(this ITestScenarioElement element)
 {
     return(WriteIndentedText($"// [{element.Type}] {element.Value}", 2));
 }
Ejemplo n.º 5
0
 public static string Write(this ITestScenarioElement element)
 {
     return($"// [{element.Type}] {element.Value}");
 }