diff --git a/Gauge.CSharp.Lib/ExecutionContext.cs b/Gauge.CSharp.Lib/ExecutionContext.cs index e3e54be..d4c12f9 100644 --- a/Gauge.CSharp.Lib/ExecutionContext.cs +++ b/Gauge.CSharp.Lib/ExecutionContext.cs @@ -93,11 +93,21 @@ public Specification() { [Serializable()] public class StepDetails { + public StepDetails(String text, bool isFailing, string stackTrace, string errorMessage, + List> parameters) { + this.Text = text; + this.StackTrace = stackTrace; + this.ErrorMessage = errorMessage; + this.IsFailing = isFailing; + this.Parameters = parameters; + } + public StepDetails(String text, bool isFailing, string stackTrace, string errorMessage) { this.Text = text; this.StackTrace = stackTrace; this.ErrorMessage = errorMessage; this.IsFailing = isFailing; + this.Parameters = null; } public StepDetails() {} @@ -121,6 +131,11 @@ public StepDetails() {} * @return Error message if step is failing. */ public String ErrorMessage { get; } = ""; + + /** + * @return All the parameters in the Step + */ + public List> Parameters { get; } } [Serializable] diff --git a/Gauge.CSharp.Lib/Gauge.CSharp.Lib.csproj b/Gauge.CSharp.Lib/Gauge.CSharp.Lib.csproj index 3d9c9f9..74e07be 100644 --- a/Gauge.CSharp.Lib/Gauge.CSharp.Lib.csproj +++ b/Gauge.CSharp.Lib/Gauge.CSharp.Lib.csproj @@ -3,9 +3,9 @@ net6.0;net7.0;net8.0 CSharp bindings for Gauge. Write CSharp step implementation for Gauge specs. https://gauge.org - 0.10.2 - 0.10.2.0 - 0.10.2.0 + 0.10.3 + 0.10.3.0 + 0.10.3.0 getgauge ThoughtWorks Inc. Copyright © ThoughtWorks Inc. 2018 diff --git a/Gauge.CSharp.Lib/Table.cs b/Gauge.CSharp.Lib/Table.cs index 5c7952d..d050b78 100644 --- a/Gauge.CSharp.Lib/Table.cs +++ b/Gauge.CSharp.Lib/Table.cs @@ -4,6 +4,10 @@ * See LICENSE.txt in the project root for license information. *----------------------------------------------------------------*/ using System; +using System.Reflection; +using System.Runtime.Serialization.Json; +using System.IO; +using System.Text; using System.Collections.Generic; using System.Linq; @@ -31,6 +35,40 @@ public Table(List headers) _tableRows = new List(); } + /// + /// Creates a new Table type from JSON string + /// + /// A JSON string representing the Table object. + public Table(string asJSon) + { + var serializer = new DataContractJsonSerializer(typeof(Table)); + using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(asJSon))) + { + var deserializedTable = serializer.ReadObject(ms) as Table; + if (deserializedTable != null) + { + // Use LINQ with reflection to copy properties + typeof(Table).GetFields(BindingFlags.NonPublic | BindingFlags.Instance) + .ToList() + .ForEach(field => field.SetValue(this, field.GetValue(deserializedTable))); + } + else + { + throw new ArgumentException("Invalid JSON string for Table deserialization."); + } + } + } + + public Table FromJSon(string asJSon) + { + var serializer = new DataContractJsonSerializer(typeof(Table)); + using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(asJSon))) + { + var obj = serializer.ReadObject(ms); + return obj as Table; + } + } + /// /// Add a row of data to the table. ///