Skip to content
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

Add step parameters to the execution Context #211

Merged
merged 18 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ gauge run specs
#### Install specific version

```
gauge install dotnet --version 0.5.2
gauge install dotnet --version 0.5.3
```

#### Offline installation
Expand Down
32 changes: 30 additions & 2 deletions src/ExecutionInfoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@


using System;
using System.Collections.Generic;
using System.Linq;
using Gauge.Dotnet.Wrappers;
using Gauge.Messages;
using Gauge.CSharp.Lib;
using Gauge.Dotnet.Processors;
using System.Diagnostics.Tracing;
using Microsoft.VisualBasic;
PiotrNestor marked this conversation as resolved.
Show resolved Hide resolved

namespace Gauge.Dotnet
{
public class ExecutionInfoMapper : IExecutionInfoMapper
{
private Type _executionContextType;
private readonly IActivatorWrapper activatorWrapper;
private readonly ITableFormatter tableFormatter;

public ExecutionInfoMapper(IAssemblyLoader assemblyLoader, IActivatorWrapper activatorWrapper)
{
_executionContextType = assemblyLoader.GetLibType(LibType.ExecutionContext);
this.activatorWrapper = activatorWrapper;
tableFormatter = new TableFormatter(assemblyLoader, activatorWrapper);
}

public dynamic ExecutionContextFrom(ExecutionInfo currentExecutionInfo)
Expand Down Expand Up @@ -61,10 +68,31 @@ private dynamic StepFrom(StepInfo currentStep)
if (currentStep == null || currentStep.Step == null)
return activatorWrapper.CreateInstance(executionContextStepType);

return activatorWrapper.CreateInstance(
var parameters = new List<List<string>>();
foreach (var parameter in currentStep.Step.Parameters) {
if (parameter.ParameterType == Parameter.Types.ParameterType.Static) {
parameters.Add(new List<string> { "Static", parameter.Name, parameter.Value });
}
else if (parameter.ParameterType == Parameter.Types.ParameterType.Dynamic) {
parameters.Add(new List<string> { "Dynamic", parameter.Name, parameter.Value });
}
else if (parameter.ParameterType == Parameter.Types.ParameterType.SpecialString) {
parameters.Add(new List<string> { "Special", parameter.Name, parameter.Value });
}
else if (parameter.ParameterType == Parameter.Types.ParameterType.SpecialTable ||
parameter.ParameterType == Parameter.Types.ParameterType.Table) {
var asJSon = tableFormatter.GetJSON(parameter.Table);
parameters.Add(new List<string> { "Table", parameter.Name, asJSon });
}
}

var inst = activatorWrapper.CreateInstance(
executionContextStepType,
currentStep.Step.ActualStepText, currentStep.IsFailed,
currentStep.StackTrace, currentStep.ErrorMessage);
currentStep.StackTrace, currentStep.ErrorMessage,
parameters);

return inst;
}
}
}
6 changes: 3 additions & 3 deletions src/Gauge.Dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<PackageId>Runner.NetCore30</PackageId>
<Authors>The Gauge Team</Authors>
<Version>0.5.8</Version>
<Version>0.5.9</Version>
<Company>ThoughtWorks Inc.</Company>
<Product>Gauge</Product>
<Description>C# runner for Gauge. https://gauge.org</Description>
Expand All @@ -23,8 +23,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Gauge.CSharp.Lib" Version="0.10.2" />
<PackageReference Include="Grpc.Tools" Version="2.61.0">
<PackageReference Include="Gauge.CSharp.Lib" Version="0.10.3" />
<PackageReference Include="Grpc.Tools" Version="2.65.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "dotnet",
"version": "0.5.8",
"version": "0.5.9",
chadlwilson marked this conversation as resolved.
Show resolved Hide resolved
"description": "C# support for gauge + .NET 6.0/7.0/8.0",
"run": {
"windows": [
Expand Down
5 changes: 3 additions & 2 deletions test/ExecutionInfoMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Gauge.Dotnet.Wrappers;
using Gauge.CSharp.Lib;
using System.Linq;
using System.Collections.Generic;
PiotrNestor marked this conversation as resolved.
Show resolved Hide resolved

namespace Gauge.Dotnet.UnitTests
{
Expand All @@ -23,7 +24,7 @@ public void Setup()
Retries = new ScenarioRetriesInfo{MaxRetries = 0, CurrentRetry = 0} },
CurrentSpec = new SpecInfo {FileName = "dummy.spec", Name = "Dummy Spec", IsFailed = true},
CurrentStep = new StepInfo {IsFailed = true, ErrorMessage = "Dummy Error", StackTrace = "Dummy Stacktrace",
Step = new ExecuteStepRequest {ActualStepText = "Dummy Step Text"}
Step = new ExecuteStepRequest {ActualStepText = "Dummy Step Text"},
PiotrNestor marked this conversation as resolved.
Show resolved Hide resolved
}
};
}
Expand Down Expand Up @@ -77,7 +78,7 @@ public void ShouldMapStepDetails()
var mockActivatorWrapper = new Mock<IActivatorWrapper>();
mockActivatorWrapper.Setup(x => x.CreateInstance(typeof(ExecutionContext.StepDetails),
executionInfo.CurrentStep.Step.ActualStepText, executionInfo.CurrentStep.IsFailed,
executionInfo.CurrentStep.StackTrace, executionInfo.CurrentStep.ErrorMessage)).Verifiable();
executionInfo.CurrentStep.StackTrace, executionInfo.CurrentStep.ErrorMessage, new List<List<string>>())).Verifiable();
new ExecutionInfoMapper(mockAssemblyLoader.Object, mockActivatorWrapper.Object).ExecutionContextFrom(executionInfo);
mockActivatorWrapper.VerifyAll();
}
Expand Down