Beispiel #1
0
        private string GenerateTestMethodBody(Scenario scenario)
        {
            const string stepsObjectName = "steps";

            var builder = new CSharpFeatureStepsBuilder();
            builder.RootNamespace = this.RootNamespace;
            builder.Feature = this.Feature;
            builder.Scenario = scenario;

            var code = new StringBuilder();
            code.AppendLine(CodeForBody("// init"));
            code.AppendLine(CodeForBody("using (var {0} = new {1}())", stepsObjectName, builder.ToClassName()));
            code.AppendLine(CodeForBody("{{"));

            code.AppendLine(CodeForBody(1, "// prepare"));
            code.AppendLine(CodeForBody(true, builder.ToMockVariablesDeclaration(1)));

            code.AppendLine(CodeForBody(1, "// do"));
            code.AppendLine(CodeForBody(1, "{0};", builder.ToMethodCall(stepsObjectName, scenario.Statements.Given)));
            code.AppendLine(CodeForBody(1, "{0};", builder.ToMethodCall(stepsObjectName, scenario.Statements.When)));
            code.AppendLine(CodeForBody(1, "{0};", builder.ToMethodCall(stepsObjectName, scenario.Statements.Then)));
            code.AppendLine();

            code.AppendLine(CodeForBody(1, "// check"));
            code.AppendLine(CodeForBody(1, "Assert.Inconclusive();"));

            code.AppendLine(CodeForBody("}}"));

            return code.ToString();
        }