Skip to content

Commit

Permalink
fix code generation in Reqnroll.Actions.Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Feb 16, 2024
1 parent cfc2451 commit 4cc76fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ private void GeneratorPluginEvents_CustomizeDependencies(object sender, Customiz
e.ObjectContainer.RegisterTypeAs<ReqnrollActionJsonLoader, IReqnrollActionJsonLoader>();
e.ObjectContainer.RegisterTypeAs<ReqnrollActionJsonLocator, IReqnrollActionJsonLocator>();
e.ObjectContainer.RegisterTypeAs<TargetIdentifier, ITargetIdentifier>();
//TODO: the MultiFeatureGeneratorProvider is disabled temporarily to be able to make the code build
//e.ObjectContainer.RegisterTypeAs<MultiFeatureGeneratorProvider, IFeatureGeneratorProvider>();
e.ObjectContainer.RegisterTypeAs<MultiFeatureGeneratorProvider, IFeatureGeneratorProvider>();
}
}
}

This file was deleted.

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;
}
}

0 comments on commit 4cc76fa

Please sign in to comment.