-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Context injection so that contexts could be shared across…
… multiple scenario implementations
- Loading branch information
Showing
13 changed files
with
455 additions
and
1 deletion.
There are no files selected for viewing
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
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
26 changes: 26 additions & 0 deletions
26
Tests/FeatureTests/ContextInjection/ContextInjection.feature
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Feature: Injecting context into step specifications | ||
As a developer | ||
I would like to have the system automatically inject an instance of any class as defined in the constructor of a step file | ||
So that I don't have to rely on the global shared state and can define the contexts required for each scenario. | ||
|
||
Scenario: Feature with no context | ||
Given a feature which requires no context | ||
Then everything is dandy | ||
|
||
Scenario: Feature with a single context | ||
Given a feature which requires a single context | ||
Then the context is set | ||
|
||
Scenario: Feature with multiple contexts | ||
Given a feature which requires multiple contexts | ||
Then the contexts are set | ||
|
||
Scenario: Feature with recursive contexts | ||
Given a feature which requires a recursive context | ||
Then the context is set | ||
And its sub-context is set | ||
|
||
Scenario: Feature with a dependent context | ||
Given a feature which requires a single context | ||
Then the context is set | ||
And the context was created by the feature with a single context scenario |
109 changes: 109 additions & 0 deletions
109
Tests/FeatureTests/ContextInjection/ContextInjection.feature.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
Tests/FeatureTests/ContextInjection/FeatureWithADependentContextSteps.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace FeatureTests.ContextInjection | ||
{ | ||
[Binding] | ||
public class FeatureWithADependentContextSteps | ||
{ | ||
private readonly SingleContext _context; | ||
|
||
public FeatureWithADependentContextSteps(SingleContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[Given("a feature which requires a dependent context")] | ||
public void GivenAFeatureWhichRequiresADependentContext() | ||
{ | ||
} | ||
|
||
[Then("the context was created by the feature with a single context scenario")] | ||
public void ThenTheContextWasCreatedByTheFeatureWithASingleContextScenario() | ||
{ | ||
Assert.That(_context.WasCreatedBy, Is.EqualTo("Feature With A Single Context")); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Tests/FeatureTests/ContextInjection/FeatureWithARecursiveContextSteps.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace FeatureTests.ContextInjection | ||
{ | ||
[Binding] | ||
public class FeatureWithARecursiveContextSteps | ||
{ | ||
private readonly NestedContext _context; | ||
|
||
public FeatureWithARecursiveContextSteps(NestedContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[Given("a feature which requires a recursive context")] | ||
public void GivenAFeatureWhichRequiresARecursiveContext() | ||
{ | ||
} | ||
|
||
[Then("its sub-context is set")] | ||
public void ThenItsSubContextIsSet() | ||
{ | ||
Assert.That(_context.TheNestedContext, Is.Not.Null); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Tests/FeatureTests/ContextInjection/FeatureWithASingleContextSteps.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace FeatureTests.ContextInjection | ||
{ | ||
[Binding] | ||
public class FeatureWithASingleContextSteps | ||
{ | ||
private readonly SingleContext _context; | ||
|
||
public FeatureWithASingleContextSteps(SingleContext context) | ||
{ | ||
_context = context; | ||
_context.WasCreatedBy = "Feature With A Single Context"; | ||
} | ||
|
||
[Given("a feature which requires a single context")] | ||
public void GivenAFeatureWhichRequiresASingleContext() | ||
{ | ||
} | ||
|
||
[Then("the context is set")] | ||
public void ThenTheContextIsSet() | ||
{ | ||
Assert.That(_context, Is.Not.Null); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Tests/FeatureTests/ContextInjection/FeatureWithMultipleContextsSteps.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace FeatureTests.ContextInjection | ||
{ | ||
[Binding] | ||
public class FeatureWithMultipleContextsSteps | ||
{ | ||
private readonly SingleContext _context1; | ||
private readonly SingleContext _context2; | ||
|
||
public FeatureWithMultipleContextsSteps(SingleContext context1, SingleContext context2) | ||
{ | ||
_context1 = context1; | ||
_context2 = context2; | ||
} | ||
|
||
[Given("a feature which requires multiple contexts")] | ||
public void GivenAFeatureWhichRequiresMultipleContexts() | ||
{ | ||
} | ||
|
||
[Then("the contexts are set")] | ||
public void ThenTheContextsAreSet() | ||
{ | ||
Assert.That(_context1, Is.Not.Null); | ||
Assert.That(_context2, Is.Not.Null); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Tests/FeatureTests/ContextInjection/FeatureWithNoContextSteps.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace FeatureTests.ContextInjection | ||
{ | ||
[Binding] | ||
public class FeatureWithNoContextSteps | ||
{ | ||
[Given("a feature which requires no context")] | ||
public void GivenAFeatureWhichRequiresNoContext() | ||
{ | ||
} | ||
|
||
[Then("everything is dandy")] | ||
public void ThenEverythingIsDandy() | ||
{ | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace FeatureTests.ContextInjection | ||
{ | ||
public class NestedContext | ||
{ | ||
private readonly SingleContext _context; | ||
|
||
public NestedContext(SingleContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public SingleContext TheNestedContext | ||
{ | ||
get { return _context; } | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace FeatureTests.ContextInjection | ||
{ | ||
public class SingleContext | ||
{ | ||
public string WasCreatedBy { get; set; } | ||
} | ||
} |
Oops, something went wrong.