Skip to content

Instantly share code, notes, and snippets.

@joebuschmann
Last active August 29, 2015 14:07
Show Gist options
  • Save joebuschmann/76c20ca025b6f3bd469c to your computer and use it in GitHub Desktop.
Save joebuschmann/76c20ca025b6f3bd469c to your computer and use it in GitHub Desktop.
Implementation of Specflow's default calculator feature using private members to maintain state
[Binding]
public class CalculatorSteps
{
private readonly List<int> _values = new List<int>();
private int _result;
[Given(@"I have entered (.*) into the calculator")]
public void GivenIHaveEnteredIntoTheCalculator(int num)
{
_values.Add(num);
}
[When(@"I press add")]
public void WhenIPressAdd()
{
var calculatorService = new CalculatorService();
_result = calculatorService.Add(_values);
}
[Then(@"the result should be (.*) on the screen")]
public void ThenTheResultShouldBeOnTheScreen(int expectedResult)
{
Assert.That(_result, Is.EqualTo(expectedResult));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment