Skip to content

Instantly share code, notes, and snippets.

@MarkBorcherding
Created September 16, 2010 21:19
Show Gist options
  • Save MarkBorcherding/583190 to your computer and use it in GitHub Desktop.
Save MarkBorcherding/583190 to your computer and use it in GitHub Desktop.
Scenario: Supplying invalid data for a provisioning job
Given there is a form to collect provisioning information
When I consider a form to be valid
Then the following fields are required
| field |
| admin first name |
| admin last name |
| admin email address |
| url |
| server |
[Given(@"there is a form to collect provisioning information")]
[When(@"I consider a form to be valid")]
public void nothing_to_do() {}
[Then(@"the following field(?:s)? (?:are|is) required")]
public void the_following_fields_are_required(Table table) {
foreach (var row in table.Rows) {
ModelProperty(LookupFieldName(row["field"])).ShouldBeRequired();
}
}
private static string LookupFieldName(string fieldname) {
switch(fieldname) {
case "admin first name": return "AdminFirstName";
case "admin last name": return "AdminLastName";
case "plan name": return "PlanName";
case "server" : return "Server";
case "admin e-mail ":
case "admin email address": return "AdminEmail";
case "url" :
case "URL" : return "Url";
}
return fieldname;
}
private static PropertyInfo ModelProperty(string propertyName) {
var prop = typeof(ProvisioningViewModel).GetProperty(LookupFieldName(propertyName)) ;
if(prop == null) throw new ApplicationException("No model parameter of " + propertyName + " found.");
return prop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment