private FeatureStatementType GetFeatureStatementType(string featureStatementLine) { FeatureStatementType featureStatement = new FeatureStatementType(); if (featureStatementLine.ToLower().StartsWith("as a ")) { featureStatement = FeatureStatementType.AsA; } else if (featureStatementLine.ToLower().StartsWith("so that ")) { featureStatement = FeatureStatementType.SoThat; } else if (featureStatementLine.ToLower().StartsWith("you can ")) { featureStatement = FeatureStatementType.YouCan; } return(featureStatement); }
private string GetFeatureStatement(string featureStatementLine, FeatureStatementType featureStatementType) { string featureStatement = null; switch (featureStatementType) { case FeatureStatementType.AsA: featureStatement = featureStatementLine.Substring(5, featureStatementLine.Length - 5); break; case FeatureStatementType.SoThat: featureStatement = featureStatementLine.Substring(8, featureStatementLine.Length - 8); break; case FeatureStatementType.YouCan: featureStatement = featureStatementLine.Substring(8, featureStatementLine.Length - 8); break; } return(featureStatement); }
private void ProcessLines(string[] lines) { string capabilityName = null; string featureName = null; string scenarioName = null; string asAStatement = null; string soThatStatement = null; string youCanStatement = null; StringBuilder stepInput = new StringBuilder(); StringBuilder stepExplanation = new StringBuilder(); StringBuilder scenarioExplanation = new StringBuilder(); StringBuilder featureExplanation = new StringBuilder(); StringBuilder capabilityExplanation = new StringBuilder(); ScenarioBuilder scenarioBuilder = null; Step currentStep = null; StepType currentStepType = new StepType(); FeatureStatementType currentFeatureStatementType = new FeatureStatementType(); LineType previousLineType = new LineType(); LineType currentLineType = new LineType(); int capabilityFeatureCount = 0; int featureScenarioCount = 0; for (int x = 0; x < lines.Length; x++) //First 2 lines are test run name and blank. { try { previousLineType = currentLineType; var currentLine = lines[x]; string previousLine = null; if (x > 0) { previousLine = lines[x - 1]; } currentLineType = this.GetLineType(currentLine, previousLineType, x + 1); var currentLineContent = this.GetLineContent(currentLine, currentLineType, x + 1); switch (currentLineType) { case LineType.Capability: if (scenarioName != null) { scenarioBuilder = this.AddScenario( capabilityName, featureName, scenarioName, asAStatement, soThatStatement, youCanStatement, scenarioExplanation.ToString(), TextFormat.markdown, featureExplanation.ToString(), TextFormat.markdown); scenarioName = null; scenarioExplanation.Clear(); featureExplanation.Clear(); } if (currentStep != null) { this.AddStep(scenarioBuilder, currentStepType, currentStep, stepInput, stepExplanation); currentStep = null; } if (capabilityName != null && capabilityFeatureCount == 0) { throw new TextImportException($"Line {x+1}: Capability defined with no features."); } capabilityFeatureCount = 0; capabilityName = currentLineContent; break; case LineType.CapabilityExplanation: capabilityExplanation.AppendLine(currentLineContent); break; case LineType.FeatureExplanation: featureExplanation.AppendLine(currentLineContent); break; case LineType.ScenarioExplanation: scenarioExplanation.AppendLine(currentLineContent); break; case LineType.StepExplanation: stepExplanation.AppendLine(currentLineContent); break; case LineType.FeatureStatement: currentFeatureStatementType = this.GetFeatureStatementType(currentLineContent); var featureStatement = this.GetFeatureStatement(currentLineContent, currentFeatureStatementType); switch (currentFeatureStatementType) { case FeatureStatementType.AsA: asAStatement = this.GetFeatureStatement(currentLineContent, currentFeatureStatementType); break; case FeatureStatementType.SoThat: soThatStatement = this.GetFeatureStatement(currentLineContent, currentFeatureStatementType); break; case FeatureStatementType.YouCan: youCanStatement = this.GetFeatureStatement(currentLineContent, currentFeatureStatementType); break; } break; case LineType.Feature: capabilityFeatureCount++; if (scenarioName != null) { if (featureScenarioCount == 0) { throw new TextImportException($"Line {x}: Feature defined with no scenarios."); } scenarioBuilder = this.AddScenario( capabilityName, featureName, scenarioName, asAStatement, soThatStatement, youCanStatement, scenarioExplanation.ToString(), TextFormat.markdown, featureExplanation.ToString(), TextFormat.markdown); scenarioName = null; scenarioExplanation.Clear(); featureExplanation.Clear(); } if (currentStep != null) { this.AddStep(scenarioBuilder, currentStepType, currentStep, stepInput, stepExplanation); currentStep = null; } this.scenarioCount = 0; featureScenarioCount = 0; featureName = currentLineContent; this.featureNames.Add($"{rootNamespace}.{capabilityName.ConvertCapabilityNameToNamespace()}.{featureName.ConvertFeatureNameToClassName()}"); break; case LineType.Scenario: featureScenarioCount++; if (scenarioName != null) { scenarioBuilder = this.AddScenario( capabilityName, featureName, scenarioName, asAStatement, soThatStatement, youCanStatement, scenarioExplanation.ToString(), TextFormat.markdown, featureExplanation.ToString(), TextFormat.markdown); scenarioName = null; scenarioExplanation.Clear(); featureExplanation.Clear(); } if (currentStep != null) { this.AddStep(scenarioBuilder, currentStepType, currentStep, stepInput, stepExplanation); currentStep = null; } scenarioName = currentLineContent; break; case LineType.Step: if (scenarioName != null) { scenarioBuilder = this.AddScenario( capabilityName, featureName, scenarioName, asAStatement, soThatStatement, youCanStatement, scenarioExplanation.ToString(), TextFormat.markdown, featureExplanation.ToString(), TextFormat.markdown); scenarioName = null; scenarioExplanation.Clear(); featureExplanation.Clear(); } if (currentStep != null) { this.AddStep(scenarioBuilder, currentStepType, currentStep, stepInput, stepExplanation); currentStep = null; } currentStepType = this.GetStepType(currentLineContent, x + 1); var stepName = this.GetStepName(currentLineContent, currentStepType); var stepReason = currentLineContent.ExtractReason(); Action <Step> action = (s) => {}; if (stepReason == "Failed") { action = (s) => { throw new Exception("Generated Failure"); }; } currentStep = xB.CreateStep(stepName, action); if (stepReason == "Failed") { currentStep.Outcome = Outcome.Failed; } break; case LineType.StepInput: stepInput.AppendLine(currentLineContent); break; } } catch (TextImportException) { throw; } catch (Exception) { throw new TextImportException(x + 1, lines[x], Enum.GetName(typeof(LineType), previousLineType)); } } this.ValidateFollowingLine(LineType.LastLine, currentLineType, lines.Length, ""); if (scenarioName != null) { scenarioBuilder = this.AddScenario( capabilityName, featureName, scenarioName, asAStatement, soThatStatement, youCanStatement, scenarioExplanation.ToString(), TextFormat.markdown, featureExplanation.ToString(), TextFormat.markdown); scenarioName = null; scenarioExplanation.Clear(); featureExplanation.Clear(); } if (currentStep != null) { this.AddStep(scenarioBuilder, currentStepType, currentStep, stepInput, stepExplanation); currentStep = null; } }