-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix code generation in Reqnroll.Actions.Configuration
- Loading branch information
1 parent
cfc2451
commit 4cc76fa
Showing
3 changed files
with
30 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 0 additions & 204 deletions
204
...s.Configuration/Reqnroll.Actions.Configuration.Generation/UnitTestFeatureGeneratorBase.cs
This file was deleted.
Oops, something went wrong.
51 changes: 29 additions & 22 deletions
51
...Configuration/Reqnroll.Actions.Configuration.Generation/UnitTestTargetFeatureGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
using System.CodeDom; | ||
using Reqnroll; | ||
using Reqnroll.Configuration; | ||
using Reqnroll.Generator; | ||
using Reqnroll.Generator.CodeDom; | ||
using Reqnroll.Generator.Generation; | ||
using Reqnroll.Generator.UnitTestConverter; | ||
using Reqnroll.Generator.UnitTestProvider; | ||
using Reqnroll.Parser; | ||
using System.Linq; | ||
|
||
namespace Reqnroll.Actions.Configuration.Generation | ||
namespace Reqnroll.Actions.Configuration.Generation; | ||
|
||
internal class UnitTestTargetFeatureGenerator : UnitTestFeatureGenerator, IFeatureGenerator | ||
{ | ||
internal class UnitTestTargetFeatureGenerator : UnitTestFeatureGeneratorBase | ||
private readonly string _target; | ||
|
||
public UnitTestTargetFeatureGenerator(IUnitTestGeneratorProvider testGeneratorProvider, | ||
CodeDomHelper codeDomHelper, ReqnrollConfiguration reqnrollConfiguration, | ||
IDecoratorRegistry decoratorRegistry, string target) | ||
: base(testGeneratorProvider, codeDomHelper, reqnrollConfiguration, decoratorRegistry) | ||
{ | ||
private readonly string _target; | ||
_target = target; | ||
TestClassNameFormat += $"_{target.Replace(".", "_")}"; | ||
} | ||
|
||
public UnitTestTargetFeatureGenerator(IUnitTestGeneratorProvider testGeneratorProvider, | ||
CodeDomHelper codeDomHelper, ReqnrollConfiguration reqnrollConfiguration, | ||
IDecoratorRegistry decoratorRegistry, string target) | ||
: base(testGeneratorProvider, codeDomHelper, reqnrollConfiguration, decoratorRegistry) | ||
{ | ||
_target = target; | ||
//base.TestClassNameFormat += $"_{_seleniumReqnrollJsonPart.Browser}"; | ||
TestClassNameFormat += $"_{target.Replace(".", "_")}"; | ||
} | ||
public new CodeNamespace GenerateUnitTestFixture(ReqnrollDocument document, string testClassName, string targetNamespace) | ||
{ | ||
var codeNamespace = base.GenerateUnitTestFixture(document, testClassName, targetNamespace); | ||
|
||
internal override void SetupScenarioInitializeMethod(TestClassGenerationContext generationContext) | ||
var testType = codeNamespace.Types.OfType<CodeTypeDeclaration>().FirstOrDefault(); | ||
if (testType != null) | ||
{ | ||
var scenarioInitializeMethod = generationContext.ScenarioInitializeMethod; | ||
scenarioInitializeMethod.Attributes = MemberAttributes.Public; | ||
scenarioInitializeMethod.Name = "ScenarioInitialize"; | ||
scenarioInitializeMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ScenarioInfo), "scenarioInfo")); | ||
var testRunnerExpression = _scenarioPartHelper.GetTestRunnerExpression(); | ||
scenarioInitializeMethod.Statements.Add(new CodeMethodInvokeExpression(testRunnerExpression, "OnScenarioInitialize", new CodeVariableReferenceExpression("scenarioInfo"))); | ||
scenarioInitializeMethod.Statements.Add(new CodeSnippetStatement($"\t\t\ttestRunner.ScenarioContext[\"__ReqnrollActionsConfigurationTarget\"] = \"{_target}\";")); | ||
var scenarioInitializeMethod = testType.Members.OfType<CodeMemberMethod>() | ||
.FirstOrDefault(m => m.Name == GeneratorConstants.SCENARIO_INITIALIZE_NAME); | ||
if (scenarioInitializeMethod != null) | ||
{ | ||
scenarioInitializeMethod.Statements.Add(new CodeSnippetStatement($"\t\t\ttestRunner.ScenarioContext[\"__ReqnrollActionsConfigurationTarget\"] = \"{_target}\";")); | ||
} | ||
} | ||
|
||
|
||
return codeNamespace; | ||
} | ||
} |