Skip to content

Commit

Permalink
Discovery error for SpecFlow v3.7 (missing method exception) (Issue #69)
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Feb 22, 2021
1 parent a462481 commit d39e4f7
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override void RegisterGlobalContainerDefaults(ObjectContainer globalConta
{
base.RegisterGlobalContainerDefaults(globalContainer);
globalContainer.RegisterInstanceAs(_loadContext);
globalContainer.RegisterTypeAs<LoadContextPluginLoader, IRuntimePluginLoader>();
ContainerRegisterTypeAs<LoadContextPluginLoader, IRuntimePluginLoader>(globalContainer);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Deveroom.VisualStudio.SpecFlowConnector/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
[assembly: InternalsVisibleTo("Deveroom.VisualStudio.SpecFlow30P220NetCoreConnector.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009860521716FB3C7979667BA43A99966045B6DA9555577697C60033FEEA939BB0E88A44EABD5F235A74CD0960151CE15CC139AF3EA1FA3AC67622593350870062FAF5153F5DE8A6AE4AF9EF8B8280E7AD110E5C534EE28F727CFE05A2C0AE43F431190FCA826E73C50B6626EDAA85BA940E325BD989CE48067CDA2C0169F3EA1")]
[assembly: InternalsVisibleTo("Deveroom.VisualStudio.SpecFlow31NetFwConnector.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009860521716FB3C7979667BA43A99966045B6DA9555577697C60033FEEA939BB0E88A44EABD5F235A74CD0960151CE15CC139AF3EA1FA3AC67622593350870062FAF5153F5DE8A6AE4AF9EF8B8280E7AD110E5C534EE28F727CFE05A2C0AE43F431190FCA826E73C50B6626EDAA85BA940E325BD989CE48067CDA2C0169F3EA1")]
[assembly: InternalsVisibleTo("Deveroom.VisualStudio.SpecFlow31NetCoreConnector.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009860521716FB3C7979667BA43A99966045B6DA9555577697C60033FEEA939BB0E88A44EABD5F235A74CD0960151CE15CC139AF3EA1FA3AC67622593350870062FAF5153F5DE8A6AE4AF9EF8B8280E7AD110E5C534EE28F727CFE05A2C0AE43F431190FCA826E73C50B6626EDAA85BA940E325BD989CE48067CDA2C0169F3EA1")]
[assembly: InternalsVisibleTo("Deveroom.VisualStudio.SpecFlow36NetCoreConnector.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009860521716FB3C7979667BA43A99966045B6DA9555577697C60033FEEA939BB0E88A44EABD5F235A74CD0960151CE15CC139AF3EA1FA3AC67622593350870062FAF5153F5DE8A6AE4AF9EF8B8280E7AD110E5C534EE28F727CFE05A2C0AE43F431190FCA826E73C50B6626EDAA85BA940E325BD989CE48067CDA2C0169F3EA1")]
[assembly: InternalsVisibleTo("Deveroom.VisualStudio.SpecFlow37NetCoreConnector.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009860521716FB3C7979667BA43A99966045B6DA9555577697C60033FEEA939BB0E88A44EABD5F235A74CD0960151CE15CC139AF3EA1FA3AC67622593350870062FAF5153F5DE8A6AE4AF9EF8B8280E7AD110E5C534EE28F727CFE05A2C0AE43F431190FCA826E73C50B6626EDAA85BA940E325BD989CE48067CDA2C0169F3EA1")]
[assembly: InternalsVisibleTo("Deveroom.VisualStudio.SpecFlow31Net5Connector.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009860521716FB3C7979667BA43A99966045B6DA9555577697C60033FEEA939BB0E88A44EABD5F235A74CD0960151CE15CC139AF3EA1FA3AC67622593350870062FAF5153F5DE8A6AE4AF9EF8B8280E7AD110E5C534EE28F727CFE05A2C0AE43F431190FCA826E73C50B6626EDAA85BA940E325BD989CE48067CDA2C0169F3EA1")]
[assembly: InternalsVisibleTo("Deveroom.VisualStudio.SpecFlowConnector.V1.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010009860521716FB3C7979667BA43A99966045B6DA9555577697C60033FEEA939BB0E88A44EABD5F235A74CD0960151CE15CC139AF3EA1FA3AC67622593350870062FAF5153F5DE8A6AE4AF9EF8B8280E7AD110E5C534EE28F727CFE05A2C0AE43F431190FCA826E73C50B6626EDAA85BA940E325BD989CE48067CDA2C0169F3EA1")]
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ public object InvokeBinding(IBinding binding, IContextManager contextManager, ob
public override void RegisterGlobalContainerDefaults(ObjectContainer container)
{
base.RegisterGlobalContainerDefaults(container);
container.RegisterTypeAs<NullBindingInvoker, IBindingInvoker>();
ContainerRegisterTypeAs<NullBindingInvoker, IBindingInvoker>(container);
}

protected void ContainerRegisterTypeAs<TType, TInterface>(ObjectContainer container)
{
// need to call RegisterTypeAs through reflection, because BoDi 1.5 (used from SpecFlow 3.7) introduced a return type
container.ReflectionCallMethod("RegisterTypeAs", typeof(TType), typeof(TInterface));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public static T ReflectionCallMethod<T>(this object obj, string methodName, para
return ReflectionCallMethod<T>(obj, methodName, args?.Select(a => a.GetType()).ToArray() ?? new Type[0], args);
}

public static void ReflectionCallMethod(this object obj, string methodName, params object[] args)
{
ReflectionCallMethod<object>(obj, methodName, args);
}

public static void ReflectionCallMethod(this object obj, string methodName, Type[] parameterTypes, params object[] args)
{
ReflectionCallMethod<object>(obj, methodName, parameterTypes, args);
Expand Down
25 changes: 17 additions & 8 deletions Deveroom.VisualStudio.sln
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Deveroom.VisualStudio.SpecF
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Deveroom.VisualStudio.SpecFlow31NetFwConnector.Tests", "Tests\Deveroom.VisualStudio.SpecFlow31NetFwConnector.Tests\Deveroom.VisualStudio.SpecFlow31NetFwConnector.Tests.csproj", "{1DE6AE23-DB3F-44B5-8633-80F6A1AB0BC1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Deveroom.VisualStudio.SpecFlow31Net5Connector.Tests", "Tests\Deveroom.VisualStudio.SpecFlow31Net5Connector.Tests\Deveroom.VisualStudio.SpecFlow31Net5Connector.Tests.csproj", "{CE4E0DF5-132A-417B-B062-F70CF0F692F4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Deveroom.VisualStudio.SpecFlow36NetCoreConnector.Tests", "Tests\Deveroom.VisualStudio.SpecFlow36NetCoreConnector.Tests\Deveroom.VisualStudio.SpecFlow36NetCoreConnector.Tests.csproj", "{A514B820-E7D3-4B07-8BC8-09F5354009B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Deveroom.VisualStudio.SpecFlow37NetCoreConnector.Tests", "Tests\Deveroom.VisualStudio.SpecFlow37NetCoreConnector.Tests\Deveroom.VisualStudio.SpecFlow37NetCoreConnector.Tests.csproj", "{E67A8D21-105E-4A1E-AF01-B0718D4E696A}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down Expand Up @@ -255,12 +257,18 @@ Global
{1DE6AE23-DB3F-44B5-8633-80F6A1AB0BC1}.Release|Any CPU.Build.0 = Release|Any CPU
{1DE6AE23-DB3F-44B5-8633-80F6A1AB0BC1}.TestDebug|Any CPU.ActiveCfg = Debug|Any CPU
{1DE6AE23-DB3F-44B5-8633-80F6A1AB0BC1}.TestDebug|Any CPU.Build.0 = Debug|Any CPU
{CE4E0DF5-132A-417B-B062-F70CF0F692F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE4E0DF5-132A-417B-B062-F70CF0F692F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE4E0DF5-132A-417B-B062-F70CF0F692F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE4E0DF5-132A-417B-B062-F70CF0F692F4}.Release|Any CPU.Build.0 = Release|Any CPU
{CE4E0DF5-132A-417B-B062-F70CF0F692F4}.TestDebug|Any CPU.ActiveCfg = Debug|Any CPU
{CE4E0DF5-132A-417B-B062-F70CF0F692F4}.TestDebug|Any CPU.Build.0 = Debug|Any CPU
{A514B820-E7D3-4B07-8BC8-09F5354009B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A514B820-E7D3-4B07-8BC8-09F5354009B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A514B820-E7D3-4B07-8BC8-09F5354009B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A514B820-E7D3-4B07-8BC8-09F5354009B3}.Release|Any CPU.Build.0 = Release|Any CPU
{A514B820-E7D3-4B07-8BC8-09F5354009B3}.TestDebug|Any CPU.ActiveCfg = Debug|Any CPU
{A514B820-E7D3-4B07-8BC8-09F5354009B3}.TestDebug|Any CPU.Build.0 = Debug|Any CPU
{E67A8D21-105E-4A1E-AF01-B0718D4E696A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E67A8D21-105E-4A1E-AF01-B0718D4E696A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E67A8D21-105E-4A1E-AF01-B0718D4E696A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E67A8D21-105E-4A1E-AF01-B0718D4E696A}.Release|Any CPU.Build.0 = Release|Any CPU
{E67A8D21-105E-4A1E-AF01-B0718D4E696A}.TestDebug|Any CPU.ActiveCfg = Debug|Any CPU
{E67A8D21-105E-4A1E-AF01-B0718D4E696A}.TestDebug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -289,7 +297,8 @@ Global
{4E99D386-BAD3-4B5E-A80A-EFD3D90A1654} = {3710808B-7098-4236-9053-FDB52CBB51E0}
{F001F36F-536C-4EEB-AB11-712D8120A771} = {3710808B-7098-4236-9053-FDB52CBB51E0}
{1DE6AE23-DB3F-44B5-8633-80F6A1AB0BC1} = {3710808B-7098-4236-9053-FDB52CBB51E0}
{CE4E0DF5-132A-417B-B062-F70CF0F692F4} = {3710808B-7098-4236-9053-FDB52CBB51E0}
{A514B820-E7D3-4B07-8BC8-09F5354009B3} = {3710808B-7098-4236-9053-FDB52CBB51E0}
{E67A8D21-105E-4A1E-AF01-B0718D4E696A} = {3710808B-7098-4236-9053-FDB52CBB51E0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2F4914B0-F8E8-4745-979B-5F36DFA8013A}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public DiscoveryResult RunDiscovery(string testAssemblyPath, string configFilePa
};
}

_logger.LogVerbose(connectorPath);
_logger.LogVerbose(result.StandardOut);

var discoveryResult = JsonSerialization.DeserializeObjectWithMarker<DiscoveryResult>(result.StandardOut);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,14 @@ protected virtual void InstallSpecFlowPackages(string packagesFolder, ProjectCha
InstallNuGetPackage(projectChanger, packagesFolder, "Google.Protobuf", dependency: true, packageVersion: "3.7.0");
}

if (_options.SpecFlowVersion >= new Version("3.0.188"))
if (_options.SpecFlowVersion >= new Version("3.7"))
{
InstallNuGetPackage(projectChanger, packagesFolder, "BoDi", dependency: true, packageVersion: "1.5.0");
InstallNuGetPackage(projectChanger, packagesFolder, "Gherkin", dependency: true, packageVersion: "6.0.0");
InstallNuGetPackage(projectChanger, packagesFolder, "Utf8Json", "net45", dependency: true, packageVersion: "1.3.7");
InstallNuGetPackage(projectChanger, packagesFolder, "System.ValueTuple", "netstandard1.0", dependency: true);
}
else if (_options.SpecFlowVersion >= new Version("3.0.188"))
{
InstallNuGetPackage(projectChanger, packagesFolder, "BoDi", dependency: true, packageVersion: "1.4.1");
InstallNuGetPackage(projectChanger, packagesFolder, "Gherkin", dependency: true, packageVersion: "6.0.0");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\Key.snk</AssemblyOriginatorKeyFile>
Expand All @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="SpecFlow.xUnit" Version="3.5.14" NoWarn="NU1608" />
<PackageReference Include="SpecFlow.xUnit" Version="3.6.23" NoWarn="NU1608" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using TechTalk.SpecFlow;
using Xunit;

namespace Deveroom.VisualStudio.SpecFlow31NetCoreConnector.Tests
namespace Deveroom.VisualStudio.SpecFlow36NetCoreConnector.Tests
{
public class SpecFlowV31DiscovererNet5Tests
public class SpecFlowV36DiscovererNetCoreTests
{
private SpecFlowV31Discoverer CreateSut()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\Key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="SpecFlow.xUnit" Version="3.7.13" NoWarn="NU1608" />
<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="..\..\Deveroom.VisualStudio.SpecFlowConnector.Models\Deveroom.VisualStudio.SpecFlowConnector.Models.csproj" />
<ProjectReference Include="..\..\Deveroom.VisualStudio.SpecFlowConnector.V2\Deveroom.VisualStudio.SpecFlowConnector.V2.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using Deveroom.VisualStudio.SpecFlowConnector.Discovery.V31;
using Deveroom.VisualStudio.SpecFlowConnector.Models;
using FluentAssertions;
using TechTalk.SpecFlow;
using Xunit;

namespace Deveroom.VisualStudio.SpecFlow37NetCoreConnector.Tests
{
public class SpecFlowV37DiscovererNetCoreTests
{
private SpecFlowV31Discoverer CreateSut()
{
var stubDiscoverer = new SpecFlowV31Discoverer(AssemblyLoadContext.Default);
return stubDiscoverer;
}

private string GetTestAssemblyPath()
{
return Assembly.GetExecutingAssembly().Location;
}

private DiscoveryResult PerformDiscover(SpecFlowV31Discoverer sut)
{
var testAssemblyPath = GetTestAssemblyPath();
var testAssembly = Assembly.LoadFrom(testAssemblyPath);
return sut.DiscoverInternal(testAssembly, testAssemblyPath, null);
}

[Binding]
public class SampleBindings
{
[When(@"I press add")]
public void WhenIPressAdd() { }

public static bool BeforeTestRunHookCalled = false;
[BeforeTestRun]
public static void BeforeTestRunHook()
{
BeforeTestRunHookCalled = true;
}

public static bool AfterTestRunHookCalled = false;
[AfterTestRun]
public static void AfterTestRunHook()
{
AfterTestRunHookCalled = true;
}
}

[Fact]
public void Discovers_step_definitions()
{
var sut = CreateSut();

var result = PerformDiscover(sut);

result.StepDefinitions.Should().NotBeNullOrEmpty();
}

[Fact]
public void Should_not_invoke_BeforeAfterTestRun_hook_during_discovery_Issue_27()
{
var sut = CreateSut();
SampleBindings.BeforeTestRunHookCalled = false;
SampleBindings.AfterTestRunHookCalled = false;

var result = PerformDiscover(sut);

result.StepDefinitions.Should().NotBeNullOrEmpty();
SampleBindings.AfterTestRunHookCalled.Should().BeFalse();
SampleBindings.BeforeTestRunHookCalled.Should().BeFalse();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Scenario Outline: Discover bindings from a SpecFlow project on .NET Framework
And the step definitions contain source file and line
Examples:
| case | version |
| line-v3.7 | v3.7.13 |
| line-v3.6 | v3.6.23 |
| line-v3.5 | v3.5.14 |
| line-v3.4 | v3.4.31 |
Expand All @@ -30,6 +31,7 @@ Scenario Outline: Discover bindings from a SpecFlow project on .NET Core
Then the discovery succeeds with several step definitions
Examples:
| case | version |
| line-v3.7 | v3.7.13 |
| line-v3.6 | v3.6.23 |
| line-v3.5 | v3.5.14 |
| line-v3.4 | v3.4.31 |
Expand Down

0 comments on commit d39e4f7

Please sign in to comment.