Skip to content

Commit

Permalink
Merge branch 'master' of github.com:techtalk/SpecFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Jun 4, 2010
2 parents eb28e80 + 2391181 commit 03a9852
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Runtime/Bindings/StepMethodBinding.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
Expand Down Expand Up @@ -121,7 +122,7 @@ public object InvokeAction(object[] arguments, ITestTracer testTracer, out TimeS
{
object result;
Stopwatch stopwatch = new Stopwatch();
using (new CultureInfoScope(FeatureContext.Current.FeatureInfo.Language))
using (CreateCultureInfoScope())
{
stopwatch.Start();
result = BindingAction.DynamicInvoke(arguments);
Expand All @@ -148,6 +149,16 @@ public object InvokeAction(object[] arguments, ITestTracer testTracer, out TimeS
}
}

private CultureInfoScope CreateCultureInfoScope()
{
var cultureInfo = CultureInfo.CurrentCulture;
if (FeatureContext.Current != null)
{
cultureInfo = FeatureContext.Current.FeatureInfo.Language;
}
return new CultureInfoScope(cultureInfo);
}

internal void PreserveStackTrace(Exception ex)
{
typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(ex, new object[0]);
Expand Down
25 changes: 25 additions & 0 deletions Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Addition
As a developer
I would like to be able to hook into pre and post conditions in SpecFlow
So that I can set up and teardown my scenario accordingly

Scenario: Hooking into pre conditions for Test Runs in SpecFlow
Given the scenario is running
Then the BeforeTestRun hook should have been executed

Scenario: Hooking into pre conditions for Features in SpecFlow
Given the scenario is running
Then the BeforeFeature hook should have been executed

Scenario: Hooking into pre conditions for Scenarios in SpecFlow
Given the scenario is running
Then the BeforeScenario hook should have been executed

Scenario: Hooking into pre conditions for ScenarioBlocks in SpecFlow
Given the scenario is running
Then the BeforeScenarioBlock hook should have been executed

Scenario: Hooking into pre conditions for Steps in SpecFlow
Given the scenario is running
Then the BeforeStep hook should have been executed

132 changes: 132 additions & 0 deletions Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooks.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 121 additions & 0 deletions Tests/FeatureTests/BeforeAfterHooks/BeforeAfterHooksSteps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using NUnit.Framework;

namespace TechTalk.SpecFlow.FeatureTests.BeforeAfterHooks
{
[Binding]
public class BeforeAfterHooksSteps
{
private static bool _beforeTestRunHookExecuted;
private static bool _beforeFeatureHookExecuted;
private bool _beforeScenarioHookExecuted;
private bool _beforeScenarioBlockHookExecuted;
private bool _beforeStepHookExecuted;
private static bool _afterFeatureHookExecuted;
private static bool _afterScenarioHookExecuted;
private static bool _afterScenarioBlockHookExecuted;
private static bool _afterStepHookExecuted;

[BeforeTestRun]
public static void BeforeTestRun()
{
_beforeTestRunHookExecuted = true;
}

[BeforeFeature]
public static void BeforeFeature()
{
_beforeFeatureHookExecuted = true;
}

[BeforeScenario]
public void BeforeScenario()
{
_beforeScenarioHookExecuted = true;
}

[BeforeScenarioBlock]
public void BeforeScenarioBlock()
{
_beforeScenarioBlockHookExecuted = true;
}

[BeforeStep]
public void BeforeStep()
{
_beforeStepHookExecuted = true;
}

[AfterTestRun]
public static void AfterTestRun()
{
// Testing AfterTestRun is tricky as it would probably involve manipulating the AppDomain
// Its been manually tested and verified that this code block is hit, but if something changes
// which stops it from being called, we'll never know...

Assert.That(_afterFeatureHookExecuted, Is.True);
Assert.That(_afterScenarioHookExecuted, Is.True);
Assert.That(_afterScenarioBlockHookExecuted, Is.True);
Assert.That(_afterStepHookExecuted, Is.True);
}

[AfterFeature]
public static void AfterFeature()
{
_afterFeatureHookExecuted = true;
}

[AfterScenario]
public void AfterScenario()
{
_afterScenarioHookExecuted = true;
}

[AfterScenarioBlock]
public void AfterScenarioBlock()
{
_afterScenarioBlockHookExecuted = true;
}

[AfterStep]
public void AfterStep()
{
_afterStepHookExecuted = true;
}

[Given(@"the scenario is running")]
public void GivenTheScenarioIsRunning()
{
}

[Then(@"the BeforeTestRun hook should have been executed")]
public void ThenTheBeforeTestRunHookShouldHaveBeenExecuted()
{
Assert.That(_beforeTestRunHookExecuted, Is.True);
}

[Then(@"the BeforeFeature hook should have been executed")]
public void ThenTheBeforeFeatureHookShouldHaveBeenExecuted()
{
Assert.That(_beforeFeatureHookExecuted, Is.True);
}

[Then(@"the BeforeScenario hook should have been executed")]
public void ThenTheBeforeScenarioHookShouldHaveBeenExecuted()
{
Assert.That(_beforeScenarioHookExecuted, Is.True);
}

[Then(@"the BeforeScenarioBlock hook should have been executed")]
public void ThenTheBeforeScenarioBlockHookShouldHaveBeenExecuted()
{
Assert.That(_beforeScenarioBlockHookExecuted, Is.True);
}

[Then(@"the BeforeStep hook should have been executed")]
public void ThenTheBeforeStepHookShouldHaveBeenExecuted()
{
Assert.That(_beforeStepHookExecuted, Is.True);
}
}
}
43 changes: 43 additions & 0 deletions Tests/FeatureTests/FeatureTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -51,6 +66,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BeforeAfterHooks\BeforeAfterHooks.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>BeforeAfterHooks.feature</DependentUpon>
</Compile>
<Compile Include="BeforeAfterHooks\BeforeAfterHooksSteps.cs" />
<Compile Include="CallingStepsFromStepDefinitions\CallingStepsFromStepDefinition.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -103,6 +124,10 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="BeforeAfterHooks\BeforeAfterHooks.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>BeforeAfterHooks.feature.cs</LastGenOutput>
</None>
<None Include="CallingStepsFromStepDefinitions\CallingStepsFromStepDefinition.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>CallingStepsFromStepDefinition.feature.cs</LastGenOutput>
Expand All @@ -120,6 +145,24 @@
<LastGenOutput>StepArgumentTransformation.feature.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 03a9852

Please sign in to comment.