SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

CreateSet<T>(Table, Func<TableRow, T>) uses the original parsed table row value instead of the callback result, if T is a class or record instead of struct.

Open golonac opened this issue 4 years ago • 1 comments

SpecFlow Version

3.9.40

Which test runner are you using?

xUnit

Test Runner Version Number

3.9.40

.NET Implementation

.NET 5.0

Project Format of the SpecFlow project

Classic project format using <PackageReference> tags

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

{ "$schema": "https://specflow.org/specflow-config.json", "runtime": { "missingOrPendingStepsOutcome": "Ignore" } }

Issue Description

CreateSet<T>(Table, Func<TableRow, T>) takes a table row and returns a set item of type T. However, if the type T is a class or record instead of a struct, the returned item is ignored and SpecFlow uses the default parsed item instead, somehow.

Reproduced in .NET 6. The dropdown didn't have it.

Steps to Reproduce

record SearchResult(string Value);

[StepArgumentTransformation] public static IEnumerable<SearchResult> SearchResultTransform(Table table) => table.CreateSet(row => new SearchResult("new value"));

| Value | | original value |

Unexpectedly, CreateSet returns a SearchResult with the original value instead of the new value.

Link to Repro Project

No response

golonac avatar Dec 23 '21 12:12 golonac

We have a unit test to check that we are using the instance we are passing via the Func to CreateSet: https://github.com/SpecFlowOSS/SpecFlow/blob/master/Tests/TechTalk.SpecFlow.RuntimeTests/AssistTests/TableHelperExtensionMethods/CreateSetHelperMethodTests_WithFunc.cs#L21

So I think something from your description and example. Please provide a complete project where we can reproduce the issue, that we can continue to look into this issue.

SabotageAndi avatar Dec 23 '21 14:12 SabotageAndi