Skip to content

Commit

Permalink
add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBorcherding committed Sep 30, 2010
1 parent 529376f commit 1ec5bec
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 10 deletions.
75 changes: 75 additions & 0 deletions AgentBdd.Specs/AgentBdd.Specs.csproj
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{35D0BB21-FB1B-4E7C-B05D-6A9A5A5B5C93}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AgentBdd.Specs</RootNamespace>
<AssemblyName>AgentBdd.Specs</AssemblyName>
<TargetFrameworkVersion>v3.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>
<ItemGroup>
<Reference Include="JetBrains.ReSharper.Feature.Services">
<HintPath>C:\Program Files (x86)\JetBrains\ReSharper\v5.1\Bin\JetBrains.ReSharper.Feature.Services.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.5.7.10213, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="TechTalk.SpecFlow, Version=1.3.5.2, Culture=neutral, PublicKeyToken=0778194805d6db41, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Creating method names from variables.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Creating method names from variables.feature</DependentUpon>
</Compile>
<Compile Include="Steps\SuggestMethodNameSteps.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Creating method names from variables.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>Creating method names from variables.feature.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AgentBdd\AgentBdd.csproj">
<Project>{001D4902-AFDE-496F-AFE7-F97A1375D720}</Project>
<Name>AgentBdd</Name>
</ProjectReference>
</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>
15 changes: 15 additions & 0 deletions AgentBdd.Specs/Creating method names from variables.feature
@@ -0,0 +1,15 @@
Feature: Creating method names from variables
In order to make writiing step definitions easier
As a ReSharper user
I want to be have my step method names suggested as I type my step


Scenario Outline: Suggest simple method names
When I provide the step "<step description>"
Then it should suggest <method name> as the method name

Examples:
| step description | method name |
| the foo is cool | the_foo_is_cool |
| the foo's bar | the_foos_bar |
| the foo is "(.*)" bar | the_foo_is_bar |
91 changes: 91 additions & 0 deletions AgentBdd.Specs/Creating method names from variables.feature.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions AgentBdd.Specs/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 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("AgentBdd.Specs")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("AgentBdd.Specs")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e895d809-0936-49b0-8351-40de126337d6")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
27 changes: 27 additions & 0 deletions AgentBdd.Specs/Steps/SuggestMethodNameSteps.cs
@@ -0,0 +1,27 @@
using System.Linq;
using AgentBdd.Macros;
using NUnit.Framework;
using TechTalk.SpecFlow;

namespace AgentBdd.Specs.Steps
{
[Binding]
public class SuggestMethodNameSteps
{
string suggestedMethodName;

[When(@"I provide the step ""(.*)""")]
public void When_I_provide_the_step(string step)
{
suggestedMethodName = new SuggestMethodNameFromVariable().EvaluateQuickResult(null,new []{step}.ToList());
}

[Then(@"it should suggest (.*) as the method name")]
public void Then_it_should_sugget_the_method_name(string methodName)
{
Assert.AreEqual(methodName,suggestedMethodName);
}


}
}
6 changes: 6 additions & 0 deletions AgentBdd.sln
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgentBdd", "AgentBdd\AgentBdd.csproj", "{001D4902-AFDE-496F-AFE7-F97A1375D720}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgentBdd.Specs", "AgentBdd.Specs\AgentBdd.Specs.csproj", "{35D0BB21-FB1B-4E7C-B05D-6A9A5A5B5C93}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -13,6 +15,10 @@ Global
{001D4902-AFDE-496F-AFE7-F97A1375D720}.Debug|Any CPU.Build.0 = Debug|Any CPU
{001D4902-AFDE-496F-AFE7-F97A1375D720}.Release|Any CPU.ActiveCfg = Release|Any CPU
{001D4902-AFDE-496F-AFE7-F97A1375D720}.Release|Any CPU.Build.0 = Release|Any CPU
{35D0BB21-FB1B-4E7C-B05D-6A9A5A5B5C93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35D0BB21-FB1B-4E7C-B05D-6A9A5A5B5C93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35D0BB21-FB1B-4E7C-B05D-6A9A5A5B5C93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35D0BB21-FB1B-4E7C-B05D-6A9A5A5B5C93}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
32 changes: 22 additions & 10 deletions AgentBdd/Macros/SuggestMethodNameFromVariable.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Hotspots;
using JetBrains.ReSharper.Feature.Services.LiveTemplates.Macros;

Expand All @@ -18,23 +19,34 @@ public override string EvaluateQuickResult(IHotspotContext context, IList<string
}

try
{

// Todo: do this better and maybe move to offer the space and camel case version
var result = arguments[0]
.Replace(' ','_')
.Replace(",","")
.Replace("\"","")
.Replace("'","");

return result;
{
return MethodNameFromString(arguments[0]);
}
catch (Exception e)
{
return "<" + e.Message + ">";
}
}

private static string MethodNameFromString(string s)
{
s = RemoveTheSymbols(s);
s = ConvertSpacesToUnderscores(s);
return s;
}

private static string RemoveTheSymbols(string s)
{
return Regex.Replace(s,@"[^A-Za-z0-9_\s]",string.Empty,RegexOptions.None);
}

private static string ConvertSpacesToUnderscores(string s)
{
return Regex.Replace(s,@"\s+","_",RegexOptions.None);
}



public override ParameterInfo[] Parameters
{
get { return new[] { new ParameterInfo(ParameterType.VariableReference) }; }
Expand Down
Binary file added lib/TechTalk.SpecFlow.dll
Binary file not shown.
Binary file added lib/nunit.framework.dll
Binary file not shown.

0 comments on commit 1ec5bec

Please sign in to comment.