Question

I have a table written in gherkin for an object that I'm passing values to as such:

    | Description | Perils |
    | foo         | 6      |

There are much more values being passed but these two above are taken for example.

In the binding, I'm retrieving this table data and putting it into an object type of Cover. It has a regualr property called Description that will be able to take the string foo from the table and set it to that property fine. However my issue is with Perils. This is not a regular property but rather an IList<string>. I would like to pass the value 6 from Perils to that property somehow, but the AssistHelper might not support that. I've tried changing the header to Peril[0] though I knew that was pointless. Any suggestions?

var tempTable = table.CreateInstance<Cover>();
var thisNeedsToBeSix = tempTable.Perils[0];  
Was it helpful?

Solution

If your SpecFlow tests only use one Peril, then you could create a CoverWrapper instead of using Cover directly e.g.

The binding could look as follows:

[Given(@"Given I entered the following data into the new form:")]
public void x(Table table)
{
    var coverWrapper = table.CreateInstance<CoverWrapper>();
}

The CoverWrapper could look like:

public class CoverWrapper
{
 private Cover cover;

 public CoverWrapper()
 {
  cover = new Cover();
 }

 public string Description
 {
  get
  {
   return cover.Description;
  }
  set
  {
   cover.Description = value;
  }
 }

 public string Peril
 {
  get
  {
   return cover.Perils[0];
  }
  set
  {
   cover.Perils.Add(value);
  }
 }

 public GetCover()
 {
  return cover;
 }
}

You could then call coverWrapper.GetCover() to return an instance of Cover as you want it.

Note that I haven't compiled that code so apologies if something is not quite right.

OTHER TIPS

How about make your perils argument just a string and then use string.Split() to break it up inside your binding?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top