-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3a30cd
commit 1895ebe
Showing
21 changed files
with
225 additions
and
1,008 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace CSF.Screenplay | ||
{ | ||
/// <summary> | ||
/// Simple key class for a combination of Scenario & Feature contexts. | ||
/// </summary> | ||
internal sealed class ScenarioAndFeatureContextKey : IEquatable<ScenarioAndFeatureContextKey> | ||
{ | ||
readonly int cachedHashCode; | ||
|
||
/// <summary>Gets the scenario</summary> | ||
public ScenarioContext Scenario { get; } | ||
|
||
/// <summary>Gets the feature</summary> | ||
public FeatureContext Feature { get; } | ||
|
||
/// <inheritdoc/> | ||
public override bool Equals(object obj) => Equals(obj as ScenarioAndFeatureContextKey); | ||
|
||
/// <inheritdoc/> | ||
public bool Equals(ScenarioAndFeatureContextKey other) | ||
{ | ||
if(ReferenceEquals(this, other)) return true; | ||
if(ReferenceEquals(null, other)) return false; | ||
|
||
return ReferenceEquals(Scenario, other.Scenario) && ReferenceEquals(Feature, other.Feature); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override int GetHashCode() => cachedHashCode; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="ScenarioAndFeatureContextKey"/>. | ||
/// </summary> | ||
/// <param name="scenario">The scenario</param> | ||
/// <param name="feature">The feature</param> | ||
/// <exception cref="ArgumentNullException">If either parameter is <see langword="null" />.</exception> | ||
public ScenarioAndFeatureContextKey(ScenarioContext scenario, FeatureContext feature) | ||
{ | ||
if(scenario is null) throw new ArgumentNullException(nameof(scenario)); | ||
if(feature is null) throw new ArgumentNullException(nameof(feature)); | ||
|
||
Scenario = scenario; | ||
Feature = feature; | ||
cachedHashCode = scenario.GetHashCode() ^ feature.GetHashCode(); | ||
} | ||
} | ||
} |
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,59 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace CSF.Screenplay | ||
{ | ||
/// <summary> | ||
/// SpecFlow binding which uses hooks to coordinate the relevant <see cref="Screenplay"/> & <see cref="IPerformance"/> event invokers. | ||
/// </summary> | ||
[Binding] | ||
public class ScreenplayBinding | ||
{ | ||
readonly IServiceProvider serviceProvider; | ||
|
||
/// <summary> | ||
/// Executed before each scenario. | ||
/// </summary> | ||
[BeforeScenario] | ||
public void BeforeScenario() | ||
{ | ||
var performance = serviceProvider.GetRequiredService<IPerformance>(); | ||
performance.BeginPerformance(); | ||
} | ||
|
||
/// <summary> | ||
/// Executed after each scenario. | ||
/// </summary> | ||
[AfterScenario] | ||
public void AfterScenario() | ||
{ | ||
var performance = serviceProvider.GetRequiredService<IPerformance>(); | ||
var scenarioContext = serviceProvider.GetRequiredService<ScenarioContext>(); | ||
var success = scenarioContext.TestError is null; | ||
performance.FinishPerformance(success); | ||
} | ||
|
||
/// <summary> | ||
/// Executed before a test run. | ||
/// </summary> | ||
[BeforeTestRun] | ||
public static void BeforeTestRun() => ScreenplayPlugin.Screenplay.BeginScreenplay(); | ||
|
||
/// <summary> | ||
/// Executed after a test run. | ||
/// </summary> | ||
[AfterTestRun] | ||
public static void AfterTestRun() => ScreenplayPlugin.Screenplay.CompleteScreenplay(); | ||
|
||
/// <summary> | ||
/// Initialises a new instance of <see cref="ScreenplayBinding"/>. | ||
/// </summary> | ||
/// <param name="serviceProvider">The service provider</param> | ||
/// <exception cref="ArgumentNullException">If the <paramref name="serviceProvider"/> is <see langword="null" />.</exception> | ||
public ScreenplayBinding(IServiceProvider serviceProvider) | ||
{ | ||
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using CSF.Screenplay.Actors; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace CSF.Screenplay | ||
{ | ||
/// <summary> | ||
/// Convenience subclass of <c>TechTalk.SpecFlow.Steps</c> making it possible to call <c>Given, When & Then</c> | ||
/// methods without conflicting with the built-in methods of the same names. | ||
/// </summary> | ||
public class ScreenplaySteps : Steps | ||
{ | ||
/// <summary> | ||
/// Returns the actor instance, as an <see cref="ICanPerformGiven"/>, in order to perform precondition actions. | ||
/// </summary> | ||
/// <param name="actor">The actor.</param> | ||
public ICanPerformGiven Given(Actor actor) => PerformanceStarter.Given(actor); | ||
|
||
/// <summary> | ||
/// Returns the actor instance, as an <see cref="ICanPerformWhen"/>, in order to perform actions which exercise the | ||
/// system under test. | ||
/// </summary> | ||
/// <param name="actor">The actor.</param> | ||
public ICanPerformWhen When(Actor actor) => PerformanceStarter.When(actor); | ||
|
||
/// <summary> | ||
/// Returns the actor instance, as an <see cref="ICanPerformThen"/>, in order to get information which are required to | ||
/// make assertions that the scenario has completed successfully. | ||
/// </summary> | ||
/// <param name="actor">The actor.</param> | ||
public ICanPerformThen Then(Actor actor) => PerformanceStarter.Then(actor); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.