예제 #1
0
        private void ProcessScenarioLine(ScenarioStyle style, string line, ref StepType stepType, StringBuilder builder)
        {
            if (stepType == StepType.When)
            {
                stepType = StepType.Then;
            }

            if (line.StartsWith("When"))
            {
                stepType = StepType.When;
            }

            const string tagToken = "@";
            if (line.StartsWith(tagToken))
            {
                var tags = line.Split('@');

                foreach (var tag in tags
                    .Select(t => t.Trim().Trim('@'))
                    .Where(t => !string.IsNullOrWhiteSpace(t)))
                {
                    builder.AppendLine($"   [Tag(\"{tag}\")]");
                }
                return;
            }
            const string scenarioToken = "Scenario:";
            if (line.StartsWith(scenarioToken))
            {
                if (style == ScenarioStyle.Classic) builder.AppendLine("   [Scenario(Feature.Unknown)]");
                string className = Sanitize(line.Substring(scenarioToken.Length));
                builder.AppendLine($"   public class {className} : {GetScenarioTypeName(style)}");
                builder.AppendLine("   {");

                if (style == ScenarioStyle.Fluent)
                {
                    builder.AppendLine($"      public {className}()");
                    builder.AppendLine("      {");
                    builder.AppendLine("         TODO");
                    builder.AppendLine("      }");
                    builder.AppendLine();
                }

                return;
            }

            if (line.StartsWith("-> done: "))
            {
                return;
            }

            var methodName = ProcessStepLine(line, stepType);

            if (style == ScenarioStyle.Classic) builder.AppendLine($"      [{stepType}]");
            builder.AppendLine($"      {GetAccessModifierForStep(style)}void {methodName}()");
            builder.AppendLine("      {");
            builder.AppendLine("      }");
            builder.AppendLine();
        }
예제 #2
0
        private void ProcessScenarioLine(ScenarioStyle style, string line, ref StepType stepType, StringBuilder builder)
        {
            if (stepType == StepType.When)
            {
                stepType = StepType.Then;
            }

            if (line.StartsWith("When"))
            {
                stepType = StepType.When;
            }

            const string tagToken = "@";
            if (line.StartsWith(tagToken))
            {
                var tags = line.Split('@');

                foreach (var tag in tags
                    .Select(t => t.Trim().Trim('@'))
                    .Where(t => !string.IsNullOrWhiteSpace(t)))
                {
                    builder.AppendLine($"   [Tag(\"{tag}\")]");
                }
                return;
            }
            const string scenarioToken = "Scenario:";
            if (line.StartsWith(scenarioToken))
            {
                if (style == ScenarioStyle.Classic) builder.AppendLine("   [Scenario(Feature.Unknown)]");
                string className = Sanitize(line.Substring(scenarioToken.Length));
                builder.AppendLine($"   public class {className} : {GetScenarioTypeName(style)}");
                builder.AppendLine("   {");

                if (style == ScenarioStyle.Fluent)
                {
                    builder.AppendLine($"      public {className}()");
                    builder.AppendLine("      {");
                    builder.AppendLine("         TODO");
                    builder.AppendLine("      }");
                    builder.AppendLine();
                }

                return;
            }

            if (line.StartsWith("-> done: "))
            {
                return;
            }

            var methodName = ProcessStepLine(line, stepType);

            if (style == ScenarioStyle.Classic) builder.AppendLine($"      [{stepType}]");
            builder.AppendLine($"      {GetAccessModifierForStep(style)}void {methodName}()");
            builder.AppendLine("      {");
            builder.AppendLine("      }");
            builder.AppendLine();
        }
예제 #3
0
 static string GetScenarioTypeName(ScenarioStyle style)
 {
     switch (style)
     {
         case ScenarioStyle.Classic:
             return "Test";
         case ScenarioStyle.Fluent:
             return "FluentTest";
         default:
             throw new NotSupportedException($"{style} is not supported");
     }
 }
예제 #4
0
 static string GetAccessModifierForStep(ScenarioStyle style)
 {
     switch (style)
     {
         case ScenarioStyle.Classic:
             return "public ";
         case ScenarioStyle.Fluent:
             return "";
         default:
             throw new NotSupportedException($"{style} is not supported");
     }
 }
예제 #5
0
 static string GetScenarioTypeName(ScenarioStyle style)
 {
     switch (style)
     {
         case ScenarioStyle.Classic:
             return "Test";
         case ScenarioStyle.Fluent:
             return "FluentTest";
         default:
             throw new NotSupportedException($"{style} is not supported");
     }
 }
예제 #6
0
 static string GetAccessModifierForStep(ScenarioStyle style)
 {
     switch (style)
     {
         case ScenarioStyle.Classic:
             return "public ";
         case ScenarioStyle.Fluent:
             return "";
         default:
             throw new NotSupportedException($"{style} is not supported");
     }
 }
예제 #7
0
        void ProcessScenario(ScenarioStyle style)
        {
            var builder = new StringBuilder();

            var stepType = StepType.Given;

            foreach (var line in _textBox.Text.Split(Environment.NewLine.ToCharArray())
                .Select(t => t.Trim())
                .Where(t => !string.IsNullOrWhiteSpace(t)))
            {
                ProcessScenarioLine(style, line, ref stepType, builder);
            }

            // remove the extra whitespace line after methods
            builder.Remove(builder.Length - 2, 2);

            builder.AppendLine("   }");

            var scenario = builder.ToString();

            Clipboard.SetText(scenario);
        }
예제 #8
0
        void ProcessScenario(ScenarioStyle style)
        {
            var builder = new StringBuilder();

            var stepType = StepType.Given;

            foreach (var line in _textBox.Text.Split(Environment.NewLine.ToCharArray())
                .Select(t => t.Trim())
                .Where(t => !string.IsNullOrWhiteSpace(t)))
            {
                ProcessScenarioLine(style, line, ref stepType, builder);
            }

            // remove the extra whitespace line after methods
            builder.Remove(builder.Length - 2, 2);

            builder.AppendLine("   }");

            var scenario = builder.ToString();

            Clipboard.SetText(scenario);
        }