Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] .NET Core proof-of-concept #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# top-most EditorConfig file
root = true

# Global settings
[*]
indent_style = space
end_of_line = crlf
insert_final_newline = true
trim_trailing_whitespace = true

[*.cs]
indent_size = 4

[*.{config,xml}]
indent_size = 2

[*.{proj,props,sln,targets}]
tab_width = 4

[*.{csproj,json,ps1,psd1,psm1,resx,rst}]
indent_size = 2

[nuget.config]
indent_size = 2


# Advanced
dotnet_sort_system_directives_first = true

###############
# Code Style
###############
# 'this.' preferences
dotnet_style_qualification_for_field = true:none
dotnet_style_qualification_for_property = true:none
dotnet_style_qualification_for_method = true:none
dotnet_style_qualification_for_event = true:none

# Predefined type preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:none
dotnet_style_predefined_type_for_member_access = true:none

# 'var' preferences
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# Code block preferences
############ Missing Prefer braces = true:warning
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion

# Expression preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
dotnet_style_explicit_tuple_names = true:warning

# Variable preferences
csharp_style_inlined_variable_declaration = true:suggestion

# 'null' checking
csharp_style_throw_expression = true:none
csharp_style_conditional_delegate_call = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion

###############
# Indentation
###############
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

#############
# New Lines
#############
# New line options for braces
csharp_new_line_before_open_brace = all

# New line options for keywords
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true

# New line options for expressions
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

###########
# Spacing
###########
# Set spacing for method declarations
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false

# Set spacing for method calls
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false

# Set other spacing options
csharp_space_after_keywords_in_control_flow_statements = true
# csharp_space_between_parentheses = none
csharp_space_after_cast = false
csharp_space_around_declaration_statements = do_not_ignore

# Set spacing for brackets
csharp_space_before_open_square_brackets = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_square_brackets = false

# Set spacing for delimiters
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_semicolon_in_for_statement = true
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_semicolon_in_for_statement = false

# Set spacing for operators
csharp_space_around_binary_operators = before_and_after

###########
# Wrapping
###########
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ License: Apache (https://github.com/gasparnagy/SpecFlow.xUnitAdapter/blob/master

NuGet: https://www.nuget.org/packages/SpecFlow.xUnitAdapter

Check the complete example at https://github.com/gasparnagy/SpecFlow.xUnitAdapter/tree/master/sample/MyCalculator.
See my blog post (http://gasparnagy.com/2017/04/specflow-without-code-behind-files/) for more information and background,
you can also look at the complete example at https://github.com/gasparnagy/SpecFlow.xUnitAdapter/tree/master/sample/MyCalculator or watch the
video demo on [YouTube](https://youtu.be/wGuoVqG3I8M).

[![Build status](https://ci.appveyor.com/api/projects/status/oshtcr06501euoih/branch/master?svg=true)](https://ci.appveyor.com/project/gasparnagy/specflow-xunitadapter/branch/master)

## Donate

If you like this plugin and would like to support developing this or similar plugins, please consider donating the project. (For receiving an invoice for your donation, please [contact me](http://gasparnagy.com/about/) upfront.)

Expand Down
43 changes: 43 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: build{build}

image: Visual Studio 2017

branches:
only:
- master

environment:
BaseVersion: 1.0.0
NugetVersion: "1.0.0-ci$(APPVEYOR_BUILD_NUMBER)"

cache:
- src\packages -> src\**\packages.config

assembly_info:
patch: true
file: 'src\**\AssemblyInfo.*'
assembly_version: "$(BaseVersion)"
assembly_file_version: "$(BaseVersion)"
assembly_informational_version: "$(NugetVersion)"

nuget:
project_feed: true
disable_publish_on_pr: true

configuration: Release

before_build:
- cd src
- appveyor DownloadFile https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
- appveyor DownloadFile https://raw.githubusercontent.com/appveyor/ci/master/scripts/nuget-restore.cmd
- nuget-restore SpecFlow.xUnitAdapter.sln
- cd ..

build:
project: src\SpecFlow.xUnitAdapter.sln
verbosity: normal

artifacts:
- path: 'src\NuGetPackages\bin\*.nupkg'

test: off
40 changes: 40 additions & 0 deletions docs/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Debugging SpecFlow xUnitAdapter
In order to debug the SpecFlow xUnitAdapter, you will need to be able to attach the debugger to the process running/discovering tests. Unfortunatly, `vstest.console.exe` kicks off child processes when it runs/discovers tests. The easiest solution to this is to use an extension created by an employee at Microsoft that instructs the Visual Studio Debugger to attach to and child process spawned from the process currently attached to the debugger. You can download and install the extension from: [Microsoft Child Process Debugging Power Tool](https://visualstudiogallery.msdn.microsoft.com/a1141bff-463f-465f-9b6d-d29b7b503d7a).

Once the extension is installed open the `SpecFlow.xUnitAdapter.SpecFlowPlugin` project's properties and go to the `Debug` property page.

## Start external program:
Visual Studio 2015:
```
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
```

Visual Studio 2017:
```
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
```

## Command line arguments:
This property will change depending on what you are trying to debug. The most common scenarios are:

Test Discovery:
```
SpecFlow.xUnitAdapter.TestProject.dll /ListTests /TestAdapterPath:.
```

Test Run:
```
SpecFlow.xUnitAdapter.TestProject.dll /TestAdapterPath:.
```

## Working directory:
This should be set to the bin directory of the test project which may be different on your machine. An example might be:
```
C:\Projects\SpecFlow.xUnitAdapter\src\tests\SpecFlow.xUnitAdapter.TestProject\bin\Debug\
```

## Enable native code debugging:
This option needt to be enabled so that the child process debugging tools work.

## Microsoft Child Process Debugging Power Tool Configuration
The settings for the child process debugging are stored in the `src\SpecFlow.xUnitAdapter.2017.ChildProcessDbgSettings` file. These settings should be already configured to work correctly with the SpecFlow adapter, however if you need to modify the settings you can do so in Visual Studio using the following menu: `Debug -> Other Debug Targets -> Child Process Debugging Settings...`
5 changes: 5 additions & 0 deletions src/SpecFlow.xUnitAdapter.ChildProcessDbgSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ChildProcessDebuggingSettings IsEnabled="true" xmlns="http://schemas.microsoft.com/vstudio/ChildProcessDebuggingSettings/2014">
<DefaultRule EngineFilter="[inherit]" />
<Rule IsEnabled="false" ProcessName="" EngineFilter="[inherit]" />
</ChildProcessDebuggingSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace SpecFlow.xUnitAdapter.SpecFlowPlugin.Framework
{
public class SpecFlowTestDiscoverer : TestFrameworkDiscoverer
{
public SpecFlowTestDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink) :
base(new SpecFlowProjectAssemblyInfo(assemblyInfo), sourceProvider, diagnosticMessageSink)
public SpecFlowTestDiscoverer(IAssemblyInfo assemblyInfo, string featureFilesFolder, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink) :
base(new SpecFlowProjectAssemblyInfo(assemblyInfo, featureFilesFolder), sourceProvider, diagnosticMessageSink)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using SpecFlow.xUnitAdapter.SpecFlowPlugin.Framework;
using Xunit.Abstractions;
using Xunit.Sdk;
using System.Runtime.Loader;
using System.IO;
using System;

namespace SpecFlow.xUnitAdapter.SpecFlowPlugin
{
Expand All @@ -10,9 +13,37 @@ public SpecFlowTestFramework(IMessageSink diagnosticMessageSink) : base(diagnost
{
}

private string GetAssemblyFolder(string assemblyPath)
{
var relativePath = Path.GetDirectoryName(assemblyPath);
if (string.IsNullOrEmpty(relativePath))
relativePath = ".";
return Path.GetFullPath(relativePath);
}

protected override ITestFrameworkDiscoverer CreateDiscoverer(IAssemblyInfo assemblyInfo)
{
return new SpecFlowTestDiscoverer(assemblyInfo, SourceInformationProvider, DiagnosticMessageSink);
string assemblyFolder = GetAssemblyFolder(assemblyInfo.AssemblyPath);
string featureFilesFolder = assemblyFolder;

AssemblyLoadContext.Default.Resolving += (ctx, an) =>
{
var assemblyPath = Path.Combine(assemblyFolder, an.Name + ".dll");
if (File.Exists(assemblyPath))
{
try
{
return AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
}
return null;
};

return new SpecFlowTestDiscoverer(assemblyInfo, featureFilesFolder, SourceInformationProvider, DiagnosticMessageSink);
}

//protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void FeatureSetup(GherkinDocument gherkinDocument)
Debug.Assert(gherkinDocument.Feature != null);
var feature = gherkinDocument.Feature;

var assembly = Assembly.LoadFrom(TestCase.FeatureFile.SpecFlowProject.AssemblyPath);
//var assembly = Assembly.LoadFrom(TestCase.FeatureFile.SpecFlowProject.AssemblyPath);
var assembly = Assembly.Load(new AssemblyName(TestCase.FeatureFile.SpecFlowProject.Name));
testRunner = TestRunnerManager.GetTestRunner(assembly);
var featureInfo = new FeatureInfo(GetFeatureCulture(feature.Language), feature.Name, feature.Description, ProgrammingLanguage.CSharp, feature.Tags.GetTags().ToArray());
testRunner.OnFeatureStart(featureInfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.5</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Gherkin" Version="4.0.1" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>
<Reference Include="TechTalk.SpecFlow.Core">
<HintPath>..\TemporaryDependencies\TechTalk.SpecFlow.Core\netstandard1.4\TechTalk.SpecFlow.Core.dll</HintPath>
</Reference>
<Reference Include="TechTalk.SpecFlow.Parser.Core">
<HintPath>..\TemporaryDependencies\TechTalk.SpecFlow.Parser.Core\netstandard1.4\TechTalk.SpecFlow.Parser.Core.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public static async Task<SpecFlowDocument> ParseSpecFlowDocumentAsync(string fea

public static SpecFlowDocument ParseSpecFlowDocument(string featureFilePath)
{
using (var reader = new StreamReader(featureFilePath))
using (var stream = new FileStream(featureFilePath, FileMode.Open))
using (var reader = new StreamReader(stream))
{
var parser = CreateParser();
var gherkinDocument = parser.Parse(reader, featureFilePath);
Expand Down
Loading