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.23k stars 752 forks source link

expand property aliases support (#1384) #2581

Closed delta-emil closed 2 years ago

delta-emil commented 2 years ago

This expands the support for [TableAliases] to (hopefully) all places where table columns and object properties are being matched. It was previously only supported in table.CreateInstance<T>() and table.CreateSet<T>()

Fixes #1384

Types of changes

I'm not entirely certain is this is a bug fix or a new feature. The documentation - https://docs.specflow.org/projects/specflow/en/latest/Bindings/SpecFlow-Assist-Helpers.html - doesn't seem to mention that the effect of [TableAliases] is limited to CreateInstance&CreateSet, so taking that at face value, this seems to be a bug fix.

Checklist:

bollhals commented 2 years ago

Out of personal interest, (unrelated specifically to this PR): What is the expected outcome if the TableAliases of two properties are matching the same input name? Only the first one gets assigned or all of them?

delta-emil commented 2 years ago

Out of personal interest, (unrelated specifically to this PR): What is the expected outcome if the TableAliases of two properties are matching the same input name? Only the first one gets assigned or all of them?

When constructing objects (the pre-existing part that I haven't changed), all properties are assigned, and there is a test about it:

        [Fact]
        public void Property_aliases_allow_multiple_property_population()
        {
            var table = new Table("AliasOne", "AliasTwo", "AliasThree");
            table.AddRow("PropertyOne", "PropertyTwo", "PropertyThree");

            var test = table.CreateInstance<AliasedTestObject>();
            test.PropertyOne.Should().Be("PropertyOne");
            test.AnotherPropertyWithSameAlias.Should().Be("PropertyOne");
        }

For the purposes of comparing to existing objects, I made it only use the first property (in no particular order), because it was simplest. Also my thinking was that assigning same alias means you already know they are equal, so no need to check. But now that I'm thinking about it, maybe the more useful thing would be to check all of them.

As you noticed, there's no documentation on the same-alias feature, so I'm not sure.

SabotageAndi commented 2 years ago

Thanks for your contribution to SpecFlow. Please submit your contributions to our SpecFlow Community Heroes program at https://specflow.org/community/submit-a-contribution/