Permalink
Browse files

Adding feature-example for StepArgumentTransformation and how to use …

…custom culture for numbers and dates.
  • Loading branch information...
jbandi
jbandi committed Jul 1, 2010
1 parent 204e2b6 commit fba502a1b58e42b073f89b0e0af686cf7740442b
@@ -0,0 +1,38 @@
+using System;
+using System.Globalization;
+using NUnit.Framework;
+using TechTalk.SpecFlow;
+
+namespace SpecFlow.Example.StepArgumentTransformation
+{
+ [Binding]
+ public class AustrianLocalizationTransformer
+ {
+ [StepArgumentTransformation]
+ public double TransformDouble(string expr)
+ {
+ return Convert.ToDouble(expr, CultureInfo.GetCultureInfo("de-AT"));
+ }
+
+ [StepArgumentTransformation]
+ public DateTime TransformDate(string expr)
+ {
+ return Convert.ToDateTime(expr, CultureInfo.GetCultureInfo("de-AT"));
+ }
+ }
+ [Binding]
+ public class ConvertSteps
+ {
+ [Given("I have entered (.*) into the system")]
+ public void GivenIHaveEnteredSomethingIntoTheSystem(double number)
+ {
+ Assert.That(number, Is.EqualTo(1050.1));
+ }
+
+ [Given("the date is (.*)")]
+ public void TheDateIs(DateTime dateTime)
+ {
+ Assert.That(dateTime, Is.EqualTo(new DateTime(2010,12,22)));
+ }
+ }
+}
@@ -0,0 +1,18 @@
+using System;
+using System.Globalization;
+using NUnit.Framework;
+
+namespace SpecFlow.Example.Localization
+{
+ [TestFixture]
+ public class ConverterTest
+ {
+ [Test]
+ public void ConvertStringToDouble_Exploration()
+ {
+ Assert.AreEqual(1050.1, Convert.ToDouble("1,050.1", CultureInfo.GetCultureInfo("en-US")));
+ Assert.AreEqual(1050.1, Convert.ToDouble("1.050,1", CultureInfo.GetCultureInfo("de-AT")));
+ Assert.AreEqual(1050.1, Convert.ToDouble("1'050.1", CultureInfo.GetCultureInfo("de-CH")));
+ }
+ }
+}
@@ -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("ClassLibrary1")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("ClassLibrary1")]
+[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("93a16f72-5ade-48f0-abcd-cc051e763d7a")]
+
+// 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")]
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{10F05D58-2CE4-40EA-BFAF-92F8F6D1F14C}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SpecFlow.Example.StepArgumentTransformation</RootNamespace>
+ <AssemblyName>SpecFlow.Example.StepArgumentTransformation</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="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\..\Projects\SpecFlow\lib\nunit\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="TechTalk.SpecFlow, Version=1.3.2.0, Culture=neutral, PublicKeyToken=0778194805d6db41, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\..\..\..\..\Program Files (x86)\TechTalk\SpecFlow\TechTalk.SpecFlow.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ConvertTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="custom_culture_for_numbers_and_dates.feature.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>custom_culture_for_numbers_and_dates.feature</DependentUpon>
+ </Compile>
+ <Compile Include="ConvertSteps.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="custom_culture_for_numbers_and_dates.feature">
+ <Generator>SpecFlowSingleFileGenerator</Generator>
+ <LastGenOutput>custom_culture_for_numbers_and_dates.feature.cs</LastGenOutput>
+ </None>
+ </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>
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpecFlow.Examples.StepArgumentTransformation", "SpecFlow.Examples.StepArgumentTransformation.csproj", "{10F05D58-2CE4-40EA-BFAF-92F8F6D1F14C}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {10F05D58-2CE4-40EA-BFAF-92F8F6D1F14C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {10F05D58-2CE4-40EA-BFAF-92F8F6D1F14C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {10F05D58-2CE4-40EA-BFAF-92F8F6D1F14C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {10F05D58-2CE4-40EA-BFAF-92F8F6D1F14C}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,8 @@
+Feature: Define the culture format for numbers and dates
+ In order to write my features in english but specify my numbers and dates in another culture format
+ As an author of features
+ I want to have an option to plug in custom conversions
+
+Scenario: Use english as feature language but numbers and dates have Austrian format
+ Given I have entered 1.050,1 into the system
+ And the date is 22.12.2010

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit fba502a

Please sign in to comment.