Permalink
Browse files

add VS2012 project and testmethod resolver to the repo

1 parent 4f8df64 commit e2b28ea22adfe9a9dc1179295ba3ee590d8eca51 @gasparnagy gasparnagy committed Oct 12, 2012
@@ -0,0 +1,11 @@
+using System.Reflection;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("VS2012Integration")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,84 @@
+using System;
+using System.ComponentModel.Composition;
+using System.IO;
+using System.Linq;
+using System.Text.RegularExpressions;
+using Microsoft.VisualStudio.TestWindow.Controller;
+using Microsoft.VisualStudio.TestWindow.Data;
+using Microsoft.VisualStudio.TestWindow.Extensibility;
+using Microsoft.VisualStudio.TestWindow.VsAdapters;
+
+namespace TechTalk.SpecFlow.Vs2012Integration
+{
+ [Export(typeof(ITestMethodResolver))]
+ public class SpecFlowTestMethodResolver : ITestMethodResolver
+ {
+ public Uri ExecutorUri
+ {
+ get { return new Uri("executor://SpecFlow/v1"); }
+ }
+
+ private readonly VsTestMethodResolver defaultResolver = null;
+
+ [ImportingConstructor]
+ public SpecFlowTestMethodResolver(Lazy<ITestContainerProvider> testContainerProvider, SafeDispatcher safeDispatcher)
+ {
+ defaultResolver = new VsTestMethodResolver(testContainerProvider, safeDispatcher);
+ }
+
+ public string GetCurrentTest(string filePath, int line, int lineCharOffset)
+ {
+ if (filePath.EndsWith(".feature", StringComparison.InvariantCultureIgnoreCase))
+ {
+ var codeBehindPath = filePath + ".cs";
+ int codeBehindLine = GetCodeBehindLine(codeBehindPath, line);
+ if (codeBehindLine < 0)
+ {
+ return null; // run the entire file
+ }
+
+ var currentTest = defaultResolver.GetCurrentTest(codeBehindPath, codeBehindLine, 0);
+ return currentTest;
+ }
+
+ return null;
+ }
+
+ private int GetCodeBehindLine(string filePath, int line)
+ {
+ using (var reader = new StreamReader(filePath))
+ {
+ return GetCodeBehindLine(reader, line);
+ }
+ }
+
+ private static readonly Regex linePragmaRe = new Regex(@"^((#line\s+(?<lineno>\d+))|(#ExternalSource\("".*"",(?<lineno>\d+)\)))\s*$");
+
+ protected int GetCodeBehindLine(TextReader reader, int sourceLine)
+ {
+ int sourceLine1Based = sourceLine + 1;
+ int startLine = 0;
+ string lineText;
+ while ((lineText = reader.ReadLine()) != null)
+ {
+ //#line 8
+ //#ExternalSource("SpecFlowFeature2.feature",8)
+ var match = linePragmaRe.Match(lineText);
+ if (match.Success)
+ {
+ int linePragmaValue;
+ if (int.TryParse(match.Groups["lineno"].Value, out linePragmaValue))
+ {
+ if (linePragmaValue >= sourceLine1Based)
+ {
+ return startLine + 1; // the next line after the pragma
+ }
+ }
+ }
+ startLine++;
+ }
+
+ return -1;
+ }
+ }
+}
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{7EE9BE0E-CAAE-4498-9DBF-5AC46EE1EBC2}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>TechTalk.SpecFlow.Vs2012Integration</RootNamespace>
+ <AssemblyName>TechTalk.SpecFlow.Vs2012Integration</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup>
+ <SignAssembly>true</SignAssembly>
+ </PropertyGroup>
+ <PropertyGroup>
+ <AssemblyOriginatorKeyFile>..\..\specflow.snk</AssemblyOriginatorKeyFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.TestWindow.Core">
+ <HintPath>..\..\lib\VS2012SDK\Microsoft.VisualStudio.TestWindow.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.TestWindow.Interfaces">
+ <HintPath>..\..\lib\VS2012SDK\Microsoft.VisualStudio.TestWindow.Interfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.ComponentModel.Composition" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\..\CommonAssemblyInfo.cs">
+ <Link>Properties\CommonAssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="SpecFlowTestMethodResolver.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TechTalk.SpecFlow.Vs2012Integration", "IdeIntegration\VS2012Integration\TechTalk.SpecFlow.Vs2012Integration.csproj", "{7EE9BE0E-CAAE-4498-9DBF-5AC46EE1EBC2}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {7EE9BE0E-CAAE-4498-9DBF-5AC46EE1EBC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7EE9BE0E-CAAE-4498-9DBF-5AC46EE1EBC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7EE9BE0E-CAAE-4498-9DBF-5AC46EE1EBC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7EE9BE0E-CAAE-4498-9DBF-5AC46EE1EBC2}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e2b28ea

Please sign in to comment.