Last active
August 29, 2015 14:07
-
-
Save joebuschmann/91a23c5066009538135b to your computer and use it in GitHub Desktop.
Implementation of Specflow's default calculator feature using a context object to maintain state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Binding] | |
public class CalculatorSteps | |
{ | |
private readonly CalculatorContext _calculatorContext; | |
public ContextObjectSteps(CalculatorContext calculatorContext) | |
{ | |
_calculatorContext = calculatorContext; | |
} | |
[Given(@"I have entered (.*) into the calculator")] | |
public void GivenIHaveEnteredIntoTheCalculator(int num) | |
{ | |
_calculatorContext.Values.Add(num); | |
} | |
[When(@"I press add")] | |
public void WhenIPressAdd() | |
{ | |
var calculatorService = new CalculatorService(); | |
_calculatorContext.Result = calculatorService.Add(_calculatorContext.Values); | |
} | |
[Then(@"the result should be (.*) on the screen")] | |
public void ThenTheResultShouldBeOnTheScreen(int expectedResult) | |
{ | |
Assert.That(_calculatorContext.Result, Is.EqualTo(expectedResult)); | |
} | |
} | |
public class CalculatorContext | |
{ | |
public CalculatorContext() | |
{ | |
Values = new List<int>(); | |
} | |
public List<int> Values { get; set; } | |
public int Result { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment