Skip to content

Instantly share code, notes, and snippets.

@joebuschmann
joebuschmann / when_sharing_state_between_bindings_not_that.cs
Created December 29, 2014 18:57
When sharing state between bindings - not that
[Given(@"the new customer")]
public void GivenTheNewCustomer(Table table)
{
var customer = table.CreateInstance<Customer>();
ScenarioContext.Current.Add("customer", customer);
}
[Given(@"the customer's address")]
public void GivenTheCustomerAddress(Table table)
{
@joebuschmann
joebuschmann / when_passing_binding_parameters_part1_code_this.cs
Created December 29, 2014 19:00
When passing binding parameters (part 1) - code this
[When(@"I remove the (\d+)(?:st|nd|rd|th) product")]
public void WhenIRemoveTheProduct(int index)
{
_products.RemoveAt(--index);
}
@joebuschmann
joebuschmann / when_passing_binding_parameters_part1_not_that.cs
Created December 29, 2014 19:01
When passing binding parameters (part 1) - not that
[When(@"I remove the product at index (.*)")]
public void WhenIRemoveTheProductAtIndex(int index)
{
_products.RemoveAt(--index);
}
@joebuschmann
joebuschmann / when_passing_binding_parameters_part2_code_this.cs
Created December 29, 2014 19:03
When passing binding parameters (part 2) - code this
[StepArgumentTransformation(@"from (A-Z|Z-A)")]
public SortOrder SortOrderTransform(string sortOrderPhrase)
{
if (sortOrderPhrase == "Z-A")
return SortOrder.Descending;
return SortOrder.Ascending;
}
[When(@"the products are sorted by name (.*)")]
@joebuschmann
joebuschmann / when_passing_binding_parameters_part2_not_that.cs
Created December 29, 2014 19:04
When passing binding parameters (part 2) - not that
[When(@"the products are sorted by name (.*)")]
public void WhenTheProductsAreSortedByName(string sortOrderText)
{
SortOrder sortOrder = SortOrder.Ascending;
if (sortOrderText == "from A-Z")
sortOrder = SortOrder.Ascending;
else if (sortOrderText == "from Z-A")
sortOrder = SortOrder.Descending;
else
@joebuschmann
joebuschmann / when_using_numeric_identifiers_in_gherkin_code_this.feature
Last active August 29, 2015 14:12
When using numeric identifiers in Gherkin - code this
Background:
Given I have the following products
| Id | Name |
| 45 | Galaxy S5 |
| 46 | iPhone 6 |
| 47 | Nokia Icon |
Scenario: Update price
When I select the Nokia Icon
And update the price to $199.00
@joebuschmann
joebuschmann / when_using_numeric_identifiers_in_gherkin_code_this.cs
Last active August 29, 2015 14:12
When using numeric identifiers in Gherkin - code this
[Given(@"I have the following products")]
public void GivenIHaveTheFollowingProducts(Table table)
{
_productIdLookup = new Dictionary<string, int>();
foreach (var row in table.Rows)
_productIdLookup.Add(row["Name"], row.GetInt32("Id"));
}
[When(@"I select the (.*)")]
@joebuschmann
joebuschmann / when_using_numeric_identifiers_in_gherkin_not_that.feature
Last active August 29, 2015 14:12
When using numeric identifiers in Gherkin - not that
Scenario: Update price
When I choose the product with ID 47
And update the price to $199.00
Then the price should be saved
@joebuschmann
joebuschmann / when_using_numeric_identifiers_in_gherkin_not_that.cs
Last active August 29, 2015 14:12
When using numeric identifiers in Gherkin - not that
[When(@"I choose the product with ID (.*)")]
public void WhenIChooseTheProductWithID(int productId)
{
_selectedProductId = productId;
}
@joebuschmann
joebuschmann / whereis
Last active August 29, 2015 14:13
whereis command for Windows
#!/bin/sh
# whereis command for Windows.
where "$@"