예제 #1
0
        private void AddStep(StringBuilder content, string keyword, string keywordType = null, string[] soHeaders = null)
        {
            StepCount++;

            keywordType = keywordType ?? keyword;
            if (!stepDefinitions.TryGetValue(keywordType, out var sdList))
            {
                throw new Exception("keyword not found: " + keywordType);
            }
            var stepDef = sdList[LoremIpsum.Rnd.Next(sdList.Length)];

            content.AppendLine($"  {keyword} {GetStepText(stepDef, soHeaders)}");
            if (stepDef.DataTable)
            {
                int cellCount = LoremIpsum.Rnd.Next(4) + 2;
                AppendTable(content, cellCount);
            }
            else if (stepDef.DocString)
            {
                content.AppendLine($"    \"\"\"");
                content.AppendLine($"    {LoremIpsum.GetShortText(5)}");
                content.AppendLine($"    {LoremIpsum.GetShortText(4)}");
                content.AppendLine($"    {LoremIpsum.GetShortText(6)}");
                content.AppendLine($"    {LoremIpsum.GetShortText(5)}");
                content.AppendLine($"    \"\"\"");
            }
        }
예제 #2
0
        public string GenerateFeatureFileContent(int scenarioCount, int scenarioOutlineCount = 0, string featureTitle = null)
        {
            var content = new StringBuilder();

            content.AppendLine($"Feature: {featureTitle ?? ToTitle(LoremIpsum.GetShortText())}");
            content.AppendLine();
            content.AppendLine(LoremIpsum.GetShortText());
            content.AppendLine(LoremIpsum.GetShortText());
            content.AppendLine();

            var scenarioDefs = LoremIpsum.Randomize(
                Enumerable.Range(0, scenarioCount).Select(i => "S")
                .Concat(Enumerable.Range(0, scenarioOutlineCount).Select(i => "O")));

            for (int i = 0; i < scenarioDefs.Length; i++)
            {
                if (scenarioDefs[i] == "S")
                {
                    GenerateScenario(content);
                }
                else
                {
                    GenerateScenarioOutline(content);
                }
            }

            return(content.ToString());
        }
예제 #3
0
        private string GenerateStepDefClass(string folder, IEnumerable <StepDef> stepDefs)
        {
            var className = ToPascalCase(LoremIpsum.GetShortText()) + "Steps";
            var filePath  = Path.Combine(folder, className + ".cs");

            File.WriteAllText(filePath, GenerateStepDefClassContent(stepDefs, className));
            return(filePath);
        }
예제 #4
0
        private void GenerateScenario(StringBuilder content)
        {
            content.AppendLine(LoremIpsum.GetShortText(LoremIpsum.Rnd.Next(3), "@"));
            content.AppendLine($"Scenario: {ToTitle(LoremIpsum.GetShortText())}");

            AddSteps(content);
            content.AppendLine();
        }
예제 #5
0
        public string GenerateFeatureFile(string folder, int scenarioCount, int scenarioOutlineCount = 0)
        {
            var featureTitle = ToTitle(LoremIpsum.GetShortText());
            var fileName     = $"{ToPascalCase(featureTitle)}.feature";
            var filePath     = Path.Combine(folder, fileName);

            File.WriteAllText(filePath, GenerateFeatureFileContent(scenarioCount, scenarioOutlineCount, featureTitle));
            return(filePath);
        }
예제 #6
0
        private void GenerateScenarioOutline(StringBuilder content)
        {
            var headers = LoremIpsum.GetUniqueWords(3);

            content.AppendLine(LoremIpsum.GetShortText(LoremIpsum.Rnd.Next(3), "@"));
            content.AppendLine($"Scenario Outline: {ToTitle(LoremIpsum.GetShortText())}");
            AddSteps(content, headers);
            content.AppendLine($"Examples: {ToTitle(LoremIpsum.GetShortText())}");
            AppendTable(content, 3, headers);
            content.AppendLine();
        }
예제 #7
0
        private string GenerateStepDefClassContent(IEnumerable <StepDef> stepDefs, string className)
        {
            var content = new StringBuilder();

            content.AppendLine("using System;");
            content.AppendLine("using TechTalk.SpecFlow;");
            content.AppendLine("namespace DeveroomSample.StepDefinitions");
            content.AppendLine("{");
            content.AppendLine("    [Binding]");
            content.AppendLine($"    public class {className}");
            content.AppendLine("    {");

            foreach (var stepDef in stepDefs)
            {
                var asyncPrefix = stepDef.Async ? "async " : "";
                content.AppendLine($"        [{stepDef.Keyword}(@\"{stepDef.Regex.Replace("\"", "\"\"")}\")]");
                content.AppendLine($"        public {asyncPrefix}void {stepDef.Keyword}{ToPascalCase(LoremIpsum.GetShortText())}({GetParams(stepDef)})");
                content.AppendLine("        {");
                content.AppendLine($"           AutomationStub.DoStep({string.Join(", ", stepDef.Params.Select((p, i) => $"p{i}"))});");
                if (stepDef.Async)
                {
                    content.AppendLine($"           await System.Threading.Tasks.Task.Delay(200);");
                }
                content.AppendLine("        }");
                content.AppendLine();
            }

            content.AppendLine("    }");
            content.AppendLine("}");
            return(content.ToString());
        }
예제 #8
0
        private string GetStepText(StepDef stepDef, string[] soHeaders)
        {
            var result = stepDef.Regex;

            result = result.Replace(NumberPattern, LoremIpsum.Rnd.Next(2009).ToString());
            result = Regex.Replace(result, Regex.Escape(StringPattern), me => "\"" + GetSOPlaceHolder(soHeaders, LoremIpsum.GetShortText(LoremIpsum.Rnd.Next(5) + 1)) + "\"");
            //result = result.Replace(StringPattern, "\"" + GetSOPlaceHolder(soHeaders, LoremIpsum.GetShortText(LoremIpsum.Rnd.Next(5) + 1)) + "\"");
            return(result);
        }