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.
- Loading branch information
Showing
17 changed files
with
546 additions
and
0 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,28 @@ | ||
*.swp | ||
*.*~ | ||
project.lock.json | ||
.DS_Store | ||
*.pyc | ||
nupkg/ | ||
|
||
# Visual Studio Code | ||
.vscode | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Rr]elease/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
[Oo]ut/ | ||
msbuild.log | ||
msbuild.err | ||
msbuild.wrn | ||
|
||
# Visual Studio 2015 | ||
.vs/ |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Solid Token (https://www.solidtoken.nl) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
7 changes: 7 additions & 0 deletions
7
SpecFlow.DependencyInjection.Tests/DependencyInjectionPlugin.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,7 @@ | ||
Feature: DependencyInjectionPlugin | ||
As a developer I want to verify | ||
that the DependencyInjectionPlugin | ||
allows me to use Microsoft.Extensions.DependencyInjection | ||
|
||
Scenario: Test service injection | ||
Then verify that TestService is correctly injected |
113 changes: 113 additions & 0 deletions
113
SpecFlow.DependencyInjection.Tests/DependencyInjectionPlugin.feature.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
SpecFlow.DependencyInjection.Tests/DependencyInjectionPluginSteps.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,35 @@ | ||
using TechTalk.SpecFlow; | ||
using Xunit; | ||
|
||
namespace SolidToken.SpecFlow.DependencyInjection.Tests | ||
{ | ||
[Binding] | ||
public class DependencyInjectionPluginSteps | ||
{ | ||
private readonly ITestService testService; | ||
|
||
public DependencyInjectionPluginSteps(ITestService testService) | ||
{ | ||
this.testService = testService; | ||
} | ||
|
||
[Then(@"verify that TestService is correctly injected")] | ||
public void ThenVerifyThatTestServiceIsCorrectlyInjected() | ||
{ | ||
Assert.True(testService.Verify()); | ||
} | ||
} | ||
|
||
public interface ITestService | ||
{ | ||
bool Verify(); | ||
} | ||
|
||
public class TestService : ITestService | ||
{ | ||
public bool Verify() | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
SpecFlow.DependencyInjection.Tests/SpecFlow.DependencyInjection.Tests.csproj
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,45 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<RootNamespace>SolidToken.SpecFlow.DependencyInjection.Tests</RootNamespace> | ||
<AssemblyName>SolidToken.SpecFlow.DependencyInjection.Tests</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="GitVersionTask" Version="4.0.1-beta1-65"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> | ||
<PackageReference Include="SpecFlow" Version="3.0.224" /> | ||
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.0.224" /> | ||
<PackageReference Include="SpecFlow.xUnit" Version="3.0.224" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SpecFlow.DependencyInjection\SpecFlow.DependencyInjection.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="DependencyInjectionPlugin.feature.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>DependencyInjectionPlugin.feature</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="DependencyInjectionPlugin.feature"> | ||
<Generator>SpecFlowSingleFileGenerator</Generator> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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,29 @@ | ||
using System; | ||
using System.Linq; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TechTalk.SpecFlow; | ||
|
||
namespace SolidToken.SpecFlow.DependencyInjection.Tests | ||
{ | ||
public static class TestDependencies | ||
{ | ||
[ScenarioDependencies] | ||
public static IServiceCollection CreateServices() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
// Add test dependencies | ||
services.AddTransient<ITestService, TestService>(); | ||
|
||
// NOTE: This line is essential so that Microsoft.Extensions.DependencyInjection knows | ||
// about the SpecFlow bindings (something normally BoDi does automatically). | ||
// TODO: Find out if we can make this part of the Plugin | ||
foreach (var type in typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute)))) | ||
{ | ||
services.AddSingleton(type); | ||
} | ||
|
||
return services; | ||
} | ||
} | ||
} |
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,41 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.705 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpecFlow.DependencyInjection", "SpecFlow.DependencyInjection\SpecFlow.DependencyInjection.csproj", "{CACF906A-7230-4E37-984C-739AB1620995}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F6B4EBE9-9995-403D-BC3F-AD26CD6E960F}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
LICENSE = LICENSE | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpecFlow.DependencyInjection.Tests", "SpecFlow.DependencyInjection.Tests\SpecFlow.DependencyInjection.Tests.csproj", "{927C1595-C4EB-4F05-91A7-D2B519B68076}" | ||
ProjectSection(ProjectDependencies) = postProject | ||
{CACF906A-7230-4E37-984C-739AB1620995} = {CACF906A-7230-4E37-984C-739AB1620995} | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{CACF906A-7230-4E37-984C-739AB1620995}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CACF906A-7230-4E37-984C-739AB1620995}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CACF906A-7230-4E37-984C-739AB1620995}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CACF906A-7230-4E37-984C-739AB1620995}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{927C1595-C4EB-4F05-91A7-D2B519B68076}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{927C1595-C4EB-4F05-91A7-D2B519B68076}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{927C1595-C4EB-4F05-91A7-D2B519B68076}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{927C1595-C4EB-4F05-91A7-D2B519B68076}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {CF1B75FE-E67E-486F-9B92-BDBAD9A8B86A} | ||
EndGlobalSection | ||
EndGlobal |
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,27 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using TechTalk.SpecFlow.Bindings; | ||
using TechTalk.SpecFlow.Bindings.Reflection; | ||
|
||
namespace SolidToken.SpecFlow.DependencyInjection | ||
{ | ||
public static class BindingRegistryExtensions | ||
{ | ||
public static IEnumerable<IBindingType> GetBindingTypes(this IBindingRegistry bindingRegistry) | ||
{ | ||
return bindingRegistry.GetStepDefinitions().Cast<IBinding>() | ||
.Concat(bindingRegistry.GetHooks().Cast<IBinding>()) | ||
.Concat(bindingRegistry.GetStepTransformations()) | ||
.Select(b => b.Method.Type) | ||
.Distinct(); | ||
} | ||
|
||
public static IEnumerable<Assembly> GetBindingAssemblies(this IBindingRegistry bindingRegistry) | ||
{ | ||
return bindingRegistry.GetBindingTypes().OfType<RuntimeBindingType>() | ||
.Select(t => t.Type.Assembly) | ||
.Distinct(); | ||
} | ||
} | ||
} |
Oops, something went wrong.