Skip to content

Instantly share code, notes, and snippets.

View gasparnagy's full-sized avatar

Gáspár Nagy gasparnagy

View GitHub Profile
@gasparnagy
gasparnagy / Addition.feature
Last active November 1, 2016 21:28
Sample code for the post "Property-based BDD Examples with SpecFlow and FsCheck"
Scenario: Add two numbers
Given I have entered 1 into the calculator
And I have entered 2 into the calculator
When I press add
Then the result should be 3 on the screen
@gasparnagy
gasparnagy / ShareDataWithBaseClass.cs
Last active February 2, 2017 08:55
Code Examples for Post "SpecFlow Tips: Baseclass or Context Injection"
public class SharedStepsBaseClass : Steps
{
protected UserContext UserContext
{
get
{
var result = (UserContext)ScenarioContext["userContext"];
if (result == null)
{
result = new UserContext();
[Binding]
public class ShareDataWithContextInjectionSteps1 : Steps
{
private readonly UserContext _userContext;
public ShareDataWithContextInjectionSteps1(UserContext userContext)
{
_userContext = userContext;
}
public class SharedStepsBaseClass : Steps
{
protected UserContext UserContext
{
get
{
var result = (UserContext)ScenarioContext["userContext"];
if (result == null)
{
result = new UserContext();
[Binding]
public class ShareDataWithScenarioContextSteps1 : Steps
{
[Given(@"an Administrator has logged in")]
public void GivenAnAdministratorHasLoggedIn()
{
var userName = UserManagement.CreateAdminUser();
UserManagement.Login(userName);
// Save data about the current user into the current scenario context
[Binding]
public class CalculatorSteps
{
private readonly CalculatorController controller = new CalculatorController();
...
}
public class ControllerContext
{
public CalculatorController Controller { get; } = new CalculatorController();
...
}
[Binding]
public class CalculatorSteps
{
public CalculatorSteps(ControllerContext controllerContext)
public class ControllerContext
{
public CalculatorController Controller { get; private set; }
public ControllerContext()
{
var containerBuilder = Dependencies.CreateContainerBuilder(); // invoke runtime dependency configuration
//TODO: apply test-specific customizations if needed
var container = containerBuilder.Build(); // create container
Controller = container.Resolve<CalculatorController>();
public static class TestDependencies
{
[ScenarioDependencies]
public static ContainerBuilder CreateContainerBuilder()
{
// create container with the runtime dependencies
var builder = Dependencies.CreateContainerBuilder();
//TODO: add customizations, stubs required for testing
Feature: Addition
Scenario Outline: Add two numbers
Given I have entered <a> into the calculator
And I have entered <b> into the calculator
When I press add
Then the result should be <result> on the screen
Examples:
| case | a | b | result |