-
Notifications
You must be signed in to change notification settings - Fork 4
Specaid Vs The TableRow
tedLehigh edited this page Feb 8, 2013
·
2 revisions
Same Thing... Using TableRow...
Looks the same But Table Row doesn't get Tagging for free.
Given I have Stores
| Store Id | Name |
| 42 | Red's Brick and Landscaping |
Given I have People
| Emp Id | First Name | Middle Name | Last Name | Years Of Service | Store Id |
| 1 | Fox | C | Smith | 1 | 42 |
Then There are People
| Emp Id | First Name | Middle Name | Last Name | Years Of Service | Store.Name |
| 1 | Fox | C | Smith | 1 | Red's Brick and Landscaping |
You should notice a LOT more code.
[Given(@"I have Stores")]
public void GivenIHaveStores(Table table)
{
var storeRepo = RecallAidHelper.GetReal<StoreRepo>();
foreach (var tableRow in table.Rows)
{
var newStore = new Store();
newStore.StoreId = int.Parse(tableRow["Store Id"]);
newStore.Name = tableRow["Name"];
storeRepo.Save(newStore);
}
}
[Given(@"I have People")]
public void GivenIHavePeople(Table table)
{
var peopleRepo = RecallAidHelper.GetReal<PeopleRepo>();
var storeRepo = RecallAidHelper.GetReal<StoreRepo>();
foreach (var tableRow in table.Rows)
{
var localTableRow = tableRow;
var newPerson = new Person();
newPerson.EmpId = tableRow["Emp Id"];
newPerson.FirstName = tableRow["First Name"];
newPerson.MiddleName = tableRow["Middle Name"];
newPerson.LastName = tableRow["Last Name"];
newPerson.YearsOfService = int.Parse(tableRow["Years Of Service"]);
var store = storeRepo.GetById(localTableRow["Store Id"]);
newPerson.Store = store;
peopleRepo.Save(newPerson);
}
}
[Then(@"There are People")]
public void ThenThereArePeople(Table table)
{
var peopleRepo = RecallAidHelper.GetReal<PeopleRepo>();
foreach (var tableRow in table.Rows)
{
var person = peopleRepo.GetById(tableRow["Emp Id"]);
if (person == null)
Assert.Fail("Person not found");
Assert.AreEqual(tableRow["First Name"],person.FirstName);
Assert.AreEqual(tableRow["Middle Name"],person.MiddleName);
Assert.AreEqual(tableRow["Last Name"],person.LastName);
Assert.AreEqual(int.Parse(tableRow["Years Of Service"]),person.YearsOfService);
Assert.AreEqual(tableRow["Store.Name"],person.Store.Name);
}
}