Skip to content

Commit

Permalink
✨ SpecFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
hlaueriksson committed Jul 30, 2016
1 parent 33631d5 commit 3c46893
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 1 deletion.
14 changes: 14 additions & 0 deletions BDD/ConductOfCode/ConductOfCode/ConductOfCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="TechTalk.SpecFlow, Version=2.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41, processorArchitecture=MSIL">
<HintPath>..\packages\SpecFlow.2.1.0\lib\net45\TechTalk.SpecFlow.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Xbehave.Core, Version=2.1.0.0, Culture=neutral, PublicKeyToken=e4957f48888f9fe8, processorArchitecture=MSIL">
<HintPath>..\packages\Xbehave.Core.2.1.0\lib\portable-net45\Xbehave.Core.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -257,12 +261,22 @@
<Compile Include="MSpec\StackSpecs.cs" />
<Compile Include="NSpec\stack_specs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SpecFlow\Stack.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Stack.feature</DependentUpon>
</Compile>
<Compile Include="SpecFlow\StackSteps.cs" />
<Compile Include="SpecsFor\StackSpecs.cs" />
<Compile Include="Xbehave\StackFeature.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="SpecFlow\Stack.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>Stack.feature.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Concordion\Stack.html" />
Expand Down
5 changes: 5 additions & 0 deletions BDD/ConductOfCode/ConductOfCode/SpecFlow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SpecFlow

* Dependencies: NUnit | xUnit | MsTest
* NuGet: https://www.nuget.org/packages/SpecFlow/
* Source: https://github.com/techtalk/SpecFlow
19 changes: 19 additions & 0 deletions BDD/ConductOfCode/ConductOfCode/SpecFlow/Stack.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Stack
In order to support last-in-first-out (LIFO) operations
As an developer
I want to use a stack

Scenario: Empty stack
Given an empty stack
Then it has no elements
And it throws an exception when calling pop
And it throws an exception when calling peek

Scenario: Non empty stack
Given a non empty stack
When calling peek
Then it returns the top element
But it does not remove the top element
When calling pop
Then it returns the top element
And it removes the top element
139 changes: 139 additions & 0 deletions BDD/ConductOfCode/ConductOfCode/SpecFlow/Stack.feature.cs

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

79 changes: 79 additions & 0 deletions BDD/ConductOfCode/ConductOfCode/SpecFlow/StackSteps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using TechTalk.SpecFlow;
using Xunit;

namespace ConductOfCode.SpecFlow
{
[Binding]
public class StackSteps
{
private Stack<int> stack;

private int result;

// Empty

[Given(@"an empty stack")]
public void GivenAnEmptyStack()
{
stack = new Stack<int>();
}

[Then(@"it has no elements")]
public void ThenItHasNoElements()
{
Assert.Empty(stack);
}

[Then(@"it throws an exception when calling pop")]
public void ThenItThrowsAnExceptionWhenCallingPop()
{
Assert.Throws<InvalidOperationException>(() => stack.Pop());
}

[Then(@"it throws an exception when calling peek")]
public void ThenItThrowsAnExceptionWhenCallingPeek()
{
Assert.Throws<InvalidOperationException>(() => stack.Peek());
}

// Not empty

[Given(@"a non empty stack")]
public void GivenANonEmptyStack()
{
stack = new Stack<int>(new[] { 1, 2, 3 });
}

[When(@"calling peek")]
public void WhenCallingPeek()
{
result = stack.Peek();
}

[Then(@"it returns the top element")]
public void ThenItReturnsTheTopElement()
{
Assert.Equal(3, result);
}

[Then(@"it does not remove the top element")]
public void ThenItDoesNotRemoveTheTopElement()
{
Assert.Contains(3, stack);
}

[When(@"calling pop")]
public void WhenCallingPop()
{
result = stack.Pop();
}

[Then(@"it removes the top element")]
public void ThenItRemovesTheTopElement()
{
Assert.DoesNotContain(3, stack);
}
}
}
7 changes: 6 additions & 1 deletion BDD/ConductOfCode/ConductOfCode/app.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
Expand All @@ -8,4 +11,6 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --><unitTestProvider name="xUnit" /></specFlow></configuration>
2 changes: 2 additions & 0 deletions BDD/ConductOfCode/ConductOfCode/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<package id="nspec" version="1.0.7" targetFramework="net46" />
<package id="NUnit" version="2.6.4" targetFramework="net46" />
<package id="Should" version="1.1.20" targetFramework="net46" />
<package id="SpecFlow" version="2.1.0" targetFramework="net46" />
<package id="SpecFlow.xUnit" version="2.1.0" targetFramework="net46" />
<package id="SpecsFor" version="5.0.0" targetFramework="net46" />
<package id="structuremap" version="4.1.3.394" targetFramework="net46" />
<package id="Xbehave" version="2.1.0" targetFramework="net46" />
Expand Down

0 comments on commit 3c46893

Please sign in to comment.