Skip to content

Commit

Permalink
revert #1874 (#1931)
Browse files Browse the repository at this point in the history
  • Loading branch information
SabotageAndi committed Apr 1, 2020
1 parent db3978c commit cde5f07
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 339 deletions.
Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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<string> 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<string> arguments, IEnumerable<string> tags, bool isIgnored);
void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle);
void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored);
void SetTestMethodAsRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string exampleSetName, string variantName, IEnumerable<KeyValuePair<string, string>> arguments);
}
}
Expand Up @@ -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
Expand All @@ -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<string> arguments, IEnumerable<string> tags, bool isIgnored)
public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored)
{
//MsTest does not support row tests... :(
throw new NotSupportedException();
Expand Down
Expand Up @@ -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))
{
Expand Down
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string> featureCategories)
Expand Down Expand Up @@ -101,43 +98,34 @@ 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<string> scenarioCategories)
{
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<string> arguments, IEnumerable<string> tags, bool isIgnored)
public void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> 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
Expand All @@ -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());
}

Expand Down
Expand Up @@ -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<string> arguments, IEnumerable<string> tags, bool isIgnored)
public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored)
{
//TODO: better handle "ignored"
if (isIgnored)
Expand Down Expand Up @@ -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<string> scenarioCategories)
Expand Down
17 changes: 0 additions & 17 deletions Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorBasicsTests.cs
Expand Up @@ -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()
{
Expand Down
22 changes: 0 additions & 22 deletions Tests/TechTalk.SpecFlow.GeneratorTests/TestGeneratorTestsBase.cs
Expand Up @@ -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 <first> into the calculator
And I have entered <second> into the calculator
When I press add
Then the result should be <result> on the screen
Examples: ExName
This is desc
| first | second | result |
| 10 | 10 | 20 |
| 50 | 70 | 120 |
",
projectRelativeFolderPath);
}
}
}

0 comments on commit cde5f07

Please sign in to comment.