This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for Context Injection Scope (#13)
Example for issue #12
- Loading branch information
Showing
5 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
SpecFlow.DependencyInjection.Tests/ContextInjectionScope.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,17 @@ | ||
Feature: ContextInjectionScope | ||
Issue #12: Scoping Context Injection to Scenario Execution Lifetimes | ||
https://github.com/solidtoken/SpecFlow.DependencyInjection/issues/12 | ||
|
||
Scenario: Assert Context Is Scoped To Scenario Execution | ||
The multiply and increase steps are intentionally implemented using different bindings. | ||
Assert that they can operate on the same context (within the scenario executing). | ||
Given I have test context with number 5 | ||
When I multiply the test context number by 2 | ||
And I increase the test context number by 3 | ||
Then the test context number should be 13 | ||
|
||
Scenario: Assert Context Is Scoped To Scenario Execution (No Spill) | ||
Assert that the test context does not spill over to other scenarios. | ||
Note that this assumes this scenario will be run after the above one (ie don't use parallel tests). | ||
Given I have a test context | ||
Then the test context number should be 0 |
140 changes: 140 additions & 0 deletions
140
SpecFlow.DependencyInjection.Tests/ContextInjectionScope.feature.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
SpecFlow.DependencyInjection.Tests/ContextInjectionScopeSteps.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,75 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using TechTalk.SpecFlow; | ||
using Xunit; | ||
|
||
namespace SolidToken.SpecFlow.DependencyInjection.Tests | ||
{ | ||
public class TestContext | ||
{ | ||
public int Number { get; set; } | ||
} | ||
|
||
[Binding] | ||
public class ContextInjectionScopeSteps | ||
{ | ||
private readonly TestContext _context; | ||
|
||
public ContextInjectionScopeSteps(TestContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[Given(@"I have a test context")] | ||
public void GivenIHaveATestContext() | ||
{ | ||
// NOOP | ||
} | ||
|
||
[Given(@"I have test context with number (.*)")] | ||
public void GivenIHaveTestContextWithNumber(int number) | ||
{ | ||
_context.Number = number; | ||
} | ||
|
||
[Then(@"the test context number should be (.*)")] | ||
public void ThenTheTestContextNumberShouldBe(int expected) | ||
{ | ||
Assert.Equal(expected, _context.Number); | ||
} | ||
} | ||
|
||
[Binding] | ||
public class MultiplySteps | ||
{ | ||
private readonly TestContext _context; | ||
|
||
public MultiplySteps(TestContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[When(@"I multiply the test context number by (.*)")] | ||
public void WhenIMultiplyTheTestContextNumberBy(int multiply) | ||
{ | ||
_context.Number *= multiply; | ||
} | ||
} | ||
|
||
[Binding] | ||
public class IncreaseSteps | ||
{ | ||
private readonly TestContext _context; | ||
|
||
public IncreaseSteps(TestContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
[When(@"I increase the test context number by (.*)")] | ||
public void WhenIIncreaseTheTestContextNumberBy(int increase) | ||
{ | ||
_context.Number += increase; | ||
} | ||
} | ||
} |
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