private void GenerateCodeFromFeature(Feature feature, TextWriter writer) { CodeDomHelper codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); XUnitTestGeneratorProvider xUnitTestGeneratorProvider = new XUnitTestGeneratorProvider(); SpecFlowUnitTestConverter converter = FactoryMethods.CreateUnitTestConverter(xUnitTestGeneratorProvider); var codeNamespace = converter.GenerateUnitTestFixture(feature, "TestClassName", "Target.Namespace"); CSharpCodeProvider codeProvider = new CSharpCodeProvider(); CodeGeneratorOptions options = new CodeGeneratorOptions(); codeProvider.GenerateCodeFromNamespace(codeNamespace, writer, options); }
public void Should_set_skip_attribute_for_theory() { // Arrange var provider = new XUnitTestGeneratorProvider(new CodeDomHelper(new CSharpCodeProvider())); // TODO: what about XUnit2TestGeneratorProvider ? // Act var codeMemberMethod = new CodeMemberMethod() { CustomAttributes = new CodeAttributeDeclarationCollection( new[] { new CodeAttributeDeclaration(XUnit2TestGeneratorProvider.THEORY_ATTRIBUTE) }) }; provider.SetTestMethodIgnore(null, codeMemberMethod); // Assert var modifiedAttribute = codeMemberMethod.CustomAttributes.OfType<CodeAttributeDeclaration>() .FirstOrDefault(a => a.Name == XUnitTestGeneratorProvider.THEORY_ATTRIBUTE); Assert.That(modifiedAttribute, Is.Not.Null); var attribute = modifiedAttribute.Arguments.OfType<CodeAttributeArgument>() .FirstOrDefault(a => a.Name == XUnitTestGeneratorProvider.THEORY_ATTRIBUTE_SKIP_PROPERTY_NAME); Assert.That(attribute, Is.Not.Null); var primitiveExpression = attribute.Value as CodePrimitiveExpression; Assert.That(primitiveExpression, Is.Not.Null); Assert.That(primitiveExpression.Value, Is.EqualTo(XUnitTestGeneratorProvider.SKIP_REASON)); }
public void Should_set_displayname_attribute() { // Arrange var provider = new XUnitTestGeneratorProvider(new CodeDomHelper(new CSharpCodeProvider())); // TODO: what about XUnit2TestGeneratorProvider ? var context = new Generator.TestClassGenerationContext( unitTestGeneratorProvider: null, document: new Parser.SpecFlowDocument( feature: new SpecFlowFeature( tags: null, location: null, language: null, keyword: null, name: "", description: null, children:null ), comments: null, sourceFilePath: null), ns: null, testClass: null, testRunnerField: null, testClassInitializeMethod: null, testClassCleanupMethod: null, testInitializeMethod: null, testCleanupMethod: null, scenarioInitializeMethod: null, scenarioCleanupMethod: null, featureBackgroundMethod: null, generateRowTests: false); var codeMemberMethod = new CodeMemberMethod(); // Act provider.SetTestMethod(context, codeMemberMethod, "Foo"); // Assert var modifiedAttribute = codeMemberMethod.CustomAttributes.OfType<CodeAttributeDeclaration>() .FirstOrDefault(a => a.Name == "Xunit.FactAttribute"); Assert.That(modifiedAttribute, Is.Not.Null); var attribute = modifiedAttribute.Arguments.OfType<CodeAttributeArgument>() .FirstOrDefault(a => a.Name == "DisplayName"); Assert.That(attribute, Is.Not.Null); var primitiveExpression = attribute.Value as CodePrimitiveExpression; Assert.That(primitiveExpression, Is.Not.Null); Assert.That(primitiveExpression.Value, Is.EqualTo("Foo")); }