Skip to content

How to create dynamic object with nested children? #24

Description

I have table:

| Key                 | Value    |
| name                | testtest |
| username            | testtest |
| phone               | 33333    |
| website             | www      |
| company.name        | test     |
| company.catchPhrase | test     |
| company.bs          | test     |

I is possible to use table.CreateDynamicInstance(); to create dynamic object with nested children?
Something like json:

{
        "name": "test1232315125",
        "username": "testfdhdfh",
        "phone": "4636346236236",
        "website": "sdgsdgsdgsdgsdg",
        "company": {
            "name": "sdgsdgsdgsdg",
            "catchPhrase": "dgsdghdfjdf",
            "bs": "sdgsdgdfjfd"
        }
}

Activity

  1. ghost closed this as completedon Jul 10, 2019
  2. icnocop commented on Jul 10, 2019

    @icnocop

    Hi.

    Did you find a solution?

  3. ghost reopened this on Jul 12, 2019
  4. marcusoftnet commented on Jul 15, 2019

    @marcusoftnet
    Owner

    Hi,

    yeah... that is not something I forsaw the tool doing. So it's not implemented.

    But I'm thinking that you can do this, pretty easy, using step argument transformations, like I have done here https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/blob/master/SpecFlow.Assist.Dynamic/DynamicStepArgumentTransformations.cs

    Instead of my code you can plug-in the code that you have above.

    [Binding]
        public class Haxy89ArgumentTransformations
        {
            [StepArgumentTransformation]
            public dynamic TransformToEnumerable(Table table)
            {
               // your code from above
            }
    }

    You might want to remove the <StepArgumentTransformation> node from you config file

    <stepAssemblies>
      <stepAssembly assembly="SpecFlow.Assist.Dynamic" /> 
    </stepAssemblies>

    that SpecFlowAssistDynamic is adding when installing.

  5. marcusoftnet commented on Jul 15, 2019

    @marcusoftnet
    Owner

    Ok - but why do you need to do that?

    If you change your signature to

    [StepArgumentTransformation]
    public dynamic BuildInstance(Table table) {}

    You don't need a at all.

    Read up on https://specflow.org/documentation/Step-Argument-Transformations/ for ways to ensure that you only get called for the steps that required transformation. As written above the code will get called for every step with a table.

  6. marcusoftnet commented on Jul 15, 2019

    @marcusoftnet
    Owner

    But you don't need to make it an extension method (using static and this). You can use the [StepArgumentTransformation] way instead.

    Or did I miss something in your original question? You want an extension method?
    Then it's outside the scope of this tool, I'm afraid.

  7. marcusoftnet commented on Jul 15, 2019

    @marcusoftnet
    Owner

    Hmmm - this is something we would need to pair on I'm afraid.

    Pretty sure it could work with a StepArgumentTransformation, but I might be wrong.
    I'll see if I can play around with it later.

    Sorry to stop here and I hope you can find a way.

    Thanks for using my little tool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions