private void AddStep(Expression <Action <TScenario> > stepAction, string stepTextTemplate, bool asserts, ExecutionOrder executionOrder, bool reports = true, bool includeInputsInStepTitle = true)
        {
            var methodInfo     = GetMethodInfo(stepAction);
            var inputArguments = new object[0];

            if (includeInputsInStepTitle)
            {
                inputArguments = stepAction.ExtractConstants().ToArray();
            }

            var flatInputArray = inputArguments.FlattenArrays();
            var stepTitle      = NetToString.Convert(methodInfo.Name);

            if (!string.IsNullOrEmpty(stepTextTemplate))
            {
                stepTitle = string.Format(stepTextTemplate, flatInputArray);
            }
            else if (includeInputsInStepTitle)
            {
                var stringFlatInputs = flatInputArray.Select(i => i.ToString()).ToArray();
                stepTitle = stepTitle + " " + string.Join(", ", stringFlatInputs);
            }

            stepTitle = stepTitle.Trim();
            var action = stepAction.Compile();

            _steps.Add(new Step(StepActionFactory.GetStepAction(action), stepTitle, asserts, executionOrder, reports));
        }
        public StoryMetadata(Type storyType, string narrative1, string narrative2, string narrative3, string storyTitle = null)
        {
            Title = storyTitle ?? NetToString.Convert(storyType.Name);
            Type  = storyType;

            Narrative1 = narrative1;
            Narrative2 = narrative2;
            Narrative3 = narrative3;
        }
        public IEnumerable <Step> Scan(object testObject, MethodInfo candidateMethod)
        {
            var executableAttribute = (ExecutableAttribute)candidateMethod.GetCustomAttributes(typeof(ExecutableAttribute), false).FirstOrDefault();

            if (executableAttribute == null)
            {
                yield break;
            }

            string stepTitle = executableAttribute.StepTitle;

            if (string.IsNullOrEmpty(stepTitle))
            {
                stepTitle = NetToString.Convert(candidateMethod.Name);
            }

            var stepAsserts = IsAssertingByAttribute(candidateMethod);

            var runStepWithArgsAttributes = (RunStepWithArgsAttribute[])candidateMethod.GetCustomAttributes(typeof(RunStepWithArgsAttribute), false);

            if (runStepWithArgsAttributes.Length == 0)
            {
                yield return
                    (new Step(StepActionFactory.GetStepAction(candidateMethod, new object[0]), stepTitle, stepAsserts, executableAttribute.ExecutionOrder, true)
                {
                    ExecutionSubOrder = executableAttribute.Order
                });
            }

            foreach (var runStepWithArgsAttribute in runStepWithArgsAttributes)
            {
                var inputArguments   = runStepWithArgsAttribute.InputArguments;
                var flatInput        = inputArguments.FlattenArrays();
                var stringFlatInputs = flatInput.Select(i => i.ToString()).ToArray();
                var methodName       = stepTitle + " " + string.Join(", ", stringFlatInputs);

                if (!string.IsNullOrEmpty(runStepWithArgsAttribute.StepTextTemplate))
                {
                    methodName = string.Format(runStepWithArgsAttribute.StepTextTemplate, flatInput);
                }
                else if (!string.IsNullOrEmpty(executableAttribute.StepTitle))
                {
                    methodName = string.Format(executableAttribute.StepTitle, flatInput);
                }

                yield return
                    (new Step(StepActionFactory.GetStepAction(candidateMethod, inputArguments), methodName, stepAsserts,
                              executableAttribute.ExecutionOrder, true)
                {
                    ExecutionSubOrder = executableAttribute.Order
                });
            }
        }
        internal static string GetTitleFromMethodNameInStackTrace(object testObject)
        {
            var trace  = new StackTrace();
            var frames = trace.GetFrames();

            if (frames == null)
            {
                return(null);
            }

            var initiatingFrame = frames.LastOrDefault(s => s.GetMethod().DeclaringType == testObject.GetType());

            if (initiatingFrame == null)
            {
                return(null);
            }

            return(NetToString.Convert(initiatingFrame.GetMethod().Name));
        }
        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()));
        }
Beispiel #6
0
 static string GetScenarioText(Type scenarioType)
 {
     return(NetToString.Convert(scenarioType.Name));
 }