/// <summary> /// Re-factor to return just a single instance. Need to state that we only support /// either a doc string or test cases, not both in the SDK. /// </summary> /// <remarks> /// Maybe this takes in the collection of steps, and applies ordering to /// the steps so that the generated code within the test method calls in /// the right order. /// </remarks> public IList <ISyntaxScenarioStep> For(IGherkinBlockSteps context) { var result = new List <ISyntaxScenarioStep>(); if (context == null) { return(result); } var classTypes = new List <string>(); foreach (var step in context) { if (step.DocString != null) { result.Add(new DocStringSyntaxStep(step)); } if (step.TestCase != null) { if (step.GherkinPlus().HasClassNotation) { var className = step.GherkinPlus().ClassName; var classStep = new DataTableSyntaxStepClass(step, className, classTypes); result.Add(classStep); if (!classTypes.Contains(className)) { classTypes.Add(className); } } else { var tupleStep = new DataTableSyntaxStepTuple(step); result.Add(tupleStep); } } else { var descriptionStep = new DescriptionOnlySyntaxStep(step); if (result.Exists(x => x.Signature == descriptionStep.Signature)) { // ignore, duplicate already in collection } else { result.Add(descriptionStep); } } } return(result); }
private SyntaxScenarioSteps( IGherkinBlock background, IGherkinBlockSteps context, IMethod method, IEnumerable <string> whereDeclaration, string whereCallSyntax) { var hasSteps = false; this.steps = new List <string>(); var callSyntax = new List <string>(); if (background != null) { foreach (var s in SyntaxScenarioStep.CreateBuilder.For(background.Steps)) { hasSteps = true; callSyntax.Add(s.CallSyntax); } } var builders = SyntaxScenarioStep.CreateBuilder.For(context); if (builders.Any()) { hasSteps = true; if (whereDeclaration != null) { this.steps.AddRange(whereDeclaration); callSyntax.Add(whereCallSyntax); } } foreach (var builder in builders) { this.steps.AddRange(builder.Syntax); callSyntax.Add(builder.CallSyntax); } this.Method = !hasSteps ? method : new TestMethodPrivate(method, callSyntax); }
public static ISyntaxScenarioSteps For( IGherkinBlock background, IGherkinBlockSteps context, IMethods methods, IMethodSignature signature, bool hasTestCases) { ISpockElements <string> whereDeclaration = null; var whereCallSyntax = string.Empty; if (hasTestCases) { whereDeclaration = methods.Implementation.Declaration(signature); whereCallSyntax = methods.Implementation.CallSyntax(signature); } return(new SyntaxScenarioSteps( background, context, methods.Specification, whereDeclaration, whereCallSyntax)); }