コード例 #1
0
        private IEnumerable <StepDef> GetStepDefinitionList(int stepDefinitionCount)
        {
            var result = new List <StepDef>();

            while (result.Count < stepDefinitionCount)
            {
                var paramList = new List <string>();
                var stepDef   = new StepDef
                {
                    Regex = string.Join(" ",
                                        LoremIpsum.GetWords(LoremIpsum.Rnd.Next(3) + 3).Select(s => ConvertToParam(s, ref paramList))),
                    DataTable = LoremIpsum.Rnd.Next(8) == 0,
                    DocString = LoremIpsum.Rnd.Next(16) == 0,
                    Keyword   = GetKeyword(result.Count)
                };
                stepDef.StepTextParams = paramList;

                var sampleText = GetStepText(stepDef, null);
                if (result.Where(sd => sd.Keyword == stepDef.Keyword).Any(sd => Regex.IsMatch(sampleText, "^" + sd.Regex + "$")))
                {
                    continue;
                }

                result.Add(stepDef);
            }
            return(result);
        }
コード例 #2
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);
        }
コード例 #3
0
 public void AddUnicodeSteps()
 {
     _unicodeStep = new StepDef()
     {
         Keyword        = "Given",
         Regex          = GeneratorOptions.UnicodeBindingRegex,
         StepTextParams = new List <string>()
     };
     if (stepDefinitions.ContainsKey("Given"))
     {
         stepDefinitions["Given"] = stepDefinitions["Given"].Concat(new[] { _unicodeStep }).ToArray();
     }
     else
     {
         stepDefinitions["Given"] = new[] { _unicodeStep }
     };
 }
コード例 #4
0
        public void AddAsyncStep()
        {
            var stepDef = new StepDef()
            {
                Keyword        = "When",
                Regex          = "there is an async step",
                StepTextParams = new List <string>(),
                Async          = true
            };

            if (stepDefinitions.ContainsKey("When"))
            {
                stepDefinitions["When"] = stepDefinitions["When"].Concat(new[] { stepDef }).ToArray();
            }
            else
            {
                stepDefinitions["When"] = new[] { stepDef }
            };
        }
    }
コード例 #5
0
 private string GetParams(StepDef stepDef)
 {
     return(string.Join(", ", stepDef.Params.Select((p, i) => $"{ParamTypes[p]} p{i}")));
 }