private static void TryResolve <T>(Pickle pickle, PickleStep step, IStepResolver resolver, T context) { try { resolver.Resolve(step, context); } catch (Exception e) { var plocs = String.Join(",", pickle.Locations.Select(loc => $"{loc.Line}:{loc.Column}")); var slocs = String.Join(",", step.Locations.Select(loc => $"{loc.Line}:{loc.Column}")); var message = $@" Scenario: ({plocs}) {pickle.Name} Step: ({slocs}) {step.Text} Error: {(e.InnerException ?? e).Message} Test Trace: {(e.InnerException ?? e).StackTrace} "; throw new Exception(message); } }
public static string ToName(PickleStep step) { var a = CommonConventions.StripBasicParameters(step.Text); var b = CommonConventions.TitlizeWords(a); var c = CommonConventions.StripToCodeCompliant(b); return(c); }
public async Task ExecuteStepAsync(PickleStep step) { string[] arguments = step.Arguments .ToList() .Cast <PickleString>() .Select(a => a.Content) .ToArray(); await _assemblyAdapter.ExecuteMethodFromStatementAsync(step.Text, arguments); }
public void ExecuteStep(PickleStep step) { string[] arguments = step.Arguments .ToList() .Cast <PickleString>() .Select(a => a.Content) .ToArray(); _assemblyAdapter.ExecuteMethodFromStatement(step.Text, arguments); }
protected virtual void CompileScenarioOutline(List <Pickle> pickles, Func <IEnumerable <PickleStep> > backgroundStepsFactory, Scenario scenarioOutline, IEnumerable <Tag> featureTags, string language, string gherkinDocumentUri) { foreach (var examples in scenarioOutline.Examples) { if (examples.TableHeader == null) { continue; } var variableCells = examples.TableHeader.Cells; foreach (var values in examples.TableBody) { var valueCells = values.Cells; var steps = new List <PickleStep>(); if (scenarioOutline.Steps.Any()) { steps.AddRange(backgroundStepsFactory()); } var tags = new List <Tag>(); tags.AddRange(featureTags); tags.AddRange(scenarioOutline.Tags); tags.AddRange(examples.Tags); foreach (var scenarioOutlineStep in scenarioOutline.Steps) { string stepText = Interpolate(scenarioOutlineStep.Text, variableCells, valueCells); PickleStep pickleStep = CreatePickleStep( scenarioOutlineStep, stepText, CreatePickleArgument(scenarioOutlineStep, variableCells, valueCells), new[] { scenarioOutlineStep.Id, values.Id } ); steps.Add(pickleStep); } Pickle pickle = new Pickle( _idGenerator.GetNewId(), gherkinDocumentUri, Interpolate(scenarioOutline.Name, variableCells, valueCells), language, steps, PickleTags(tags), new[] { scenarioOutline.Id, values.Id } ); pickles.Add(pickle); } } }
public void Resolve <T>(PickleStep step, T context) { var name = ToName(step); var method = Find(name, context); if (method == null) { throw new Exception($"Unable to find step method: \"{name}\""); } var parameters = ToParams(method, step); if (typeof(Task).IsAssignableFrom(method.ReturnType)) { ((Task)method.Invoke(context, parameters)).GetAwaiter().GetResult(); } else { method.Invoke(context, parameters); } }
public static object[] ToParams(MethodInfo method, PickleStep step) { var inlines = CommonConventions.ExtractBasicParameters(step.Text) .Cast <Object>(); var docs = step.Arguments .Select(arg => arg as PickleString) .Where(arg => arg != null) .Select(arg => arg.Content); var tables = step.Arguments .Select(arg => arg as PickleTable) .Where(arg => arg != null); var values = inlines .Concat(docs) .Concat(tables) .Zip(method.GetParameters(), Tuple.Create) .Select(tuple => CommonConventions.CoerceType(tuple.Item1, tuple.Item2)) .ToArray(); return(values); }