diff --git a/TechTalk.SpecFlow.Generator/Generation/UnitTestMethodGenerator.cs b/TechTalk.SpecFlow.Generator/Generation/UnitTestMethodGenerator.cs index 013e14a5c..cf96d840c 100644 --- a/TechTalk.SpecFlow.Generator/Generation/UnitTestMethodGenerator.cs +++ b/TechTalk.SpecFlow.Generator/Generation/UnitTestMethodGenerator.cs @@ -332,7 +332,7 @@ private void GenerateScenarioOutlineExamplesAsRowTests(TestClassGenerationContex foreach (var row in examples.TableBody) { var arguments = row.Cells.Select(c => c.Value); - _unitTestGeneratorProvider.SetRow(generationContext, scenatioOutlineTestMethod, scenarioOutline.Name, arguments, GetNonIgnoreTags(examples.Tags), HasIgnoreTag(examples.Tags)); + _unitTestGeneratorProvider.SetRow(generationContext, scenatioOutlineTestMethod, arguments, GetNonIgnoreTags(examples.Tags), HasIgnoreTag(examples.Tags)); } } } @@ -468,11 +468,11 @@ private CodeMemberMethod CreateScenatioOutlineTestMethod(TestClassGenerationCont if (rowTest) { - _unitTestGeneratorProvider.SetRowTest(generationContext, testMethod, friendlyTestName, scenarioDefinition.Description); + _unitTestGeneratorProvider.SetRowTest(generationContext, testMethod, friendlyTestName); } else { - _unitTestGeneratorProvider.SetTestMethod(generationContext, testMethod, friendlyTestName, scenarioDefinition.Description); + _unitTestGeneratorProvider.SetTestMethod(generationContext, testMethod, friendlyTestName); } _decoratorRegistry.DecorateTestMethod(generationContext, testMethod, ConcatTags(scenarioDefinition.GetTags(), additionalTags), out var scenarioCategories); diff --git a/TechTalk.SpecFlow.Generator/UnitTestProvider/IUnitTestGeneratorProvider.cs b/TechTalk.SpecFlow.Generator/UnitTestProvider/IUnitTestGeneratorProvider.cs index 214fa046e..5133f3b9c 100644 --- a/TechTalk.SpecFlow.Generator/UnitTestProvider/IUnitTestGeneratorProvider.cs +++ b/TechTalk.SpecFlow.Generator/UnitTestProvider/IUnitTestGeneratorProvider.cs @@ -19,12 +19,12 @@ public interface IUnitTestGeneratorProvider void SetTestInitializeMethod(TestClassGenerationContext generationContext); void SetTestCleanupMethod(TestClassGenerationContext generationContext); - void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName, string testDescription = null); + void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName); void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable scenarioCategories); void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod); - void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string scenarioDescription = null); - void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, IEnumerable arguments, IEnumerable tags, bool isIgnored); + void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle); + void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable arguments, IEnumerable tags, bool isIgnored); void SetTestMethodAsRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string exampleSetName, string variantName, IEnumerable> arguments); } } diff --git a/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestGeneratorProvider.cs b/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestGeneratorProvider.cs index f9e4aa004..ac534bacf 100644 --- a/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestGeneratorProvider.cs +++ b/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestGeneratorProvider.cs @@ -164,11 +164,10 @@ public void SetTestCleanupMethod(TestClassGenerationContext generationContext) } - public virtual void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName, string testDescription = null) + public virtual void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName) { - testDescription = string.IsNullOrEmpty(testDescription) ? friendlyTestName : testDescription; CodeDomHelper.AddAttribute(testMethod, TEST_ATTR); - CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, testDescription); + CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, friendlyTestName); //as in mstest, you cannot mark classes with the description attribute, we //just apply it for each test method as a property @@ -186,13 +185,13 @@ public void SetTestMethodIgnore(TestClassGenerationContext generationContext, Co } - public virtual void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string scenarioDescription = null) + public virtual void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle) { //MsTest does not support row tests... :( throw new NotSupportedException(); } - public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, IEnumerable arguments, IEnumerable tags, bool isIgnored) + public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable arguments, IEnumerable tags, bool isIgnored) { //MsTest does not support row tests... :( throw new NotSupportedException(); diff --git a/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestV2GeneratorProvider.cs b/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestV2GeneratorProvider.cs index 16258bdad..51d0b3b8d 100644 --- a/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestV2GeneratorProvider.cs +++ b/TechTalk.SpecFlow.Generator/UnitTestProvider/MsTestV2GeneratorProvider.cs @@ -65,7 +65,7 @@ public override void SetTestClassCategories(TestClassGenerationContext generatio } } - public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName, string testDescription = null) + public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName) { if (generationContext.CustomData.ContainsKey(DONOTPARALLELIZE_TAG)) { diff --git a/TechTalk.SpecFlow.Generator/UnitTestProvider/NUnit3TestGeneratorProvider.cs b/TechTalk.SpecFlow.Generator/UnitTestProvider/NUnit3TestGeneratorProvider.cs index 49e1ce60f..fbcdc557a 100644 --- a/TechTalk.SpecFlow.Generator/UnitTestProvider/NUnit3TestGeneratorProvider.cs +++ b/TechTalk.SpecFlow.Generator/UnitTestProvider/NUnit3TestGeneratorProvider.cs @@ -12,10 +12,8 @@ public class NUnit3TestGeneratorProvider : IUnitTestGeneratorProvider protected internal const string TESTFIXTURETEARDOWN_ATTR_NUNIT3 = "NUnit.Framework.OneTimeTearDownAttribute"; protected internal const string PARALLELIZABLE_ATTR = "NUnit.Framework.ParallelizableAttribute"; protected internal const string TESTFIXTURE_ATTR = "NUnit.Framework.TestFixtureAttribute"; - protected internal const string TESTFIXTURENAME_PROPERTY_NAME = "TestName"; protected internal const string TEST_ATTR = "NUnit.Framework.TestAttribute"; protected internal const string ROW_ATTR = "NUnit.Framework.TestCaseAttribute"; - protected internal const string TESTCASENAME_PROPERTY_NAME = "TestName"; protected internal const string CATEGORY_ATTR = "NUnit.Framework.CategoryAttribute"; protected internal const string TESTSETUP_ATTR = "NUnit.Framework.SetUpAttribute"; protected internal const string TESTTEARDOWN_ATTR = "NUnit.Framework.TearDownAttribute"; @@ -65,9 +63,8 @@ public virtual void SetTestClassParallelize(TestClassGenerationContext generatio public void SetTestClass(TestClassGenerationContext generationContext, string featureTitle, string featureDescription) { - featureDescription = string.IsNullOrEmpty(featureDescription) ? featureTitle : featureDescription; - CodeDomHelper.AddAttribute(generationContext.TestClass, TESTFIXTURE_ATTR, new CodeAttributeArgument(TESTFIXTURENAME_PROPERTY_NAME, new CodePrimitiveExpression(featureTitle))); - CodeDomHelper.AddAttribute(generationContext.TestClass, DESCRIPTION_ATTR, featureDescription); + CodeDomHelper.AddAttribute(generationContext.TestClass, TESTFIXTURE_ATTR); + CodeDomHelper.AddAttribute(generationContext.TestClass, DESCRIPTION_ATTR, featureTitle); } public void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable featureCategories) @@ -101,16 +98,10 @@ public void SetTestCleanupMethod(TestClassGenerationContext generationContext) CodeDomHelper.AddAttribute(generationContext.TestCleanupMethod, TESTTEARDOWN_ATTR); } - private void SetTestDescription(CodeMemberMethod testMethod, string description) + public void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName) { - CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, description); - } - - public void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName, string testDescription = null) - { - testDescription = string.IsNullOrEmpty(testDescription) ? friendlyTestName : testDescription; - CodeDomHelper.AddAttribute(testMethod, ROW_ATTR, new CodeAttributeArgument(TESTCASENAME_PROPERTY_NAME, new CodePrimitiveExpression(friendlyTestName))); - SetTestDescription(testMethod, testDescription); + CodeDomHelper.AddAttribute(testMethod, TEST_ATTR); + CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, friendlyTestName); } public void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable scenarioCategories) @@ -118,26 +109,23 @@ public void SetTestMethodCategories(TestClassGenerationContext generationContext CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, scenarioCategories); } - public void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string scenarioDescription = null) + public void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle) { - scenarioDescription = string.IsNullOrEmpty(scenarioDescription) ? scenarioTitle : scenarioDescription; - SetTestDescription(testMethod, scenarioDescription); + SetTestMethod(generationContext, testMethod, scenarioTitle); } - public void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, IEnumerable arguments, IEnumerable tags, bool isIgnored) + public void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable arguments, IEnumerable tags, bool isIgnored) { var args = arguments.Select( arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList(); - - // addressing ReSharper bug: TestCase attribute with empty string[] param causes inconclusive result - https://github.com/techtalk/SpecFlow/issues/116 bool hasExampleTags = tags.Any(); var exampleTagExpressionList = tags.Select(t => new CodePrimitiveExpression(t)); var exampleTagsExpression = hasExampleTags ? new CodeArrayCreateExpression(typeof(string[]), exampleTagExpressionList.ToArray()) : (CodeExpression) new CodePrimitiveExpression(null); - + args.Add(new CodeAttributeArgument(exampleTagsExpression)); // adds 'Category' named parameter so that NUnit also understands that this test case belongs to the given categories @@ -150,9 +138,6 @@ public void SetRow(TestClassGenerationContext generationContext, CodeMemberMetho if (isIgnored) args.Add(new CodeAttributeArgument("Ignored", new CodePrimitiveExpression(true))); - var outlineScenarioTitle = arguments.Any() ? $"{scenarioTitle}({string.Join(",", arguments)})" : scenarioTitle; - - args.Add(new CodeAttributeArgument(TESTCASENAME_PROPERTY_NAME, new CodePrimitiveExpression(outlineScenarioTitle))); CodeDomHelper.AddAttribute(testMethod, ROW_ATTR, args.ToArray()); } diff --git a/TechTalk.SpecFlow.Generator/UnitTestProvider/XUnit2TestGeneratorProvider.cs b/TechTalk.SpecFlow.Generator/UnitTestProvider/XUnit2TestGeneratorProvider.cs index 9bc016c40..4c268a372 100644 --- a/TechTalk.SpecFlow.Generator/UnitTestProvider/XUnit2TestGeneratorProvider.cs +++ b/TechTalk.SpecFlow.Generator/UnitTestProvider/XUnit2TestGeneratorProvider.cs @@ -66,16 +66,15 @@ protected virtual CodeTypeReference CreateFixtureInterface(TestClassGenerationCo public bool GenerateParallelCodeForFeature { get; set; } - public virtual void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string scenarioDescription = null) + public virtual void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle) { - scenarioDescription = string.IsNullOrEmpty(scenarioDescription) ? scenarioTitle : scenarioDescription; CodeDomHelper.AddAttribute(testMethod, THEORY_ATTRIBUTE, new CodeAttributeArgument("DisplayName", new CodePrimitiveExpression(scenarioTitle))); SetProperty(testMethod, FEATURE_TITLE_PROPERTY_NAME, generationContext.Feature.Name); - SetDescription(testMethod, scenarioDescription); + SetDescription(testMethod, scenarioTitle); } - public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, IEnumerable arguments, IEnumerable tags, bool isIgnored) + public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable arguments, IEnumerable tags, bool isIgnored) { //TODO: better handle "ignored" if (isIgnored) @@ -234,13 +233,12 @@ public void SetTestClassCleanupMethod(TestClassGenerationContext generationConte generationContext.TestClassCleanupMethod.Name)); } - public void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName, string testDescription = null) + public void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName) { - testDescription = string.IsNullOrEmpty(testDescription) ? friendlyTestName : testDescription; CodeDomHelper.AddAttribute(testMethod, FACT_ATTRIBUTE, new CodeAttributeArgument("DisplayName", new CodePrimitiveExpression(friendlyTestName))); SetProperty(testMethod, FEATURE_TITLE_PROPERTY_NAME, generationContext.Feature.Name); - SetDescription(testMethod, testDescription); + SetDescription(testMethod, friendlyTestName); } public virtual void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable scenarioCategories) diff --git a/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorBasicsTests.cs b/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorBasicsTests.cs index 81cfef46f..f9e504277 100644 --- a/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorBasicsTests.cs +++ b/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorBasicsTests.cs @@ -107,23 +107,6 @@ public void Should_generate_test_from_feature_file_specified_by_path() } } - [Fact] - public void Should_generate_row_test_cases_from_feature_file_specified_by_path() - { - using (var tempFile = new TempFile(".feature")) - { - tempFile.SetContent(CreateScenarioOutlineValidFeatureFileInput().FeatureFileContent); - - ProjectSettings projectSettings = new ProjectSettings { ProjectFolder = tempFile.FolderName, ProjectPlatformSettings = net35CSSettings }; - var testGenerator = CreateTestGenerator(projectSettings); - - var result = testGenerator.GenerateTestFile( - new FeatureFileInput(tempFile.FileName), - defaultSettings); - result.Success.Should().Be(true); - } - } - [Fact] public void Should_return_detected_version() { diff --git a/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorTestsBase.cs b/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorTestsBase.cs index 228cae542..71b889d41 100644 --- a/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorTestsBase.cs +++ b/Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorTestsBase.cs @@ -99,27 +99,5 @@ protected TestGenerator CreateTestGenerator(ProjectSettings projectSettings) return new TestGenerator(generatorSpecFlowConfiguration, projectSettings, TestHeaderWriterStub.Object, TestUpToDateCheckerStub.Object, generatorRegistryStub.Object, codeDomHelper, gherkinParserFactory); } - - protected FeatureFileInput CreateScenarioOutlineValidFeatureFileInput(string projectRelativeFolderPath = null) - { - return CreateSimpleFeatureFileInput(@" -Feature: Addition -Feature Description - -@mytag -Scenario Outline: Add two numbers -Scenario Description - Given I have entered into the calculator - And I have entered into the calculator - When I press add - Then the result should be on the screen -Examples: ExName -This is desc - | first | second | result | - | 10 | 10 | 20 | - | 50 | 70 | 120 | -", -projectRelativeFolderPath); - } } } diff --git a/Tests/TechTalk.SpecFlow.GeneratorTests/UnitTestProvider/NUnit3GeneratorProviderTests.cs b/Tests/TechTalk.SpecFlow.GeneratorTests/UnitTestProvider/NUnit3GeneratorProviderTests.cs index 170dca780..0d72d9877 100644 --- a/Tests/TechTalk.SpecFlow.GeneratorTests/UnitTestProvider/NUnit3GeneratorProviderTests.cs +++ b/Tests/TechTalk.SpecFlow.GeneratorTests/UnitTestProvider/NUnit3GeneratorProviderTests.cs @@ -17,8 +17,6 @@ namespace TechTalk.SpecFlow.GeneratorTests.UnitTestProvider public class NUnit3GeneratorProviderTests { private const string NUnit3TestCaseAttributeName = @"NUnit.Framework.TestCaseAttribute"; - private const string NUnit3DescriptionAttribute = @"NUnit.Framework.DescriptionAttribute"; - private const string NUnit3TestFixtureAttribute = @"NUnit.Framework.TestFixtureAttribute"; private const string SampleFeatureFile = @" Feature: Sample feature file @@ -37,257 +35,6 @@ public class NUnit3GeneratorProviderTests @ignore Scenario: Ignored scenario"; - [Fact] - public void NUnit3TestGeneratorProvider_EmptyFeatureDescriptionShouldSetCorrectly() - { - // ARRANGE - const string sampleFeatureFile = @" - Feature: Sample feature file - - Scenario: Simple scenario - Given there is something - When I do something - Then something should happen"; - - var document = ParseDocumentFromString(sampleFeatureFile); - var sampleTestGeneratorProvider = new NUnit3TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp)); - var converter = sampleTestGeneratorProvider.CreateUnitTestConverter(); - - // ACT - var code = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace"); - - var testClass = code.Class(); - - // ASSERT - testClass.CustomAttributes().Should().ContainSingle(a => a.Name == NUnit3DescriptionAttribute && a.ArgumentValues().Any(v => v.ToString().Trim() == "Sample feature file")); - - var fixtureAttribute = testClass.CustomAttributes().OfType().FirstOrDefault(a => a.Name == NUnit3TestFixtureAttribute); - - fixtureAttribute.Arguments.OfType().Should().ContainSingle(a => a.Name == "TestName"); - var testNameArgument = fixtureAttribute.Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - - var testNameArgumentValueExpression = testNameArgument.Value as CodePrimitiveExpression; - - testNameArgumentValueExpression.Should().NotBeNull(); - testNameArgumentValueExpression.Value.Should().Be("Sample feature file"); - } - - [Fact] - public void NUnit3TestGeneratorProvider_FeatureDescriptionShouldSetCorrectly() - { - // ARRANGE - const string sampleFeatureFile = @" - Feature: Sample feature file - FeatureDescription - - Scenario: Simple scenario - Given there is something - When I do something - Then something should happen"; - - var document = ParseDocumentFromString(sampleFeatureFile); - var sampleTestGeneratorProvider = new NUnit3TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp)); - var converter = sampleTestGeneratorProvider.CreateUnitTestConverter(); - - // ACT - var code = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace"); - - var testClass = code.Class(); - - // ASSERT - testClass.CustomAttributes().Should().ContainSingle(a => a.Name == NUnit3DescriptionAttribute && a.ArgumentValues().Any(v=>v.ToString().Trim() == "FeatureDescription")); - - var fixtureAttribute = testClass.CustomAttributes().OfType().FirstOrDefault(a => a.Name == NUnit3TestFixtureAttribute); - - fixtureAttribute.Arguments.OfType().Should().ContainSingle(a => a.Name == "TestName"); - var testNameArgument = fixtureAttribute.Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - - var testNameArgumentValueExpression = testNameArgument.Value as CodePrimitiveExpression; - - testNameArgumentValueExpression.Should().NotBeNull(); - testNameArgumentValueExpression.Value.Should().Be("Sample feature file"); - } - - - [Fact] - public void NUnit3TestGeneratorProvider_EmptyScenarioDescriptionShouldSetCorrectly() - { - // ARRANGE - const string sampleFeatureFile = @" - Feature: Sample feature file - - Scenario: Simple scenario - Given there is something - When I do something - Then something should happen"; - - var document = ParseDocumentFromString(sampleFeatureFile); - var sampleTestGeneratorProvider = new NUnit3TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp)); - var converter = sampleTestGeneratorProvider.CreateUnitTestConverter(); - - // ACT - var code = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace"); - - // ASSERT - var testMethod = code.Class().Members().Single(m => m.Name == "SimpleScenario"); - testMethod.CustomAttributes().Should().ContainSingle(a => a.Name == NUnit3DescriptionAttribute && a.ArgumentValues().Any(v => v.ToString().Trim() == "Simple scenario")); - - var caseAttribute = testMethod.CustomAttributes().OfType().FirstOrDefault(a => a.Name == NUnit3TestCaseAttributeName); - - caseAttribute.Arguments.OfType().Should().ContainSingle(a => a.Name == "TestName"); - var testNameArgument = caseAttribute.Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - - var testNameArgumentValueExpression = testNameArgument.Value as CodePrimitiveExpression; - - testNameArgumentValueExpression.Should().NotBeNull(); - testNameArgumentValueExpression.Value.Should().Be("Simple scenario"); - } - - [Fact] - public void NUnit3TestGeneratorProvider_ScenarioDescriptionShouldSetCorrectly() - { - // ARRANGE - const string sampleFeatureFile = @" - Feature: Sample feature file - - Scenario: Simple scenario - ScenarioDescription - Given there is something - When I do something - Then something should happen"; - - var document = ParseDocumentFromString(sampleFeatureFile); - var sampleTestGeneratorProvider = new NUnit3TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp)); - var converter = sampleTestGeneratorProvider.CreateUnitTestConverter(); - - // ACT - var code = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace"); - - var testClass = code.Class(); - - // ASSERT - var testMethod = code.Class().Members().Single(m => m.Name == "SimpleScenario"); - testMethod.CustomAttributes().Should().ContainSingle(a => a.Name == NUnit3DescriptionAttribute && a.ArgumentValues().Any(v => v.ToString().Trim() == "ScenarioDescription")); - - var caseAttribute = testMethod.CustomAttributes().OfType().FirstOrDefault(a => a.Name == NUnit3TestCaseAttributeName); - - caseAttribute.Arguments.OfType().Should().ContainSingle(a => a.Name == "TestName"); - var testNameArgument = caseAttribute.Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - - var testNameArgumentValueExpression = testNameArgument.Value as CodePrimitiveExpression; - - testNameArgumentValueExpression.Should().NotBeNull(); - testNameArgumentValueExpression.Value.Should().Be("Simple scenario"); - } - - [Fact] - public void NUnit3TestGeneratorProvider_ScenarioOutlineWithEmptyDescriptionShouldSetCorrectly() - { - // ARRANGE - const string sampleFeatureFile = @" - Feature: Sample feature file - - Scenario: Simple scenario - Given there is something - When I do something - Then something should happen - - @mytag - Scenario Outline: Simple Scenario Outline - Given there is something - """""" - long string - """""" - When I do - | foo | bar | - | 1 | 2 | - Then something should happen - Examples: - | what | - | something | - | something else | -"; - - var document = ParseDocumentFromString(sampleFeatureFile); - var sampleTestGeneratorProvider = new NUnit3TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp)); - var converter = sampleTestGeneratorProvider.CreateUnitTestConverter(); - - // ACT - var code = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace"); - - var testMethod = code.Class().Members().Single(m => m.Name == "SimpleScenarioOutline"); - testMethod.CustomAttributes().Should().ContainSingle(a => a.Name == NUnit3DescriptionAttribute && a.ArgumentValues().Any(v => v.ToString().Trim() == "Simple Scenario Outline")); - - var caseAttributes = testMethod.CustomAttributes().OfType().Where(a => a.Name == NUnit3TestCaseAttributeName).ToList(); - - var testCase1NameArgument = caseAttributes[0].Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - var testCase1NameArgumentValueExpression = testCase1NameArgument.Value as CodePrimitiveExpression; - - testCase1NameArgumentValueExpression.Should().NotBeNull(); - testCase1NameArgumentValueExpression.Value.Should().Be("Simple Scenario Outline(something)"); - - var testCase2NameArgument = caseAttributes[1].Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - var testCase2NameArgumentValueExpression = testCase2NameArgument.Value as CodePrimitiveExpression; - - testCase2NameArgumentValueExpression.Should().NotBeNull(); - testCase2NameArgumentValueExpression.Value.Should().Be("Simple Scenario Outline(something else)"); - } - - [Fact] - public void NUnit3TestGeneratorProvider_ScenarioOutlineDescriptionShouldSetCorrectly() - { - // ARRANGE - const string sampleFeatureFile = @" - Feature: Sample feature file - - Scenario: Simple scenario - Given there is something - When I do something - Then something should happen - - @mytag - Scenario Outline: Simple Scenario Outline - ScenarioOutlineDescription - Given there is something - """""" - long string - """""" - When I do - | foo | bar | - | 1 | 2 | - Then something should happen - Examples: - | what | - | something | - | something else | -"; - - var document = ParseDocumentFromString(sampleFeatureFile); - var sampleTestGeneratorProvider = new NUnit3TestGeneratorProvider(new CodeDomHelper(CodeDomProviderLanguage.CSharp)); - var converter = sampleTestGeneratorProvider.CreateUnitTestConverter(); - - // ACT - var code = converter.GenerateUnitTestFixture(document, "TestClassName", "Target.Namespace"); - - var testMethod = code.Class().Members().Single(m => m.Name == "SimpleScenarioOutline"); - testMethod.CustomAttributes().Should().ContainSingle(a => a.Name == NUnit3DescriptionAttribute && a.ArgumentValues().Any(v => v.ToString().Trim() == "ScenarioOutlineDescription")); - - var caseAttributes = testMethod.CustomAttributes().OfType().Where(a => a.Name == NUnit3TestCaseAttributeName).ToList(); - - var testCase1NameArgument = caseAttributes[0].Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - var testCase1NameArgumentValueExpression = testCase1NameArgument.Value as CodePrimitiveExpression; - - testCase1NameArgumentValueExpression.Should().NotBeNull(); - testCase1NameArgumentValueExpression.Value.Should().Be("Simple Scenario Outline(something)"); - - var testCase2NameArgument = caseAttributes[1].Arguments.OfType().FirstOrDefault(a => a.Name == "TestName"); - var testCase2NameArgumentValueExpression = testCase2NameArgument.Value as CodePrimitiveExpression; - - testCase2NameArgumentValueExpression.Should().NotBeNull(); - testCase2NameArgumentValueExpression.Value.Should().Be("Simple Scenario Outline(something else)"); - } - - [Fact] public void NUnit3TestGeneratorProvider_ExampleSetSingleColumn_ShouldSetDescriptionWithVariantNameFromFirstColumn() { diff --git a/Tests/TechTalk.SpecFlow.Specs/Features/Execution/BasicExecution.feature b/Tests/TechTalk.SpecFlow.Specs/Features/Execution/BasicExecution.feature index 2aad4aa2e..880d2b529 100644 --- a/Tests/TechTalk.SpecFlow.Specs/Features/Execution/BasicExecution.feature +++ b/Tests/TechTalk.SpecFlow.Specs/Features/Execution/BasicExecution.feature @@ -4,11 +4,7 @@ Background: Given there is a feature file in the project as """ Feature: Simple Feature - Feature Description - Scenario: Simple Scenario - Scenario Description - Given there is something When I do something Then something should happen diff --git a/changelog.txt b/changelog.txt index 3eaee55dc..eeb75794b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Changes since 3.1.89 Fixes: + Update the default C# skeleton template to use context injection instead of the deprecated ScenarioContext.Current ++ Revert "Replace NUnit.Framework.DescriptionAttribute to TestName in NUnit generator #1225" because of problems with the NUnit Test Adapter Changes since 3.1.86