-
-
Save darrencauthon/722125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(DynamicItems people) | |
{ | |
var person = people.First(); | |
string Id = Convert.ToInt32(person.Id); | |
string Name = person.Name; | |
// do your stuff | |
//... | |
} | |
//However I am not able to use DynamicItems as a parameter | |
//Hence I have to do the following | |
[Given(@"the following Dealer exists")] | |
public void GivenTheFollowingDealerExists(Table table) | |
{ | |
var people = new DynamicItems(table); | |
string Id = Convert.ToInt32(people.FirstRow().Id); | |
string Name = people.FirstRow().Name; | |
// do your stuff | |
//... | |
} | |
public class DynamicItems : IEnumerable<dynamic> | |
{ | |
private Table table; | |
public DynamicItems(Table table) | |
{ | |
this.table = table; | |
} | |
public IEnumerator<dynamic> GetEnumerator() | |
{ | |
foreach (var tableRow in table.Rows) | |
{ | |
yield return new DynamicItemsRow(row); | |
} | |
yield break; | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
} | |
public class DynamicItemsRow : DynamicObject | |
{ | |
private readonly TableRow _specflowTableRow; | |
public DynamicItemsRow(TableRow specflowTableRow) | |
{ | |
_specflowTableRow = specflowTableRow; | |
} | |
public override bool TryGetMember(GetMemberBinder binder, out object result) | |
{ | |
string dynamicMethodName = binder.Name; | |
result = _specflowTableRow[dynamicMethodName]; | |
return true; | |
} | |
} |
So is it possible to get the first method to work with specflow?
[Given(@"the following Dealer exists")]
public void GivenTheFollowingDealerExists(DynamicItems people)
{
var person = people.First();
string Id = Convert.ToInt32(person.Id);
string Name = person.Name;
// do your stuff
//...
}
By the way IEnumerable is a bit of a problem I just found out:
http://blogs.msdn.com/b/cburrows/archive/2009/02/04/c-dynamic-part-vii.aspx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah like this idea, however my original thought was to make DynamicTable inherit from table and be used as a parameter for steps where Table is used today.
That way when you make tables in your features you don't need a suitable object, but can use the dynamic keyword...