Beispiel #1
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);
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="generationContext"></param>
 /// <param name="testMethod"></param>
 /// <param name="friendlyTestName"></param>
 public new void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName)
 {
     if (_dictTestCaseWarningAndErrors.ContainsKey(testMethod.Name))
     {
         SpecsWarningAndErrors testCaseWarningAndErrors = _dictTestCaseWarningAndErrors[testMethod.Name];
         AddWarningAndErrorStatement(testMethod, testCaseWarningAndErrors);
     }
     base.SetTestMethod(generationContext, testMethod, friendlyTestName);
 }
 private void AddWarningAndErrorStatement(CodeMemberMethod testMethod, SpecsWarningAndErrors testCaseWarningAndErrors)
 {
     testCaseWarningAndErrors.Errors.ForEach(x => testMethod.Statements.Add(new CodeSnippetStatement(CodeDomHelper.GetErrorStatementString($" ({x.Location.Line}:{x.Location.Column}): {x.Message}"))));
     if (testCaseWarningAndErrors.HavingWarnings)
     {
         testMethod.Statements.Add(CodeDomHelper.GetEnableWarningsPragma());
         testCaseWarningAndErrors.Warnings.ForEach(x => testMethod.Statements.Add(new CodeSnippetStatement($"#warning ({x.Location.Line}:{x.Location.Column}): {x.Message} ")));
         testMethod.Statements.Add(CodeDomHelper.GetDisableWarningsPragma());
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="generationContext"></param>
        public override void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
        {
            var feature = generationContext.Feature;

            if (null != feature)
            {
                SpecsWarningAndErrors testCaseWarningAndErrorsFeature = new SpecsWarningAndErrors();
                _funcValidator.FeatureValidator(feature, feature.Location, testCaseWarningAndErrorsFeature);
                AddWarningAndErrorStatement(generationContext.FeatureBackgroundMethod, testCaseWarningAndErrorsFeature);

                if (feature.Tags != null && feature.HasTags())
                {
                    SpecsWarningAndErrors testCaseWarningAndErrorsFeaturetags = new SpecsWarningAndErrors();
                    var properties = feature.Tags.Select(x => x.Name.TrimStart("@".ToCharArray())).ToArray();
                    _funcValidator.FeatureTagValidator(properties, feature.Location, testCaseWarningAndErrorsFeaturetags);
                    AddWarningAndErrorStatement(generationContext.FeatureBackgroundMethod, testCaseWarningAndErrorsFeaturetags);
                }

                if (null != feature.Background)
                {
                    SpecsWarningAndErrors testCaseWarningAndErrorsBackground = new SpecsWarningAndErrors();
                    _funcValidator.BackgroundValidator(feature.Background, feature.Background.Location, testCaseWarningAndErrorsBackground);
                    AddWarningAndErrorStatement(generationContext.FeatureBackgroundMethod, testCaseWarningAndErrorsBackground);
                }

                foreach (var featureScenarioDefinition in feature.ScenarioDefinitions)
                {
                    var scenario = featureScenarioDefinition;
                    SpecsWarningAndErrors testCaseWarningAndErrorsScenario = new SpecsWarningAndErrors();
                    _funcValidator.ScenarioValidator(featureScenarioDefinition, featureScenarioDefinition.Location, testCaseWarningAndErrorsScenario);
                    if (((IHasTags)scenario).Tags != null && scenario.HasTags())
                    {
                        var properties = scenario.GetTags().Select(x => x.Name.TrimStart("@".ToCharArray())).ToArray();
                        _funcValidator.ScenarioTagValidator(properties, scenario.Location, testCaseWarningAndErrorsScenario);
                    }
                    if (testCaseWarningAndErrorsScenario.HavingErrors || testCaseWarningAndErrorsScenario.HavingWarnings)
                    {
                        _dictTestCaseWarningAndErrors.Add(string.Format(TestNameFormat, scenario.Name.ToIdentifier()), testCaseWarningAndErrorsScenario);
                    }
                }
            }
            base.SetTestClassInitializeMethod(generationContext);
        }
Beispiel #5
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 #6
0
 /// <summary>
 /// Validator for scenario description
 /// </summary>
 /// <param name="scenarioDefinition"></param>
 /// <param name="location"></param>
 /// <param name="testCaseWarningAndErrors"></param>
 public void ScenarioValidator(ScenarioDefinition scenarioDefinition, Location location, SpecsWarningAndErrors testCaseWarningAndErrors)
 {
     ScenarioDefinitionValidator(scenarioDefinition, location, testCaseWarningAndErrors, RuleApplicableTo.Scenario);
 }
Beispiel #7
0
 public void FeatureValidator(SpecFlowFeature specFlowFeature, Location location, SpecsWarningAndErrors testCaseWarningAndErrors)
 {
 }
Beispiel #8
0
 /// <summary>
 /// Validator for scenario tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="location"></param>
 /// <param name="testCaseWarningAndErrors"></param>
 public void ScenarioTagValidator(IEnumerable <string> tags, Location location, SpecsWarningAndErrors testCaseWarningAndErrors)
 {
     TagsValidator(tags, location, testCaseWarningAndErrors, RuleApplicableTo.ScenarioTags);
 }