示例#1
0
        public ISpockElements <string> Spock()
        {
            var framework = TestFramework.For(this.Options);

            var builder = new SpockCollectionString();

            builder.Append(this.Header());
            builder.AppendLine("namespace {0} {{", this.FixtureInvariants.Namespace);
            if (!framework.SupportsParameterDriven)
            {
                builder.AppendLine("using System;");
                builder.AppendLine("using System.Collections.Generic;");
                builder.AppendLine("using System.Linq;");
            }

            builder.AppendLine("using global::ErraticMotion.Test.Tools.Gherkin.Annotations;");
            builder.AppendLine("using {0};", framework.Namespace);
            builder.Append(this.XmlDocComments);
            builder.AppendLine("[FeatureId(\"{0}\")]", this.FixtureInvariants.FeatureId);
#if GHERKIN_ATTRIBUTES
            builder.Append(this.GherkinAttributes);
#endif
            builder.AppendLine("[GeneratedFromFeature]");

            var testClass = framework.TestClass();
            if (testClass.Supported)
            {
                builder.AppendLine(testClass.Value);
            }

            var testCategory = framework.TestCategory(Target.Class);
            if (testCategory.Supported)
            {
                builder.AppendLine(testCategory.Value);
            }

            builder.AppendLine("public partial class {0}", this.FixtureInvariants.FixtureName);
            builder.AppendLine("{0}", "{");
            if (this.gherkin.Background != null)
            {
                foreach (var s in SyntaxScenarioStep.CreateBuilder.For(this.gherkin.Background.Steps))
                {
                    builder.AddRange(s.Syntax);
                }
            }

            builder.Append(this.FixtureMethods);
            builder.AppendLine("{0}", "}");
            builder.AppendLine("{0}", "}");
            return(builder);
        }
示例#2
0
        public ISpockElements <string> Syntax()
        {
            var framework     = TestFramework.For(this.Options);
            var builder       = new SpockCollectionString();
            var referenceTags = new List <string>();

            var stepBuilder = SyntaxScenarioSteps.For(this.background, this.scenario.Steps, this.Methods, this.Signature, this.TestCases.Any());

            builder.AddRange(stepBuilder.Syntax);
            builder.AppendLine();
            builder.Append(stepBuilder.Method.Declaration(this.Signature));
            builder.AppendLine();
            builder.Append(this.XmlComments());
            builder.AppendLine("[ScenarioId(\"{0}\")]", this.Identity.Id);
#if GHERKIN_ATTRIBUTES
            builder.Append(GherkinAttribtes());
            foreach (var args in testCases)
            {
                builder.AppendLine("[Where{0:v}]", args);
            }
#endif
            foreach (var tag in referenceTags)
            {
                builder.AppendLine(tag);
            }

            var testIgnore = framework.TestIgnore();
            if (testIgnore.Supported && this.Options.SetIgnore)
            {
                builder.AppendLine(testIgnore.Value);
            }

            var testCategory = framework.TestCategory(Target.Method);
            if (testCategory.Supported)
            {
                builder.AppendLine(testCategory.Value);
            }

            if (framework.SupportsParameterDriven)
            {
                if (this.TestCases.Any())
                {
                    var facts = framework.TestFacts(this.TestCases).ToArray();
                    if (facts[0].Supported)
                    {
                        builder.AppendLine("[System.CLSCompliant(false)]");
                        foreach (var args in facts)
                        {
                            builder.AppendLine(args.Value);
                        }
                    }
                }
                else
                {
                    var testMethod = framework.TestMethod();
                    if (testMethod.Supported)
                    {
                        builder.AppendLine(testMethod.Value);
                    }
                }

                builder.Append(this.Methods.Conceptual.Declaration(this.Signature));
                builder.AppendLine("{0}", "{");
                builder.AppendLine("   {0}", this.Methods.Specification.CallSyntax(this.Signature));
                builder.AppendLine("{0}", "}");
            }
            else
            {
                var testMethod = framework.TestMethod();
                if (testMethod.Supported)
                {
                    builder.AppendLine(testMethod.Value);
                }

                builder.Append(this.Methods.Conceptual.Declaration(new EmptyMethodSignature()));
                builder.AppendLine("{0}", "{");
                var testCaseBuilder = SyntaxTestCasesBuilder.For(this.TestCases, this.Methods, framework);
                builder.AddRange(testCaseBuilder.Build());
                builder.AppendLine("{0}", "}");
            }

            return(builder);
        }