Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten Kools committed Dec 19, 2018
1 parent 2fd1378 commit d65b67e
Show file tree
Hide file tree
Showing 23 changed files with 606 additions and 0 deletions.
19 changes: 19 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '{build}'
pull_requests:
do_not_increment_build_number: true
nuget:
disable_publish_on_pr: true
build_script:
- ps: .\build.ps1
test: off
artifacts:
- path: '.\artifacts\**\*.nupkg'
name: NuGet
deploy:
- provider: NuGet
name: production
api_key:
secure: clUnJlfR9/a4dTu2340OT2XEgmQvFdDRwkqZbt2r+yTq4XAC+L536GpWhkSy4bu1
on:
branch: master
appveyor_repo_tag: true
30 changes: 30 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
#>
function Exec {
[CmdletBinding()]
param(
[Parameter(Position = 0, Mandatory = 1)][scriptblock]$cmd,
[Parameter(Position = 1, Mandatory = 0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
}
}

if (Test-Path ".\artifacts") {
Remove-Item ".\artifacts" -Force -Recurse
}

exec { & dotnet restore .\src\SpecFlow.GenericContainer.sln }

exec { & dotnet build .\src\SpecFlow.GenericContainer.sln -c Release -v q --no-restore /nologo }

exec { & dotnet pack .\src\SpecFlow.GenericContainer\SpecFlow.GenericContainer.csproj -c Release -o (Join-Path $PSScriptRoot "artifacts") --include-symbols --no-build --no-restore /nologo }
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "2.1.400"
}
}
13 changes: 13 additions & 0 deletions src/SpecFlow.GenericContainer.SpecFlowPlugin.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="NUnit" />
<plugins>
<add name="SpecFlow.GenericContainer" type="Runtime" />
</plugins>
</specFlow>
</configuration>
26 changes: 26 additions & 0 deletions src/SpecFlow.GenericContainer.SpecFlowPlugin.Tests/Calculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;

namespace SpecFlow.GenericContainer.SpecFlowPlugin.Tests
{
public class Calculator : ICalculator
{
private readonly Stack<int> _operands = new Stack<int>();

public Calculator()
{

}

public void Enter(int operand)
{
_operands.Push(operand);
}

public void Add()
{
_operands.Push(_operands.Pop() + _operands.Pop());
}

public int Result => _operands.Peek();
}
}
30 changes: 30 additions & 0 deletions src/SpecFlow.GenericContainer.SpecFlowPlugin.Tests/Dependencies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using SimpleInjector;
using SimpleInjector.Lifestyles;
using System;
using System.Linq;
using TechTalk.SpecFlow;

namespace SpecFlow.GenericContainer.SpecFlowPlugin.Tests
{
public static class Dependencies
{
[ScenarioDependencies]
public static IGenericContainer CreateContainer()
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
container.Options.DefaultLifestyle = Lifestyle.Singleton;

container.Register<ICalculator, Calculator>();

foreach (var type in typeof(Dependencies).Assembly
.GetTypes()
.Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
{
container.Register(type);
}

return new SimpleInjectorContainer(container);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: IntegrationTests
In order to test the functionality of the plugin
I want to test whether SimpleInjector is used to resolve dependencies


Scenario Outline: Add two numbers
Given I have entered <operand1> into the calculator
And I have entered <operand2> into the calculator
When I press add
Then the result should be <result> on the screen

Examples:
| operand1 | operand2 | result |
| 50 | 70 | 120 |
| 3 | 33 | 36 |

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SpecFlow.GenericContainer.SpecFlowPlugin.Tests
{
public interface ICalculator
{
void Enter(int operand);
void Add();
int Result { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using SimpleInjector;
using System;

namespace SpecFlow.GenericContainer.SpecFlowPlugin.Tests
{
public class SimpleInjectorContainer : IGenericContainer
{
private readonly Container _container;

public SimpleInjectorContainer(Container container)
{
_container = container;
}

public void Register<TService>(Func<TService> instanceCreator)
where TService : class
{
_container.Register(instanceCreator);
}

public object Resolve(Type bindingType)
{
return _container.GetInstance(bindingType);
}

public TService Resolve<TService>()
where TService : class
{
return _container.GetInstance<TService>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net471</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.2" />
<PackageReference Include="SimpleInjector" Version="4.4.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SpecFlow.GenericContainer.SpecFlowPlugin\SpecFlow.GenericContainer.SpecFlowPlugin.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Features\IntegrationTests.feature.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>IntegrationTests.feature</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="Features\IntegrationTests.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>IntegrationTests.feature.cs</LastGenOutput>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using NUnit.Framework;
using TechTalk.SpecFlow;

namespace SpecFlow.GenericContainer.SpecFlowPlugin.Tests.Steps
{
[Binding]
public class IntegrationTestsSteps
{
private readonly ICalculator _calculator;

public IntegrationTestsSteps(ScenarioContext context, ICalculator calculator)
{
_calculator = calculator;
}

[Given(@"I have entered (.*) into the calculator")]
public void GivenIHaveEnteredIntoTheCalculator(int p0)
{
_calculator.Enter(p0);
}

[When(@"I press add")]
public void WhenIPressAdd()
{
_calculator.Add();
}

[Then(@"the result should be (.*) on the screen")]
public void ThenTheResultShouldBeOnTheScreen(int p0)
{
Assert.That(_calculator.Result, Is.EqualTo(p0));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using BoDi;
using System;
using TechTalk.SpecFlow.Infrastructure;

namespace SpecFlow.GenericContainer.SpecFlowPlugin
{
internal class BindingInstanceResolver : ITestObjectResolver
{
public object ResolveBindingInstance(Type bindingType, IObjectContainer container)
{
var componentContext = container.Resolve<IGenericContainer>();
return componentContext.Resolve(bindingType);
}
}
}
Loading

0 comments on commit d65b67e

Please sign in to comment.