-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added draft of transformations #129
Draft
Oleg-Mozhey
wants to merge
1
commit into
main
Choose a base branch
from
feature/transformations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
Behavioral.Automation.Transformations/Behavioral.Automation.Transformations.csproj
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Configurations>Debug;Release;Test;Dev;Prod</Configurations> | ||
<Platforms>AnyCPU</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Behavioral.Automation" Version="1.9.0" /> | ||
<PackageReference Include="Scriban" Version="5.4.1" /> | ||
<PackageReference Include="SpecFlow" Version="3.9.69" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Behavioral.Automation.Configs\Behavioral.Automation.Configs.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
Behavioral.Automation.Transformations/ScribanFunctions/ConfigFunction.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Behavioral.Automation.Configs; | ||
using Scriban.Runtime; | ||
|
||
namespace Behavioral.Automation.Transformations.ScribanFunctions; | ||
|
||
public class ConfigFunction : ScriptObject | ||
{ | ||
public static string Config(string configName) | ||
{ | ||
return ConfigManager.GetConfig(configName); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using Behavioral.Automation.Transformations.ScribanFunctions; | ||
using Scriban; | ||
using Scriban.Runtime; | ||
using TechTalk.SpecFlow; | ||
using TechTalk.SpecFlow.Infrastructure; | ||
|
||
namespace Behavioral.Automation.Transformations; | ||
|
||
[Binding] | ||
public class Transformations | ||
{ | ||
private readonly ConfigFunction _configFunction; | ||
private readonly ScenarioContext _scenarioContext; | ||
private static readonly List<IScriptObject> customFunctions = new List<IScriptObject>(); | ||
private readonly SpecFlowOutputHelper _specFlowOutputHelper; | ||
|
||
public Transformations(ConfigFunction configFunction, ScenarioContext scenarioContext, SpecFlowOutputHelper specFlowOutputHelper) | ||
{ | ||
_configFunction = configFunction; | ||
_scenarioContext = scenarioContext; | ||
_specFlowOutputHelper = specFlowOutputHelper; | ||
} | ||
|
||
public static void AddFunction(IScriptObject function) | ||
{ | ||
customFunctions.Add(function); | ||
} | ||
|
||
[StepArgumentTransformation] | ||
public string ProcessStringTransformations(string value) | ||
{ | ||
var specflowContextVariables = new ScriptObject(); | ||
if (_scenarioContext.Any()) | ||
{ | ||
foreach (var item in _scenarioContext) | ||
{ | ||
specflowContextVariables.Add(item.Key, item.Value); | ||
} | ||
} | ||
|
||
var context = new TemplateContext(); | ||
|
||
context.PushGlobal(specflowContextVariables); | ||
context.PushGlobal(_configFunction); | ||
foreach (var customFunction in customFunctions) | ||
{ | ||
context.PushGlobal(customFunction); | ||
} | ||
|
||
var template = Template.Parse(value); | ||
var result = template.Render(context); | ||
return result; | ||
} | ||
|
||
[StepArgumentTransformation] | ||
public Table ProcessTableTransformations(Table table) | ||
{ | ||
var newTable = table; | ||
if (table.Rows.Count > 0) | ||
{ | ||
foreach (var row in newTable.Rows) | ||
{ | ||
foreach (var value in row) | ||
{ | ||
var template = Template.Parse(value.Value); | ||
var result = template.Render(); | ||
row[value.Key] = result; | ||
} | ||
} | ||
} | ||
|
||
return newTable; | ||
} | ||
|
||
[Given("save variable \"(.*)\" with value:")] | ||
[Given("save variable \"(.*)\" with value \"(.*)\"")] | ||
public void SaveStringIntoContext(string variableName, string stringToSave) | ||
{ | ||
_scenarioContext.Add(variableName, stringToSave); | ||
_specFlowOutputHelper.WriteLine($"Saved '{stringToSave}' with key '{variableName}' in scenario context"); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant Configurations