From f3ddbc821c3cd6cfd47f8cd4d5b311328aac7fe8 Mon Sep 17 00:00:00 2001 From: Piotr Nestorow Date: Mon, 19 Aug 2024 09:46:05 +0200 Subject: [PATCH] Add step parameters to the execution Context (#211) * Context has parameters info Signed-off-by: Piotr Nestorow * Context params and table params Signed-off-by: Piotr Nestorow * Context Step params and table params Signed-off-by: Piotr Nestorow * StepFrom parameters update Signed-off-by: Piotr Nestorow * Update to force pipeline Signed-off-by: Piotr Nestorow * ShouldMapStepDetails fix Signed-off-by: Piotr Nestorow * project file update Signed-off-by: Piotr Nestorow * csproj update Signed-off-by: Piotr Nestorow * Context params and table params Signed-off-by: Piotr Nestorow * Context Step params and table params Signed-off-by: Piotr Nestorow * StepFrom parameters update Signed-off-by: Piotr Nestorow * Update to force pipeline Signed-off-by: Piotr Nestorow * ShouldMapStepDetails fix Signed-off-by: Piotr Nestorow * project file update Signed-off-by: Piotr Nestorow * Version update Signed-off-by: Piotr Nestorow * Cosmetic updates Signed-off-by: Piotr Nestorow --------- Signed-off-by: Piotr Nestorow --- README.MD | 2 +- src/ExecutionInfoMapper.cs | 30 ++++++++++++++++++++++++++++-- src/Gauge.Dotnet.csproj | 4 ++-- src/dotnet.json | 2 +- test/ExecutionInfoMapperTests.cs | 3 ++- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/README.MD b/README.MD index a963394..5fd6d06 100644 --- a/README.MD +++ b/README.MD @@ -37,7 +37,7 @@ gauge run specs #### Install specific version ``` -gauge install dotnet --version 0.5.8 +gauge install dotnet --version 0.6.0 ``` #### Offline installation diff --git a/src/ExecutionInfoMapper.cs b/src/ExecutionInfoMapper.cs index 9baaba2..a8a519e 100644 --- a/src/ExecutionInfoMapper.cs +++ b/src/ExecutionInfoMapper.cs @@ -6,9 +6,12 @@ using System; +using System.Collections.Generic; using System.Linq; using Gauge.Dotnet.Wrappers; using Gauge.Messages; +using Gauge.CSharp.Lib; +using Gauge.Dotnet.Processors; namespace Gauge.Dotnet { @@ -16,11 +19,13 @@ 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) @@ -61,10 +66,31 @@ private dynamic StepFrom(StepInfo currentStep) if (currentStep == null || currentStep.Step == null) return activatorWrapper.CreateInstance(executionContextStepType); - return activatorWrapper.CreateInstance( + var parameters = new List>(); + foreach (var parameter in currentStep.Step.Parameters) { + if (parameter.ParameterType == Parameter.Types.ParameterType.Static) { + parameters.Add(new List { "Static", parameter.Name, parameter.Value }); + } + else if (parameter.ParameterType == Parameter.Types.ParameterType.Dynamic) { + parameters.Add(new List { "Dynamic", parameter.Name, parameter.Value }); + } + else if (parameter.ParameterType == Parameter.Types.ParameterType.SpecialString) { + parameters.Add(new List { "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 { "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; } } } \ No newline at end of file diff --git a/src/Gauge.Dotnet.csproj b/src/Gauge.Dotnet.csproj index 61397ae..4430841 100644 --- a/src/Gauge.Dotnet.csproj +++ b/src/Gauge.Dotnet.csproj @@ -5,7 +5,7 @@ net6.0;net7.0;net8.0 Runner.NetCore30 The Gauge Team - 0.5.8 + 0.6.0 ThoughtWorks Inc. Gauge C# runner for Gauge. https://gauge.org @@ -23,7 +23,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/dotnet.json b/src/dotnet.json index 7ddaab9..da2ab82 100644 --- a/src/dotnet.json +++ b/src/dotnet.json @@ -1,6 +1,6 @@ { "id": "dotnet", - "version": "0.5.8", + "version": "0.6.0", "description": "C# support for gauge + .NET 6.0/7.0/8.0", "run": { "windows": [ diff --git a/test/ExecutionInfoMapperTests.cs b/test/ExecutionInfoMapperTests.cs index 8862e00..5d5e18f 100644 --- a/test/ExecutionInfoMapperTests.cs +++ b/test/ExecutionInfoMapperTests.cs @@ -4,6 +4,7 @@ using Gauge.Dotnet.Wrappers; using Gauge.CSharp.Lib; using System.Linq; +using System.Collections.Generic; namespace Gauge.Dotnet.UnitTests { @@ -77,7 +78,7 @@ public void ShouldMapStepDetails() var mockActivatorWrapper = new Mock(); 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>())).Verifiable(); new ExecutionInfoMapper(mockAssemblyLoader.Object, mockActivatorWrapper.Object).ExecutionContextFrom(executionInfo); mockActivatorWrapper.VerifyAll(); }