예제 #1
0
        private StepTitle CreateTitle(string stepTextTemplate, bool includeInputsInStepTitle, MethodInfo methodInfo, StepArgument[] inputArguments, string stepPrefix)
        {
            Func <string> createTitle = () =>
            {
                var flatInputArray     = inputArguments.Select(o => o.Value).FlattenArrays();
                var name               = methodInfo.Name;
                var stepTitleAttribute = methodInfo.GetCustomAttributes(typeof(StepTitleAttribute), true).SingleOrDefault();
                if (stepTitleAttribute != null)
                {
                    var titleAttribute = ((StepTitleAttribute)stepTitleAttribute);
                    name = string.Format(titleAttribute.StepTitle, flatInputArray);
                    if (titleAttribute.IncludeInputsInStepTitle != null)
                    {
                        includeInputsInStepTitle = titleAttribute.IncludeInputsInStepTitle.Value;
                    }
                }

                var stepTitle = AppendPrefix(Configurator.Scanners.Humanize(name), stepPrefix);

                if (!string.IsNullOrEmpty(stepTextTemplate))
                {
                    stepTitle = string.Format(stepTextTemplate, flatInputArray);
                }
                else if (includeInputsInStepTitle)
                {
                    var parameters       = methodInfo.GetParameters();
                    var stringFlatInputs =
                        inputArguments
                        .Select((a, i) => new { ParameterName = parameters[i].Name, Value = a })
                        .Select(i =>
                    {
                        if (_testContext.Examples != null)
                        {
                            var matchingHeader = _testContext.Examples.Headers
                                                 .SingleOrDefault(header => ExampleTable.HeaderMatches(header, i.ParameterName) ||
                                                                  ExampleTable.HeaderMatches(header, i.Value.Name));
                            if (matchingHeader != null)
                            {
                                return(string.Format("<{0}>", matchingHeader));
                            }
                        }
                        return(i.Value.Value.FlattenArray());
                    })
                        .ToArray();
                    string[] strings = stringFlatInputs.Select(x => x.ToString()).Where(x => x != null).ToArray();
                    stepTitle = stepTitle + " " + string.Join(", ", strings);
                }

                return(stepTitle.Trim());
            };

            return(new StepTitle(createTitle));
        }
예제 #2
0
        public static ExampleTable Parse(string table)
        {
            var lines    = table.Trim().Split('\n').Select(l => l.Trim().Trim('|')).ToArray();
            var firstRow = lines.First();
            var headers  = firstRow.Split('|').Select(h => h.Trim()).ToArray();

            var exampleTable = new ExampleTable(headers);

            foreach (var line in lines.Skip(1))
            {
                exampleTable.Add(GetValues(line));
            }

            return(exampleTable);
        }
예제 #3
0
 public bool MatchesName(string name)
 {
     return(ExampleTable.HeaderMatches(Header, name));
 }