Skip to content

Instantly share code, notes, and snippets.

@joebuschmann
joebuschmann / CalculatorService.cs
Created September 29, 2014 22:49
Simple implementation of Specflow's calculator service
public class CalculatorService
{
public int Add(IEnumerable<int> numbers)
{
return numbers.Sum();
}
}
@joebuschmann
joebuschmann / specflow_comparetoinstance_generic.cs
Last active August 29, 2015 14:07
Specflow CompareToInstance<T>() with generic parameter
public static void CompareToInstance<T>(this Table table, T instance)
{
AssertThatTheInstanceExists(instance);
var instanceTable = TEHelpers.GetTheProperInstanceTable(table, typeof(T));
var differences = FindAnyDifferences(instanceTable, instance);
if (ThereAreAnyDifferences(differences))
ThrowAnExceptionThatDescribesThoseDifferences(differences);
@joebuschmann
joebuschmann / specflow_comparetoinstance.cs
Created October 5, 2014 20:39
Specflow CompareToInstance<T>() without generic parameter
public static void CompareToInstance(this Table table, object instance)
{
AssertThatTheInstanceExists(instance);
var instanceTable = TEHelpers.GetTheProperInstanceTable(table, instance.GetType());
var differences = FindAnyDifferences(instanceTable, instance);
if (ThereAreAnyDifferences(differences))
ThrowAnExceptionThatDescribesThoseDifferences(differences);
@joebuschmann
joebuschmann / enum_values.feature
Last active August 29, 2015 14:07
Gherkin example for limiting argument options to enum values
Scenario: Limit argument options to enum values
Given the following devices
| Product Name |
| Galaxy IV |
| iPhone |
| Windows Phone |
| Note |
| Kindle |
When I sort by product name ascending
Then they should be in the following order
@joebuschmann
joebuschmann / enum_values.cs
Last active August 29, 2015 14:07
Binding example for limiting argument options to enum values
[When(@"I sort by product name (ascending|descending)")]
public void WhenISortByProductName(SortOrder sortOrder)
{
_products.Sort((s1, s2) =>
{
if (sortOrder == SortOrder.Descending)
return s1.ProductName.CompareTo(s2.ProductName) * (-1);
return s1.ProductName.CompareTo(s2.ProductName);
});
@joebuschmann
joebuschmann / step_argument_transform.cs
Last active August 29, 2015 14:07
Example of using a step argument transform to convert text to an enum value
[StepArgumentTransformation(@"from (A-Z|Z-A)")]
public SortOrder SortOrderTransform(string sortOrderPhrase)
{
if (sortOrderPhrase == "Z-A")
return SortOrder.Descending;
return SortOrder.Ascending;
}
[When(@"I sort by product name (.*)")]
@joebuschmann
joebuschmann / ordinal_text.feature
Last active August 29, 2015 14:07
Gherkin example for converting oridinal text to integers
Scenario: Convert 1st, 2nd, etc to integral values
Given the following devices
| Product Name |
| Galaxy IV |
| iPhone |
| Windows Phone |
| Note |
| Kindle |
| Blackberry Storm |
| iPad |
@joebuschmann
joebuschmann / ordinal_text.cs
Last active August 29, 2015 14:07
Step binding example for converting oridinal text to integers
[When(@"I remove the (\d+)(?:st|nd|rd|th) item")]
public void WhenIRemoveTheItem(int index)
{
_products.RemoveAt(--index);
}
@joebuschmann
joebuschmann / singular_or_plural.feature
Created October 14, 2014 12:49
Gherkin example for supporting singular or plural wording
Scenario: Support singular and plural wording
Given the following devices
| Product Name |
| Galaxy IV |
| iPhone |
And the following device
| Product Name |
| Windows Phone |
@joebuschmann
joebuschmann / singular_or_plural.cs
Created October 14, 2014 12:51
Step binding example for supporting singular or plural wording
[Given(@"the following devices?")]
public void GivenTheFollowingDevices(Table table)
{
_products = table.CreateSet<Product>().ToList();
}