private string GetStepTitle(MethodInfo method, object testObject, RunStepWithArgsAttribute argAttribute, bool returnsItsText) { Func<string> stepTitleFromMethodName = () => GetStepTitleFromMethodName(method, argAttribute); if(returnsItsText) return GetStepTitleFromMethod(method, argAttribute, testObject) ?? stepTitleFromMethodName(); return stepTitleFromMethodName(); }
private string GetStepTitleFromMethodName(MethodInfo method, RunStepWithArgsAttribute argAttribute) { var methodName = _stepTextTransformer(NetToString.Convert(method.Name)); object[] inputs = null; if (argAttribute != null && argAttribute.InputArguments != null) inputs = argAttribute.InputArguments; if (inputs == null) return methodName; if (string.IsNullOrEmpty(argAttribute.StepTextTemplate)) { var stringFlatInputs = inputs.FlattenArrays().Select(i => i.ToString()).ToArray(); return methodName + " " + string.Join(", ", stringFlatInputs); } return string.Format(argAttribute.StepTextTemplate, inputs.FlattenArrays()); }
private ExecutionStep GetStep(object testObject, MethodNameMatcher matcher, MethodInfo method, bool returnsItsText, object[] inputs = null, RunStepWithArgsAttribute argAttribute = null) { var stepMethodName = GetStepTitle(method, testObject, argAttribute, returnsItsText); var stepAction = GetStepAction(method, inputs, returnsItsText); return new ExecutionStep(stepAction, stepMethodName, matcher.Asserts, matcher.ExecutionOrder, matcher.ShouldReport); }
private static string GetStepTitleFromMethod(MethodInfo method, RunStepWithArgsAttribute argAttribute, object testObject) { object[] inputs = null; if(argAttribute != null && argAttribute.InputArguments != null) inputs = argAttribute.InputArguments; var enumerableResult = InvokeIEnumerableMethod(method, testObject, inputs); try { return enumerableResult.FirstOrDefault(); } catch (Exception ex) { var message = string.Format( "The signature of method '{0}' indicates that it returns its step title; but the code is throwing an exception before a title is returned", method.Name); throw new StepTitleException(message, ex); } }