public StepDescription Describe(StepDefinition stepDefinition)
        {
            var matcher = (RegexMatcher) stepDefinition.Matcher;
            try
            {
                var pieces = Split(matcher.Pattern);

                List<StepSpan> spans = new List<StepSpan>();

                int currentParam = 0;
                foreach (var piece in pieces)
                {
                    if (piece.StartsWith("("))
                    {
                        var param = ((MethodInfo)matcher.MemberInfo).GetParameters().ElementAt(currentParam);
                        spans.Add(new ParameterSpan(param.ParameterType, param.Name));
                        currentParam++;
                    }
                    else
                    {
                        spans.Add(new TextSpan(piece));
                    }
                }

                return new StepDescription {Spans = spans};
            }
            catch(Exception ex)
            {
                DebugTrace.Trace(this, "Error occurred describing Regex: " + ex);
                return new StepDescription {Spans = new StepSpan[] {new TextSpan(matcher.Pattern)}};
            }
        }
示例#2
0
        public void can_describe_a_step_with_multiple_levels_of_children()
        {
            var grandchildStep = new StepDefinition
            {
                DeclaringType = typeof(ExampleGrandChildContext),
                Matcher       = new MethodNameMatcher(typeof(ExampleGrandChildContext).GetMethod("Baz"))
            };

            var childStep = new StepDefinition
            {
                Children      = new[] { grandchildStep },
                DeclaringType = typeof(ExampleChildContext),
                Matcher       = new MethodNameMatcher(typeof(ExampleChildContext).GetMethod("Bar"))
            };

            var step = new StepDefinition
            {
                Children      = new[] { childStep },
                DeclaringType = typeof(ExampleParentContext),
                Matcher       = new MethodNameMatcher(typeof(ExampleParentContext).GetMethod("Foo"))
            };

            var result = new StepDescriber().Describe(step);

            result.Description.ShouldEqual("Foo");
            result.ChildDescription.ShouldEqual("    Bar\r\n        Baz");
        }
示例#3
0
        private StepDescription Describe(IMemberMatcher matcher)
        {
            var def = new StepDefinition {
                DeclaringType = typeof(ExampleContext), Matcher = matcher
            };

            return(new StepDescriber().Describe(def));
        }
示例#4
0
        private StepDefinition BuildStepDefinition(Type type, IMemberMatcher memberMatcher, int levels)
        {
            var stepDefinition = new StepDefinition { DeclaringType = type, Matcher = memberMatcher };

            if (levels > 0 && memberMatcher.ReturnType != null && memberMatcher.ReturnType != typeof (void))
                stepDefinition.Children = GetStepsForType(memberMatcher.ReturnType, levels - 1, x=>true);
            else
                stepDefinition.Children = new StepDefinition[0];

            return stepDefinition;
        }
示例#5
0
        public void sends_step_defs_to_formatter()
        {
            var definition1 = new StepDefinition();
            var definition2 = new StepDefinition();

            StepProviderReturns(definition1, definition2);
            _fakeStepDescriber.Stub(x => x.Describe(Arg<StepDefinition>.Is.Anything)).Return(new StepDescription());
            Job.Run();

            _fakeStepDescriber.AssertWasCalled(x => x.Describe(definition1));
            _fakeStepDescriber.AssertWasCalled(x => x.Describe(definition2));
        }
示例#6
0
        public void sends_step_defs_to_formatter()
        {
            var definition1 = new StepDefinition();
            var definition2 = new StepDefinition();

            StepProviderReturns(definition1, definition2);
            _fakeStepDescriber.Stub(x => x.Describe(Arg<StepDefinition>.Is.Anything)).Return(new StepDescription());
            Job.Run();

            _fakeStepDescriber.AssertWasCalled(x => x.Describe(definition1));
            _fakeStepDescriber.AssertWasCalled(x => x.Describe(definition2));
        }
        private StepViewModel BuildViewModelStep(StepDefinition stepDefinition)
        {
            var describer = new StepDescriber();

            return new StepViewModel
                       {
                           TypeName = stepDefinition.DeclaringType.FullName,
                           MemberName = stepDefinition.Matcher.MemberInfo.Name,
                           Description = describer.Describe(stepDefinition),
                           IsExtensionMethod = IsExtensionMethod(stepDefinition.Matcher.MemberInfo),
                           Children = stepDefinition.Children.Select(BuildViewModelStep)
                       };
        }
示例#8
0
        private StepViewModel BuildViewModelStep(StepDefinition stepDefinition)
        {
            var describer = new StepDescriber();

            return(new StepViewModel
            {
                TypeName = stepDefinition.DeclaringType.FullName,
                MemberName = stepDefinition.Matcher.MemberInfo.Name,
                Description = describer.Describe(stepDefinition),
                IsExtensionMethod = IsExtensionMethod(stepDefinition.Matcher.MemberInfo),
                Children = stepDefinition.Children.Select(BuildViewModelStep)
            });
        }
 public StepDescription Describe(StepDefinition stepDefinition)
 {
     var matcher = (PropertyOrFieldNameMatcher)stepDefinition.Matcher;
     return  _wordFilterDescriber.Describe(matcher.WordFilters);
 }
        public StepDescription Describe(StepDefinition stepDefinition)
        {
            var methodNameMatcher = (MethodNameMatcher) stepDefinition.Matcher;

            return _wordFilterDescriber.Describe(methodNameMatcher.WordFilters);
        }
示例#11
0
 private StepDescription Describe(IMemberMatcher matcher)
 {
     var def = new StepDefinition { DeclaringType = typeof(ExampleContext), Matcher = matcher };
     return new StepDescriber().Describe(def);
 }
示例#12
0
        public void can_describe_a_step_with_multiple_levels_of_children()
        {
            var grandchildStep = new StepDefinition
                                     {
                                         DeclaringType = typeof(ExampleGrandChildContext),
                                         Matcher = new MethodNameMatcher(typeof(ExampleGrandChildContext).GetMethod("Baz"))
                                     };

            var childStep = new StepDefinition
                                {
                                    Children = new[] { grandchildStep },
                                    DeclaringType = typeof(ExampleChildContext),
                                    Matcher = new MethodNameMatcher(typeof(ExampleChildContext).GetMethod("Bar"))
                                };

            var step = new StepDefinition
                           {
                               Children = new[] { childStep },
                               DeclaringType = typeof(ExampleParentContext),
                               Matcher = new MethodNameMatcher(typeof(ExampleParentContext).GetMethod("Foo"))
                           };

            var result = new StepDescriber().Describe(step);
            result.Description.ShouldEqual("Foo");
            result.ChildDescription.ShouldEqual("    Bar\r\n        Baz");
        }
示例#13
0
 public StepDefinition()
 {
     Children = new StepDefinition[0];
 }
示例#14
0
 public StepDefinition()
 {
     Children = new StepDefinition[0];
 }