Beispiel #1
0
        /// <summary>
        /// Validator for scenario definition
        /// </summary>
        /// <param name="scenarioDefinition"></param>
        /// <param name="location"></param>
        /// <param name="testCaseWarningAndErrors"></param>
        /// <param name="ruleApplicabeTo"></param>
        private void ScenarioDefinitionValidator(ScenarioDefinition scenarioDefinition, Location location, SpecsWarningAndErrors testCaseWarningAndErrors, RuleApplicableTo ruleApplicabeTo)
        {
            var backgroundRules = _specValidationConfiguration.Rules.Cast <Rule>().Where(x => x.ApplyTo == ruleApplicabeTo);
            var enumerableRules = backgroundRules as IList <Rule> ?? backgroundRules.ToList();

            if (enumerableRules.Any())
            {
                var           lstSteps = scenarioDefinition.Steps.ToList();
                StringBuilder steps    = new StringBuilder();
                foreach (var step in lstSteps)
                {
                    steps.Append(step.Text);
                    steps.Append(Environment.NewLine);
                }
                foreach (var backgroundRule in enumerableRules)
                {
                    var matches = Regex.Match(steps.ToString(), backgroundRule.RegEx, RegexOptions.IgnoreCase);

                    if (!matches.Success)
                    {
                        MessageDetails messagedetails = new MessageDetails()
                        {
                            Message = backgroundRule.Message, Location = location
                        };
                        if (backgroundRule.IsError)
                        {
                            testCaseWarningAndErrors.Errors.Add(messagedetails);
                        }
                        else
                        {
                            testCaseWarningAndErrors.Warnings.Add(messagedetails);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Validator for tags
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="location"></param>
        /// <param name="testCaseWarningAndErrors"></param>
        /// <param name="ruleApplicabeTo"></param>
        private void TagsValidator(IEnumerable <string> tags, Location location, SpecsWarningAndErrors testCaseWarningAndErrors, RuleApplicableTo ruleApplicabeTo)
        {
            var backgroundRules = _specValidationConfiguration.Rules.Cast <Rule>().Where(x => x.ApplyTo == ruleApplicabeTo);
            var enumerableRules = backgroundRules as IList <Rule> ?? backgroundRules.ToList();

            if (enumerableRules.Any())
            {
                var propertiesList = tags as IList <string> ?? tags.ToList();
                if (propertiesList.Any())
                {
                    foreach (var backgroundRule in enumerableRules)
                    {
                        var matches = propertiesList
                                      .Select(p => Regex.Match(p, backgroundRule.RegEx, RegexOptions.IgnoreCase))
                                      .Where(m => m.Success);
                        var matchList = matches as IList <Match> ?? matches.ToList();
                        if (!matchList.Any())
                        {
                            MessageDetails messagedetails = new MessageDetails()
                            {
                                Message = backgroundRule.Message, Location = location
                            };
                            if (backgroundRule.IsError)
                            {
                                testCaseWarningAndErrors.Errors.Add(messagedetails);
                            }
                            else
                            {
                                testCaseWarningAndErrors.Warnings.Add(messagedetails);
                            }
                        }
                    }
                }
            }
        }