Skip to content

Commit

Permalink
Support for Verify (#2602)
Browse files Browse the repository at this point in the history
  • Loading branch information
SabotageAndi committed Aug 10, 2022
1 parent 1b143ad commit a64b51e
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 0 deletions.
@@ -0,0 +1,33 @@
// <auto-generated />
#pragma warning disable

using System.CodeDom.Compiler;
using global::System.Runtime.CompilerServices;
using System.Threading.Tasks;

[assembly: global::Xunit.TestFramework("TechTalk.SpecFlow.xUnit.SpecFlowPlugin.XunitTestFrameworkWithAssemblyFixture", "TechTalk.SpecFlow.xUnit.SpecFlowPlugin")]
[assembly: global::TechTalk.SpecFlow.xUnit.SpecFlowPlugin.AssemblyFixture(typeof(global::XUnitAssemblyFixture))]

[GeneratedCode("SpecFlow", "3.10.3-beta")]
public class XUnitAssemblyFixture : global::Xunit.IAsyncLifetime
{
[MethodImpl(MethodImplOptions.NoInlining)]
public async Task InitializeAsync()
{
var currentAssembly = typeof(XUnitAssemblyFixture).Assembly;
await global::TechTalk.SpecFlow.TestRunnerManager.OnTestRunStartAsync(currentAssembly);
}

[MethodImpl(MethodImplOptions.NoInlining)]
public async Task DisposeAsync()
{
var currentAssembly = typeof(XUnitAssemblyFixture).Assembly;
await global::TechTalk.SpecFlow.TestRunnerManager.OnTestRunEndAsync(currentAssembly);
}
}

[global::Xunit.CollectionDefinition("SpecFlowNonParallelizableFeatures", DisableParallelization = true)]
public class SpecFlowNonParallelizableFeaturesCollectionDefinition
{
}
#pragma warning restore
@@ -0,0 +1,14 @@
Feature: Verify Test

Scenario: Check if Verify is working
When I try Verify with SpecFlow
Then it works

Scenario Outline: Check if Verify is working with Example Tables
When I try Verify with SpecFlow for Parameter '<Parameter>'
Then it works

Examples:
| Parameter |
| 1 |
| 2 |
@@ -0,0 +1 @@
value
@@ -0,0 +1 @@
value
@@ -0,0 +1 @@
value
@@ -0,0 +1,69 @@
<Project>

<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Import Project="..\..\..\SpecFlow.Tools.MsBuild.Generation\build\SpecFlow.Tools.MsBuild.Generation.props" />

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Verify.Xunit" Version="17.7.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.console" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Plugins\TechTalk.SpecFlow.xUnit.SpecFlowPlugin\TechTalk.SpecFlow.xUnit.SpecFlowPlugin.csproj" />
<ProjectReference Include="..\SpecFlow.Verify.SpecFlowPlugin\SpecFlow.Verify.SpecFlowPlugin.csproj" />
</ItemGroup>

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<_SpecFlow_Needed_MSBuildGenerator Condition=" '$(MSBuildRuntimeType)' == 'Core'">$(SpecFlow_Core_Generator_TFM)</_SpecFlow_Needed_MSBuildGenerator>
<_SpecFlow_Needed_MSBuildGenerator Condition=" '$(MSBuildRuntimeType)' != 'Core'">$(SpecFlow_FullFramework_Generator_TFM)</_SpecFlow_Needed_MSBuildGenerator>
</PropertyGroup>

<Target Name="PreBuild">
<MSBuild Projects="..\..\..\SpecFlow.Tools.MsBuild.Generation\SpecFlow.Tools.MsBuild.Generation.csproj" ContinueOnError="false" Properties="TargetFramework=$(_SpecFlow_Needed_MSBuildGenerator)" />
<MSBuild Projects="..\..\..\Plugins\TechTalk.SpecFlow.xUnit.Generator.SpecFlowPlugin\TechTalk.SpecFlow.xUnit.Generator.SpecFlowPlugin.csproj" ContinueOnError="false" Properties="TargetFramework=$(_SpecFlow_Needed_MSBuildGenerator)" />
<MSBuild Projects="..\SpecFlow.Verify.SpecFlowPlugin\SpecFlow.Verify.SpecFlowPlugin.csproj" ContinueOnError="false" Properties="TargetFramework=$(_SpecFlow_Needed_MSBuildGenerator)" />
</Target>

<ItemGroup>
<SpecFlowGeneratorPlugins Include="$(MSBuildThisFileDirectory)..\SpecFlow.Verify.SpecFlowPlugin\bin\$(Configuration)\$(_SpecFlow_Needed_MSBuildGenerator)\SpecFlow.Verify.SpecFlowPlugin.dll" />
<SpecFlowGeneratorPlugins Include="$(MSBuildThisFileDirectory)..\..\TechTalk.SpecFlow.xUnit.Generator.SpecFlowPlugin\bin\$(Configuration)\$(_SpecFlow_Needed_MSBuildGenerator)\TechTalk.SpecFlow.xUnit.Generator.SpecFlowPlugin.dll" />
</ItemGroup>

<ItemGroup>
<Folder Include="Features\" />
<Folder Include="StepDefinitions\" />
</ItemGroup>

<PropertyGroup>
<_SpecFlow_TaskAssembly>..\..\SpecFlow.Tools.MsBuild.Generation\bin\$(Configuration)\$(_SpecFlow_Needed_MSBuildGenerator)\SpecFlow.Tools.MsBuild.Generation.dll</_SpecFlow_TaskAssembly>
</PropertyGroup>

<Import Project="..\..\..\SpecFlow.Tools.MsBuild.Generation\build\SpecFlow.Tools.MsBuild.Generation.targets" />
<!-- has to be before the PropertyGroup change-->
<PropertyGroup>
<BuildDependsOn>
PreBuild;
$(BuildDependsOn)
</BuildDependsOn>
<RebuildDependsOn>
PreBuild;
$(RebuildDependsOn)
</RebuildDependsOn>
</PropertyGroup>
</Project>
@@ -0,0 +1,24 @@
using TechTalk.SpecFlow;

namespace SpecFlow.Verify.SpecFlowPlugin.IntegrationTest.Steps;

[Binding]
internal class Steps
{
[When("I try Verify with SpecFlow")]
public async Task ITryVerifyWithSpecFlow()
{
await Verifier.Verify("value");
}

[When(@"I try Verify with SpecFlow for Parameter '([^']*)'")]
public async Task WhenITryVerifyWithSpecFlowForParameter(string p0)
{
await Verifier.Verify("value");
}

[Then("it works")]
public void ItWorks()
{
}
}
@@ -0,0 +1,2 @@
using System.Runtime.CompilerServices;

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(SpecFlow_Generator_TFM)</TargetFrameworks>
<NuspecFile>$(MSBuildThisFileDirectory)SpecFlow.Verify.nuspec</NuspecFile>
<AssemblyOriginatorKeyFile>$(SpecFlow_KeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>$(SpecFlow_EnableStrongNameSigning)</SignAssembly>
<PublicSign>$(SpecFlow_PublicSign)</PublicSign>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Verify" Version="17.7.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\TechTalk.SpecFlow.Generator\TechTalk.SpecFlow.Generator.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,47 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>SpecFlow.Verify</id>
<version>$version$</version>
<title>SpecFlow.Verify</title>
<authors>$author$</authors>
<owners>$owner$</owners>
<description>Package to use Verify with SpecFlow</description>
<summary>Package to use Verify with SpecFlow</summary>
<language>en-US</language>
<projectUrl>https://www.specflow.org</projectUrl>
<icon>images\specflow-icon.png</icon>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">LICENSE.txt</license>
<tags>specflow externaldata json</tags>
<copyright>$copyright$</copyright>

<dependencies>
<group targetFramework=".NETFramework4.6.2">
<dependency id="SpecFlow" version="[$version$]" />
<dependency id="Verify" version="17.7.0" />
</group>
<group targetFramework="netcoreapp3.1">
<dependency id="SpecFlow" version="[$version$]" />
<dependency id="Verify" version="17.7.0" />
</group>
<group targetFramework="net6.0">
<dependency id="SpecFlow" version="[$version$]" />
<dependency id="Verify" version="17.7.0" />
</group>
</dependencies>

</metadata>
<files>
<file src="build\**\*" target="build"/>

<file src="bin\$config$\net462\**\*" target="build\net462"/>
<file src="bin\$config$\netcoreapp3.1\*" target="build\netcoreapp3.1"/>

<file src="bin\$config$\net462\SpecFlow.Verify.SpecFlowPlugin.*" target="lib\net462"/>
<file src="bin\$config$\netcoreapp3.1\SpecFlow.Verify.SpecFlowPlugin.*" target="lib\netcoreapp3.1"/>
<file src="bin\$config$\net6.0\SpecFlow.Verify.SpecFlowPlugin.*" target="lib\net6.0"/>

<file src="$SolutionDir$LICENSE.txt" target="LICENSE.txt" />
<file src="$SolutionDir$specflow-icon.png" target="images\" />
</files>
</package>
@@ -0,0 +1,25 @@
using TechTalk.SpecFlow.Generator;
using TechTalk.SpecFlow.Generator.CodeDom;
using TechTalk.SpecFlow.Generator.UnitTestConverter;

namespace SpecFlow.Verify.SpecFlowPlugin;

public class VerifyDecorator : ITestClassDecorator
{
private readonly CodeDomHelper _codeDomHelper;

public VerifyDecorator(CodeDomHelper codeDomHelper)
{
_codeDomHelper = codeDomHelper;
}

public int Priority { get; } = 0;

public bool CanDecorateFrom(TestClassGenerationContext generationContext) => true;

public void DecorateFrom(TestClassGenerationContext generationContext)
{
_codeDomHelper.AddAttribute(generationContext.TestClass, "UsesVerify");

}
}
@@ -0,0 +1,22 @@
using SpecFlow.Verify.SpecFlowPlugin;
using TechTalk.SpecFlow.Generator.Plugins;
using TechTalk.SpecFlow.Generator.UnitTestConverter;
using TechTalk.SpecFlow.Infrastructure;
using TechTalk.SpecFlow.UnitTestProvider;

[assembly:GeneratorPlugin(typeof(VerifyGeneratorPlugin))]

namespace SpecFlow.Verify.SpecFlowPlugin
{
public class VerifyGeneratorPlugin : IGeneratorPlugin
{
public void Initialize(GeneratorPluginEvents generatorPluginEvents, GeneratorPluginParameters generatorPluginParameters,
UnitTestProviderConfiguration unitTestProviderConfiguration)
{
generatorPluginEvents.RegisterDependencies += (sender, args) =>
{
args.ObjectContainer.RegisterTypeAs<VerifyDecorator, ITestClassDecorator>("verify");
};
}
}
}
@@ -0,0 +1,47 @@
using System.Collections;
using System.IO;
using SpecFlow.Verify.SpecFlowPlugin;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Plugins;
using TechTalk.SpecFlow.UnitTestProvider;
using VerifyTests;

[assembly: RuntimePlugin(typeof(VerifyRuntimePlugin))]

namespace SpecFlow.Verify.SpecFlowPlugin;

public class VerifyRuntimePlugin : IRuntimePlugin
{
public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters, UnitTestProviderConfiguration unitTestProviderConfiguration)
{
runtimePluginEvents.CustomizeGlobalDependencies += RuntimePluginEvents_CustomizeGlobalDependencies;
}

private void RuntimePluginEvents_CustomizeGlobalDependencies(object sender, CustomizeGlobalDependenciesEventArgs e)
{
var runtimePluginTestExecutionLifecycleEvents = e.ObjectContainer.Resolve<RuntimePluginTestExecutionLifecycleEvents>();
runtimePluginTestExecutionLifecycleEvents.BeforeScenario += RuntimePluginTestExecutionLifecycleEvents_BeforeScenario;
}

private void RuntimePluginTestExecutionLifecycleEvents_BeforeScenario(object sender, RuntimePluginBeforeScenarioEventArgs e)
{
var scenarioContext = e.ObjectContainer.Resolve<ScenarioContext>();
var featureContext = e.ObjectContainer.Resolve<FeatureContext>();

VerifierSettings.DerivePathInfo(
(sourceFile, projectDirectory, type, method) =>
{
string scenarioInfoTitle = scenarioContext.ScenarioInfo.Title;
foreach (DictionaryEntry scenarioInfoArgument in scenarioContext.ScenarioInfo.Arguments)
{
scenarioInfoTitle += "_" + scenarioInfoArgument.Value;
}
return new PathInfo(
Path.Combine(projectDirectory, featureContext.FeatureInfo.FolderPath),
featureContext.FeatureInfo.Title,
scenarioInfoTitle);
});
}
}
@@ -0,0 +1,5 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="TaskFolder;TaskAssembly">
<ItemGroup>
<SpecFlowGeneratorPlugins Include="$(_VerifyGeneratorPluginPath)" />
</ItemGroup>
</Project>
@@ -0,0 +1,9 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_VerifyGeneratorPluginFramework Condition=" '$(MSBuildRuntimeType)' == 'Core'">netcoreapp2.1</_VerifyGeneratorPluginFramework>
<_VerifyGeneratorPluginFramework Condition=" '$(MSBuildRuntimeType)' != 'Core'">net461</_VerifyGeneratorPluginFramework>

<_VerifyGeneratorPluginPath>$(MSBuildThisFileDirectory)$(_VerifyGeneratorPluginFramework)\SpecFlow.Verify.SpecFlowPlugin.dll</_VerifyGeneratorPluginPath>

</PropertyGroup>
</Project>
33 changes: 33 additions & 0 deletions TechTalk.SpecFlow.sln
Expand Up @@ -117,6 +117,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{33D198CB
ExternalRepositories\SpecFlow.TestProjectGenerator\Directory.Build.rsp = ExternalRepositories\SpecFlow.TestProjectGenerator\Directory.Build.rsp
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Verify", "Verify", "{229D5199-8A48-4174-AE8F-0B4C91170751}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpecFlow.Verify.SpecFlowPlugin", "Plugins\SpecFlow.Verify\SpecFlow.Verify.SpecFlowPlugin\SpecFlow.Verify.SpecFlowPlugin.csproj", "{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpecFlow.Verify.SpecFlowPlugin.IntegrationTest", "Plugins\SpecFlow.Verify\SpecFlow.Verify.SpecFlowPlugin.IntegrationTest\SpecFlow.Verify.SpecFlowPlugin.IntegrationTest.csproj", "{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -451,6 +457,30 @@ Global
{C681C731-49F2-4C93-A730-467251741457}.Release|Any CPU.Build.0 = Release|Any CPU
{C681C731-49F2-4C93-A730-467251741457}.VS2010IntegrationTest|Any CPU.ActiveCfg = Debug|Any CPU
{C681C731-49F2-4C93-A730-467251741457}.VS2010IntegrationTest|Any CPU.Build.0 = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug-MSTest|Any CPU.ActiveCfg = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug-MSTest|Any CPU.Build.0 = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug-NUnit|Any CPU.ActiveCfg = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug-NUnit|Any CPU.Build.0 = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug-XUnit|Any CPU.ActiveCfg = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Debug-XUnit|Any CPU.Build.0 = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.Release|Any CPU.Build.0 = Release|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.VS2010IntegrationTest|Any CPU.ActiveCfg = Debug|Any CPU
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0}.VS2010IntegrationTest|Any CPU.Build.0 = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug-MSTest|Any CPU.ActiveCfg = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug-MSTest|Any CPU.Build.0 = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug-NUnit|Any CPU.ActiveCfg = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug-NUnit|Any CPU.Build.0 = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug-XUnit|Any CPU.ActiveCfg = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Debug-XUnit|Any CPU.Build.0 = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.Release|Any CPU.Build.0 = Release|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.VS2010IntegrationTest|Any CPU.ActiveCfg = Debug|Any CPU
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30}.VS2010IntegrationTest|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -485,6 +515,9 @@ Global
{C681C731-49F2-4C93-A730-467251741457} = {35D24F50-A29E-428A-8649-275C73C1E646}
{35D24F50-A29E-428A-8649-275C73C1E646} = {16EAF4F9-9860-4BB9-8992-98522E68E570}
{33D198CB-E5C7-4922-8285-246A0EFA752D} = {974420E8-FEEA-4564-B4CE-BE06F7457E3B}
{229D5199-8A48-4174-AE8F-0B4C91170751} = {8BE0FE31-6A52-452E-BE71-B8C64A3ED402}
{93476F8A-EBF1-4DB4-929F-77F5B96D08E0} = {229D5199-8A48-4174-AE8F-0B4C91170751}
{68E341C2-12C9-4DAC-AB04-A11C7CF94F30} = {229D5199-8A48-4174-AE8F-0B4C91170751}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A4D0636F-0160-4FA5-81A3-9784C7E3B3A4}
Expand Down

0 comments on commit a64b51e

Please sign in to comment.