public static string[] GetDefaultTestCodeunitText(string elementValue)
        {
            string       newProcedureName = "NewTestProcedure";
            TestALMethod testalMethod     = new TestALMethod
            {
                MethodKind = ALMethodKind.Method,
                Name       = newProcedureName,
                Scenario   = new TestScenario {
                    ID = 1, Name = "New Test Procedure", Feature = new TestFeature {
                        Name = elementValue
                    }
                },
                TestMethod = true
            };

            testalMethod.Scenario.Feature.Scenarios.Add(testalMethod.Scenario);
            testalMethod.Attributes.Add(new ALAttribute {
                Name = "Test"
            });

            string         codeunitName   = elementValue.Contains(' ') ? '"' + elementValue + '"' : elementValue;
            TestALCodeunit testALCodeunit = new TestALCodeunit {
                Type = ALObjectParser.ALObjectType.codeunit, Id = 0, Name = codeunitName
            };

            testALCodeunit.Methods.Add(testalMethod);
            testALCodeunit.Features.Add(testalMethod.Scenario.Feature);
            testALCodeunit.Properties.Add(new ALProperty {
                Name = "Subtype", Value = "Test"
            });

            ALTestCodeunitWriter aLTestCodeunitWriter = new ALTestCodeunitWriter();

            return(aLTestCodeunitWriter.Write(testALCodeunit).Split("\r\n"));
        }
Пример #2
0
        private void InitializeSaveChanges(MessageUpdate msg, Configurations config, out TestALMethod testALMethod, out int scenarioLine, out int elementLine, bool elementOfNewValue, out List <string> fileContent, out ScenarioElementType scenarioElementType, out string oldProcedureNameOfElement, out string newProcedureNameOfElement)
        {
            string               scenarioName         = msg.Scenario;
            string               fsPath               = msg.FsPath;
            string               elementOldValue      = msg.OldValue;
            string               elementNewValue      = msg.NewValue;
            TypeChanged          typeChanged          = msg.Type;
            ALTestCodeunitReader alTestCodeunitReader = new ALTestCodeunitReader();
            TestALCodeunit       testCodeunit         = (TestALCodeunit)alTestCodeunitReader.ReadSingle(fsPath);

            testALMethod        = testCodeunit.Methods.First(m => (m.Scenario != null) && (m.Scenario.Name == scenarioName));
            scenarioElementType = Library.ALMethodHelper.ToEnum <ScenarioElementType>(typeChanged.ToString().ToUpper());

            if (elementOldValue == null)
            {
                oldProcedureNameOfElement = "";
            }
            else
            {
                oldProcedureNameOfElement = Library.ALMethodHelper.GetProcedurename(scenarioElementType, elementOldValue, config.prefixGiven, config.prefixWhen, config.prefixThen);
            }
            if (elementNewValue == null)
            {
                newProcedureNameOfElement = "";
            }
            else
            {
                newProcedureNameOfElement = Library.ALMethodHelper.GetProcedurename(scenarioElementType, elementNewValue, config.prefixGiven, config.prefixWhen, config.prefixThen);
            }

            fileContent  = File.ReadAllLines(fsPath).ToList();
            elementLine  = 0;
            scenarioLine = Library.Helpers.ALTestCodeunitHelper.FindScenarioLine(testALMethod.Scenario.Name, fileContent);
            if (scenarioLine == 0)
            {
                return;
            }

            if (elementOfNewValue)
            {
                elementLine = Library.Helpers.ALTestCodeunitHelper.FindElementLine(fileContent, scenarioElementType, elementNewValue, scenarioLine);
            }
            else
            {
                elementLine = Library.Helpers.ALTestCodeunitHelper.FindElementLine(fileContent, scenarioElementType, elementOldValue, scenarioLine);
            }
            if (elementLine == 0)
            {
                return;
            }
        }
        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);
        }