コード例 #1
0
        private static ScenarioStepPattern GetMatchingPattern(StepMethodInfo stepMethod, Step gherkinScenarioStep)
        {
            var gherkinStepText = gherkinScenarioStep.Text.Trim();
            var gherkinKeyword  = gherkinScenarioStep.Keyword.Trim();

            if (gherkinKeyword == "*")
            {
                gherkinKeyword = "Star";
            }

            foreach (var pattern in stepMethod.ScenarioStepPatterns)
            {
                if (!pattern.Kind.ToString().Equals(gherkinKeyword, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var match = Regex.Match(gherkinStepText, pattern.Pattern);
                if (!match.Success || !match.Value.Equals(gherkinStepText))
                {
                    continue;
                }

                return(pattern);
            }

            return(null);
        }
コード例 #2
0
        public StepMethod(StepMethodInfo stepMethodInfo, string stepText)
        {
            _stepMethodInfo = stepMethodInfo ?? throw new ArgumentNullException(nameof(stepMethodInfo));
            StepText        = !string.IsNullOrWhiteSpace(stepText)
                ? stepText
                : throw new ArgumentNullException(nameof(stepText));

            Kind = stepMethodInfo.Kind;
        }
コード例 #3
0
        public bool IsSameAs(StepMethodInfo other)
        {
            if (other == this)
            {
                return(true);
            }

            return(other != null &&
                   other._methodInfoWrapper.IsSameAs(_methodInfoWrapper));
        }
コード例 #4
0
        private StepMethod(StepMethodInfo stepMethodInfo, PatternKind kind, string pattern, string stepText)
        {
            _stepMethodInfo = stepMethodInfo ?? throw new ArgumentNullException(nameof(stepMethodInfo));
            Kind            = kind;
            Pattern         = !string.IsNullOrWhiteSpace(pattern) ? pattern : throw new ArgumentNullException(nameof(pattern));

            StepText = !string.IsNullOrWhiteSpace(stepText)
                ? stepText
                : throw new ArgumentNullException(nameof(stepText));
        }
コード例 #5
0
        public bool IsSameAs(StepMethodInfo other)
        {
            if (other == this)
            {
                return(true);
            }

            return(other != null &&
                   other.Kind == Kind &&
                   other.Pattern == Pattern &&
                   ArgumentsEqual(other._arguments, _arguments) &&
                   other._methodInfoWrapper.IsSameAs(_methodInfoWrapper));
        }
コード例 #6
0
        public static StepMethod FromStepMethodInfo(StepMethodInfo stepMethodInfo, Step gherkinScenarioStep)
        {
            var matchingPattern = stepMethodInfo.GetMatchingPattern(gherkinScenarioStep);

            if (matchingPattern == null)
            {
                throw new InvalidOperationException($"This step method info (`{stepMethodInfo.GetMethodName()}`) cannot handle given scenario step: `{gherkinScenarioStep.Keyword.Trim()} {gherkinScenarioStep.Text.Trim()}`.");
            }

            var stepMethodInfoClone = stepMethodInfo.Clone();

            stepMethodInfoClone.DigestScenarioStepValues(gherkinScenarioStep);
            return(new StepMethod(stepMethodInfoClone, matchingPattern.Kind, matchingPattern.Pattern, gherkinScenarioStep.Text));
        }
コード例 #7
0
        public static FeatureClass FromFeatureInstance(Feature featureInstance)
        {
            if (featureInstance == null)
            {
                throw new ArgumentNullException(nameof(featureInstance));
            }

            Type featureType     = featureInstance.GetType();
            var  featureFilePath = FeatureClassInfo.FromFeatureClassType(featureType).FeatureFilePath;

            var stepMethods = featureType.GetTypeInfo().GetMethods()
                              .Where(m => m.IsDefined(typeof(BaseStepDefinitionAttribute)))
                              .Select(m => StepMethodInfo.FromMethodInfo(m, featureInstance))
                              .ToList();

            return(new FeatureClass(featureFilePath, stepMethods));
        }
コード例 #8
0
        public static FeatureClass FromFeatureInstance(Feature featureInstance)
        {
            if (featureInstance == null)
            {
                throw new ArgumentNullException(nameof(featureInstance));
            }

            Type featureType = featureInstance.GetType();

            var featureFileAttribute = featureType
                                       .GetTypeInfo()
                                       .GetCustomAttribute <FeatureFileAttribute>();
            var featureFilePath = featureFileAttribute?.Path ?? $"{featureType.Name}.feature";

            var stepMethods = featureType.GetTypeInfo().GetMethods()
                              .Where(m => m.IsDefined(typeof(BaseStepDefinitionAttribute)))
                              .Select(m => StepMethodInfo.FromMethodInfo(m, featureInstance))
                              .ToList();

            return(new FeatureClass(featureFilePath, stepMethods)
            {
                _instance = featureInstance,
            });
        }