Exemple #1
0
        public void Should_register_testOutputHelper_on_scenario_setup()
        {
            SpecFlowGherkinParser parser = new SpecFlowGherkinParser(new CultureInfo("en-US"));

            using (var reader = new StringReader(SampleFeatureFile))
            {
                SpecFlowDocument document = parser.Parse(reader, null);
                document.Should().NotBeNull();

                var provider = new XUnit2TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp));

                var           converter = provider.CreateUnitTestConverter();
                CodeNamespace code      = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace");

                code.Should().NotBeNull();
                var scenarioStartMethod = code.Class().Members().Single(m => m.Name == @"ScenarioInitialize");

                scenarioStartMethod.Statements.Count.Should().Be(2);
                var expression = (scenarioStartMethod.Statements[1] as CodeExpressionStatement).Expression;
                var method     = (expression as CodeMethodInvokeExpression).Method;
                (method.TargetObject as CodePropertyReferenceExpression).PropertyName.Should().Be("ScenarioContainer");
                method.MethodName.Should().Be("RegisterInstanceAs");
                method.TypeArguments.Should().NotBeNullOrEmpty();
                method.TypeArguments[0].BaseType.Should().Be("Xunit.Abstractions.ITestOutputHelper");

                ((expression as CodeMethodInvokeExpression).Parameters[0] as CodeVariableReferenceExpression).VariableName.Should().Be("_testOutputHelper");
            }
        }
Exemple #2
0
        public void Should_initialize_testOutputHelper_field_in_constructor()
        {
            SpecFlowGherkinParser parser = new SpecFlowGherkinParser(new CultureInfo("en-US"));

            using (var reader = new StringReader(SampleFeatureFile))
            {
                SpecFlowDocument document = parser.Parse(reader, null);
                document.Should().NotBeNull();


                var provider = new XUnit2TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp));

                var           converter = provider.CreateUnitTestConverter();
                CodeNamespace code      = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace");

                code.Should().NotBeNull();

                var classContructor = code.Class().Members().Single(m => m.Name == ".ctor");
                classContructor.Should().NotBeNull();
                classContructor.Parameters.Count.Should().Be(2);
                classContructor.Parameters[1].Type.BaseType.Should().Be("Xunit.Abstractions.ITestOutputHelper");
                classContructor.Parameters[1].Name.Should().Be("testOutputHelper");

                var initOutputHelper = classContructor.Statements.OfType <CodeAssignStatement>().First();
                initOutputHelper.Should().NotBeNull();
                ((CodeFieldReferenceExpression)(initOutputHelper.Left)).FieldName.Should().Be("_testOutputHelper");
                ((CodeVariableReferenceExpression)(initOutputHelper.Right)).VariableName.Should().Be("testOutputHelper");
            }
        }
Exemple #3
0
        public void Should_add_testOutputHelper_field_in_class()
        {
            SpecFlowGherkinParser parser = new SpecFlowGherkinParser(new CultureInfo("en-US"));

            using (var reader = new StringReader(SampleFeatureFile))
            {
                SpecFlowDocument document = parser.Parse(reader, null);
                document.Should().NotBeNull();

                var provider = new XUnit2TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp));

                var           converter = provider.CreateUnitTestConverter();
                CodeNamespace code      = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace");

                code.Should().NotBeNull();
                var loggerInstance = code.Class().Members.OfType <CodeMemberField>().First(m => m.Name == @"_testOutputHelper");
                loggerInstance.Type.BaseType.Should().Be("Xunit.Abstractions.ITestOutputHelper");
                loggerInstance.Attributes.Should().Be(MemberAttributes.Private | MemberAttributes.Final);
            }
        }