diff --git a/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs b/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs index 92e5f39..8539dee 100644 --- a/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs +++ b/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs @@ -176,49 +176,47 @@ private ExecutionOrder FixConsecutiveStep(ExecutionOrder executionOrder) private StepTitle CreateTitle(string stepTextTemplate, bool includeInputsInStepTitle, MethodInfo methodInfo, StepArgument[] inputArguments, string stepPrefix) { - Func createTitle = () => + string Title() + { + var autoFormatText = true; + 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; + autoFormatText = titleAttribute.AutoFormatStepText; + } - 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(autoFormatText ? Configurator.Scanners.Humanize(name) : name, stepPrefix); - 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(); - stepTitle = stepTitle + " " + string.Join(", ", stringFlatInputs); - } + 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(); + stepTitle = stepTitle + " " + string.Join(", ", stringFlatInputs); + } - return stepTitle.Trim(); - }; + return stepTitle.Trim(); + } - return new StepTitle(createTitle); + return new StepTitle(Title); } private static MethodInfo GetMethodInfo(LambdaExpression stepAction) diff --git a/src/TestStack.BDDfy/StepTitleAttribute.cs b/src/TestStack.BDDfy/StepTitleAttribute.cs index 2a81d96..252bb40 100644 --- a/src/TestStack.BDDfy/StepTitleAttribute.cs +++ b/src/TestStack.BDDfy/StepTitleAttribute.cs @@ -4,20 +4,18 @@ namespace TestStack.BDDfy { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class StepTitleAttribute : Attribute - { - public StepTitleAttribute(string stepTitle) - { - StepTitle = stepTitle; - } - - public StepTitleAttribute(string stepTitle, bool includeInputsInStepTitle) + { + public StepTitleAttribute(string stepTitle, bool includeInputsInStepTitle = false, bool autoFormatStepText = false) { IncludeInputsInStepTitle = includeInputsInStepTitle; StepTitle = stepTitle; + AutoFormatStepText = autoFormatStepText; } public string StepTitle { get; private set; } public bool? IncludeInputsInStepTitle { get; private set; } + + public bool AutoFormatStepText { get; } } } \ No newline at end of file