Example #1
0
        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 ExecutionStep(o => action((TScenario)o), stepTitle, asserts, executionOrder, reports));
        }
        public void ReportsIllegalExampleStepNames(string stepName, string expectedStepTitle)
        {
            var exception = Record.Exception(() => {
                NetToString.Convert(stepName).ShouldBe(expectedStepTitle, Case.Sensitive);
            });

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
        }
        public void ReportsIllegalExampleStepNames(string stepName, string expectedStepTitle)
        {
            var exception = Record.Exception(() => {
                NetToString.Convert(stepName).ShouldBe(expectedStepTitle);
            });

            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <ArgumentException>();
        }
Example #4
0
        public IEnumerable <ExecutionStep> 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 ExecutionStep(GetStepAction(candidateMethod), 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 ExecutionStep(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()));
        }
 public void CanDealWithExampleStepNames(string stepName, string expectedStepTitle)
 {
     NetToString.Convert(stepName).ShouldBe(expectedStepTitle, Case.Sensitive);
 }
Example #8
0
 static string GetScenarioText(Type scenarioType)
 {
     return(NetToString.Convert(scenarioType.Name));
 }