Skip to content

Commit

Permalink
Merge pull request #43 from system-verification/dynamic-params
Browse files Browse the repository at this point in the history
Add parameters to StepDetails
  • Loading branch information
sriv committed Jul 2, 2024
2 parents 9d5ca8a + 5224352 commit c61c471
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Gauge.CSharp.Lib/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,21 @@ public Specification() {

[Serializable()]
public class StepDetails {
public StepDetails(String text, bool isFailing, string stackTrace, string errorMessage,
List<List<string>> 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() {}
Expand All @@ -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<List<string>> Parameters { get; }
}

[Serializable]
Expand Down
6 changes: 3 additions & 3 deletions Gauge.CSharp.Lib/Gauge.CSharp.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Description>CSharp bindings for Gauge. Write CSharp step implementation for Gauge specs. https://gauge.org</Description>
<Version>0.10.2</Version>
<AssemblyVersion>0.10.2.0</AssemblyVersion>
<FileVersion>0.10.2.0</FileVersion>
<Version>0.10.3</Version>
<AssemblyVersion>0.10.3.0</AssemblyVersion>
<FileVersion>0.10.3.0</FileVersion>
<Authors>getgauge</Authors>
<Company>ThoughtWorks Inc.</Company>
<Copyright>Copyright © ThoughtWorks Inc. 2018</Copyright>
Expand Down
38 changes: 38 additions & 0 deletions Gauge.CSharp.Lib/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -31,6 +35,40 @@ public Table(List<string> headers)
_tableRows = new List<TableRow>();
}

/// <summary>
/// Creates a new Table type from JSON string
/// </summary>
/// <param name="asJson">A JSON string representing the Table object.</param>
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;
}
}

/// <summary>
/// Add a row of data to the table.
/// </summary>
Expand Down

0 comments on commit c61c471

Please sign in to comment.