public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo method, Example example) { var executableAttribute = (ExecutableAttribute)method.GetCustomAttributes(typeof(ExecutableAttribute), false).FirstOrDefault(); if (executableAttribute == null) yield break; string stepTitle = executableAttribute.StepTitle; if (string.IsNullOrEmpty(stepTitle)) stepTitle = Configurator.Scanners.Humanize(method.Name); var stepAsserts = IsAssertingByAttribute(method); var methodParameters = method.GetParameters(); var inputs = new List<object>(); var inputPlaceholders = Regex.Matches(stepTitle, " <(\\w+)> "); for (int i = 0; i < inputPlaceholders.Count; i++) { var placeholder = inputPlaceholders[i].Groups[1].Value; for (int j = 0; j < example.Headers.Length; j++) { if (example.Values.ElementAt(j).MatchesName(placeholder)) { inputs.Add(example.GetValueOf(j, methodParameters[inputs.Count].ParameterType)); break; } } } var stepAction = StepActionFactory.GetStepAction(method, inputs.ToArray()); yield return new Step(stepAction, new StepTitle(stepTitle), stepAsserts, executableAttribute.ExecutionOrder, true, new List<StepArgument>()); }
public Scenario(string id, object testObject, List<Step> steps, string scenarioText, Example example, List<string> tags) { Id = id; TestObject = testObject; Steps = steps; Title = scenarioText; Example = example; Tags = tags; }
public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo method, Example example) { foreach (var matcher in _matchers) { if (!matcher.IsMethodOfInterest(method.Name)) continue; var returnsItsText = method.ReturnType == typeof(IEnumerable<string>); yield return GetStep(testContext.TestObject, matcher, method, returnsItsText, example); } }
protected virtual IEnumerable<Step> ScanScenarioForSteps(ITestContext testContext, Example example) { var allSteps = new List<Step>(); var scenarioType = testContext.TestObject.GetType(); foreach (var methodInfo in GetMethodsOfInterest(scenarioType)) { // chain of responsibility of step scanners foreach (var scanner in _stepScanners) { var steps = scanner.Scan(testContext, methodInfo, example); if (steps.Any()) { allSteps.AddRange(steps); break; } } } return allSteps; }
private Step GetStep(object testObject, MethodNameMatcher matcher, MethodInfo method, bool returnsItsText, Example example) { var stepMethodName = GetStepTitleFromMethodName(method, null); var methodParameters = method.GetParameters(); var inputs = new object[methodParameters.Length]; for (var parameterIndex = 0; parameterIndex < inputs.Length; parameterIndex++) { for (var exampleIndex = 0; exampleIndex < example.Headers.Length; exampleIndex++) { var methodParameter = methodParameters[parameterIndex]; var parameterName = methodParameter.Name; var placeholderMatchesExampleColumn = example.Values.ElementAt(exampleIndex).MatchesName(parameterName); if (placeholderMatchesExampleColumn ) inputs[parameterIndex] = example.GetValueOf(exampleIndex, methodParameter.ParameterType); } } var stepAction = GetStepAction(method, inputs.ToArray(), returnsItsText); return new Step(stepAction, new StepTitle(stepMethodName), matcher.Asserts, matcher.ExecutionOrder, matcher.ShouldReport, new List<StepArgument>()); }