SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

ColumnCouldNotBeBoundException when using VerifyAllColumnsBound with table property names that have spaces or different casing

Open crackalak opened this issue 4 years ago • 3 comments

SpecFlow Version

3.9.8

Which test runner are you using?

xUnit

Test Runner Version Number

2.4.1

.NET Implementation

.NET 5.0

Project Format of the SpecFlow project

Sdk-style project format

.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

No response

Issue Description

When creating an instance of a type from a table, and using VerifyAllColumnsBound, with property names that have whitespace or different casing to the class properties, the creation fails.

Steps to Reproduce

public class Person 
{
    public string FullName { get; set; }
}

[Given(@"I have the following inputs:")]
public void GivenIHaveTheFollowingInputs(Table table)
{
    var person = table.CreateInstance<Person>(new InstanceCreationOptions { VerifyAllColumnsBound = true });
}

Fails:

Scenario: Test
	Given I have the following inputs:
        | Input         | Value    |
        | Full Name     | Bob      |

TechTalk.SpecFlow.ColumnCouldNotBeBoundException : Member or field Full Name not found

Fails:

Scenario: Test
	Given I have the following inputs:
        | Input         | Value    |
        | FullNaMe      | Bob      |

TechTalk.SpecFlow.ColumnCouldNotBeBoundException : Member or field FullNaMe not found

Works:

Scenario: Test
	Given I have the following inputs:
        | Input         | Value    |
        | FullName      | Bob      |

Link to Repro Project

No response

crackalak avatar Jun 30 '21 15:06 crackalak

I think you need to provide aliases when you want to have spaces in it: https://docs.specflow.org/projects/specflow/en/latest/Bindings/SpecFlow-Assist-Helpers.html#aliasing

SabotageAndi avatar Jul 05 '21 09:07 SabotageAndi

@SabotageAndi aliasing isn't required for spaces:

the names of the columns do not need to match exactly - whitespace and casing is ignored https://docs.specflow.org/projects/specflow/en/latest/Bindings/SpecFlow-Assist-Helpers.html#column-naming

Also, the binding works correctly when using spaces and not specifying VerifyAllColumnsBound

crackalak avatar Jul 05 '21 17:07 crackalak

Furthermore, VerifyAllColumnsBound doesn't support [TableAliases] either.

markhobson avatar Nov 24 '21 17:11 markhobson