Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //First the usage
- //Would be cool to use it for taking out parameters from a table, when I only use a few parameters and don't have a real class
- [Given(@"the following Dealer exists")]
- public void GivenTheFollowingDealerExists(DynamicSpecflowTable dynamicTable )
- {
- string Id = Convert.ToInt32(dynamicTable.FirstRow().Id);
- string Name = dynamicTable.FirstRow().Name;
- // do your stuff
- //...
- }
- //However I am not able to use DynamicSpecflowTable as a parameter
- //Hence I have to do the following
- [Given(@"the following Dealer exists")]
- public void GivenTheFollowingDealerExists(Table table)
- {
- var dynamicTable = new DynamicSpecflowTable(table);
- string Id = Convert.ToInt32(dynamicTable.FirstRow().Id);
- string Name = dynamicTable.FirstRow().Name;
- // do your stuff
- //...
- }
- public class DynamicSpecflowTable
- {
- private readonly List<dynamic> _tableRows;
- public DynamicSpecflowTable(Table table)
- {
- _tableRows = new List<dynamic>();
- foreach (var tableRow in table.Rows)
- {
- _tableRows.Add(new DynamicSpecflowTableRow(tableRow));
- }
- }
- public dynamic this[int i]
- {
- get { return _tableRows[i]; }
- }
- public dynamic FirstRow()
- {
- return _tableRows[0];
- }
- public dynamic SecondRow()
- {
- return _tableRows[1];
- }
- }
- public class DynamicSpecflowTableRow : DynamicObject
- {
- private readonly TableRow _specflowTableRow;
- public DynamicSpecflowTableRow(TableRow specflowTableRow)
- {
- _specflowTableRow = specflowTableRow;
- }
- public override bool TryGetMember(GetMemberBinder binder, out object result)
- {
- string dynamicMethodName = binder.Name;
- result = _specflowTableRow[dynamicMethodName];
- return true;
- }
- }
Add Comment
Please, Sign In to add comment