Skip to content

Instantly share code, notes, and snippets.

View gasparnagy's full-sized avatar

Gáspár Nagy gasparnagy

View GitHub Profile
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;
}
@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();
@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
[Binding]
public class CalculatorSteps
{
private readonly CalculatorController controller = new CalculatorController();
...
}
@gasparnagy
gasparnagy / AfterScenarioOnError.cs
Last active June 20, 2019 00:00
Code examples for post: SpecFlow Tips: Collect more information on error (part 1)
[AfterScenario]
public void OnError()
{
if (ScenarioContext.Current.TestError != null)
{
//TODO: save useful information to a file
}
}
@gasparnagy
gasparnagy / OrderedHooks.cs
Last active March 1, 2016 09:29
Code examples for post: SpecFlow Tips: Put your hooks in order
[BeforeScenario(Order = 10)]
public void ResetDatabase()
{
myDatabase.ResetToBaseline();
}
[BeforeScenario("login", Order = 20)]
public void LoginAUser()
{
loginPage.GoTo();
@gasparnagy
gasparnagy / Addition.feature
Last active February 23, 2016 07:11
Examples for blog post "Running SpecFlow scenarios parallel with xUnit 2"
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 |
@gasparnagy
gasparnagy / ShoopingCart.feature
Last active February 9, 2016 21:57
Examples for blog post "SpecFlow tips: Feature file backgrounds -- like them or not"
Feature: Shopping Cart
Scenario: Books can be added to the cart
Given the following books
| Author | Title | Price |
| Martin Fowler | Analysis Patterns | 50.20 |
| Eric Evans | Domain Driven Design | 46.34 |
| Ted Pattison | Inside Windows SharePoint Services | 31.49 |
| Gojko Adzic | Bridging the Communication Gap | 24.75 |
And I am logged in
@gasparnagy
gasparnagy / SetupStepArgumentConverterForAssist.cs
Created December 21, 2015 08:05
Configure SpecFlow v2 Assist Table helpers to use [StepArgumentTransformation] extensions
/// <summary>
/// Sets the step argument conversion infrasuructure as default for CreateSet and CreateInstance
/// </summary>
/// <remarks>
/// This method has to be called once, in a static ctor for example. Note: this way of setting is not
/// supported for parallel execution.
/// </remarks>
private static void SetupStepArgumentConverterValueRetriever()
{
var assistService = TechTalk.SpecFlow.Assist.Service.Instance;