SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.24k stars 754 forks source link

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. #2539

Open golonac opened 2 years ago

golonac commented 2 years ago

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(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 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

SabotageAndi commented 2 years ago

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.