diff --git a/Runtime/ObjectContainer.cs b/Runtime/ObjectContainer.cs index 1d153bda7..0a01ee14c 100644 --- a/Runtime/ObjectContainer.cs +++ b/Runtime/ObjectContainer.cs @@ -188,6 +188,18 @@ public static StepDefinitionSkeletonProvider StepDefinitionSkeletonProvider } #endregion + #region StepArgumentTypeConverter + private static IStepArgumentTypeConverter stepArgumentTypeConverter = null; + + public static IStepArgumentTypeConverter StepArgumentTypeConverter + { + get + { + return GetOrCreate(ref stepArgumentTypeConverter, typeof(StepArgumentTypeConverter)); + } + } + #endregion + #region unitTestRuntimeProvider private static IUnitTestRuntimeProvider unitTestRuntimeProvider = null; diff --git a/Runtime/StepArgumentTypeConverter.cs b/Runtime/StepArgumentTypeConverter.cs index 4b567ede8..5c7d1416e 100644 --- a/Runtime/StepArgumentTypeConverter.cs +++ b/Runtime/StepArgumentTypeConverter.cs @@ -1,26 +1,27 @@ using System; +using System.Globalization; namespace TechTalk.SpecFlow { public interface IStepArgumentTypeConverter { - object Convert(string value, Type typeToConvertTo); + object Convert(string value, Type typeToConvertTo, CultureInfo cultureInfo); } - public class StepStepArgumentTypeConverter : IStepArgumentTypeConverter + public class StepArgumentTypeConverter : IStepArgumentTypeConverter { - public object Convert(string value, Type typeToConvertTo) + public object Convert(string value, Type typeToConvertTo, CultureInfo cultureInfo) { object convertedArg; var paramType = typeToConvertTo; - if (paramType.BaseType == typeof(Enum)) + if (paramType.IsEnum) { convertedArg = Enum.Parse(paramType, value, true); } else { - convertedArg = System.Convert.ChangeType(value, paramType); + convertedArg = System.Convert.ChangeType(value, paramType, cultureInfo); } return convertedArg; diff --git a/Runtime/TestRunner.cs b/Runtime/TestRunner.cs index d925aee55..81be0fa02 100644 --- a/Runtime/TestRunner.cs +++ b/Runtime/TestRunner.cs @@ -19,6 +19,7 @@ public class TestRunner : ITestRunner private readonly IUnitTestRuntimeProvider unitTestRuntimeProvider; private readonly StepFormatter stepFormatter; private readonly StepDefinitionSkeletonProvider stepDefinitionSkeletonProvider; + private readonly IStepArgumentTypeConverter stepArgumentTypeConverter = new StepArgumentTypeConverter(); public TestRunner() { @@ -27,6 +28,7 @@ public TestRunner() unitTestRuntimeProvider = ObjectContainer.UnitTestRuntimeProvider; stepFormatter = ObjectContainer.StepFormatter; stepDefinitionSkeletonProvider = ObjectContainer.StepDefinitionSkeletonProvider; + stepArgumentTypeConverter = ObjectContainer.StepArgumentTypeConverter; } public virtual void InitializeTestRunner(Assembly[] bindingAssemblies) @@ -382,7 +384,6 @@ private TimeSpan InvokeAction(Delegate action, object[] arguments, MethodInfo me private object[] GetExecuteArguments(BindingMatch match) { - IStepArgumentTypeConverter typeConverter = new StepStepArgumentTypeConverter(); List arguments = new List(); var regexArgs = match.Match.Groups.Cast().Skip(1).Select(g => g.Value).ToArray(); @@ -392,8 +393,7 @@ private object[] GetExecuteArguments(BindingMatch match) for (int argIndex = 0; argIndex < regexArgs.Length; argIndex++) { - var convertedArg = typeConverter.Convert(regexArgs[argIndex], match.StepBinding.ParameterTypes[argIndex]); - object convertedArg = Convert.ChangeType(regexArgs[argIndex], match.StepBinding.ParameterTypes[argIndex], + var convertedArg = stepArgumentTypeConverter.Convert(regexArgs[argIndex], match.StepBinding.ParameterTypes[argIndex], FeatureContext.Current.FeatureInfo.CultureInfo); arguments.Add(convertedArg); } diff --git a/Tests/ParserTests/TestFiles/background.feature.xml b/Tests/ParserTests/TestFiles/background.feature.xml index 24c27ee48..185072393 100644 --- a/Tests/ParserTests/TestFiles/background.feature.xml +++ b/Tests/ParserTests/TestFiles/background.feature.xml @@ -1,6 +1,6 @@  - en + en-US <Steps> diff --git a/Tests/ParserTests/TestFiles/background_withtitle.feature.xml b/Tests/ParserTests/TestFiles/background_withtitle.feature.xml index 7d8178d9e..a3a910c2e 100644 --- a/Tests/ParserTests/TestFiles/background_withtitle.feature.xml +++ b/Tests/ParserTests/TestFiles/background_withtitle.feature.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <Feature xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - <Language>en</Language> + <Language>en-US</Language> <Background> <Title>these preconditions should be applied always diff --git a/Tests/ParserTests/TestFiles/but.feature.xml b/Tests/ParserTests/TestFiles/but.feature.xml index fb7b9061e..4bc5eab5d 100644 --- a/Tests/ParserTests/TestFiles/but.feature.xml +++ b/Tests/ParserTests/TestFiles/but.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario diff --git a/Tests/ParserTests/TestFiles/comments.feature.xml b/Tests/ParserTests/TestFiles/comments.feature.xml index 23bea99fa..2c8b21e4b 100644 --- a/Tests/ParserTests/TestFiles/comments.feature.xml +++ b/Tests/ParserTests/TestFiles/comments.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario diff --git a/Tests/ParserTests/TestFiles/featureheader.feature.xml b/Tests/ParserTests/TestFiles/featureheader.feature.xml index a1ea00bab..c25a1dad4 100644 --- a/Tests/ParserTests/TestFiles/featureheader.feature.xml +++ b/Tests/ParserTests/TestFiles/featureheader.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario diff --git a/Tests/ParserTests/TestFiles/full.feature.xml b/Tests/ParserTests/TestFiles/full.feature.xml index a9f944e19..5e4c6ea12 100644 --- a/Tests/ParserTests/TestFiles/full.feature.xml +++ b/Tests/ParserTests/TestFiles/full.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario diff --git a/Tests/ParserTests/TestFiles/givenwhenthenduplication.feature.xml b/Tests/ParserTests/TestFiles/givenwhenthenduplication.feature.xml index f5253934c..9f23b9170 100644 --- a/Tests/ParserTests/TestFiles/givenwhenthenduplication.feature.xml +++ b/Tests/ParserTests/TestFiles/givenwhenthenduplication.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario with duplicated keywords diff --git a/Tests/ParserTests/TestFiles/mixedgivenwhenthen.feature.xml b/Tests/ParserTests/TestFiles/mixedgivenwhenthen.feature.xml index 430eb921e..0f7f7fc6f 100644 --- a/Tests/ParserTests/TestFiles/mixedgivenwhenthen.feature.xml +++ b/Tests/ParserTests/TestFiles/mixedgivenwhenthen.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario diff --git a/Tests/ParserTests/TestFiles/multilineargument.feature.xml b/Tests/ParserTests/TestFiles/multilineargument.feature.xml index 2fb110a8b..2a7fde69b 100644 --- a/Tests/ParserTests/TestFiles/multilineargument.feature.xml +++ b/Tests/ParserTests/TestFiles/multilineargument.feature.xml @@ -1,6 +1,6 @@  - en + en-US a scenario with a multiline argument diff --git a/Tests/ParserTests/TestFiles/multilinetitle.feature.xml b/Tests/ParserTests/TestFiles/multilinetitle.feature.xml index 480b59c8b..818915c38 100644 --- a/Tests/ParserTests/TestFiles/multilinetitle.feature.xml +++ b/Tests/ParserTests/TestFiles/multilinetitle.feature.xml @@ -1,6 +1,6 @@  - en + en-US some background with multi-line title diff --git a/Tests/ParserTests/TestFiles/scenariooutline.feature.xml b/Tests/ParserTests/TestFiles/scenariooutline.feature.xml index c17f6cd5e..218b5b9a7 100644 --- a/Tests/ParserTests/TestFiles/scenariooutline.feature.xml +++ b/Tests/ParserTests/TestFiles/scenariooutline.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario outline diff --git a/Tests/ParserTests/TestFiles/simple.feature.xml b/Tests/ParserTests/TestFiles/simple.feature.xml index 686d86ef5..e30da2b73 100644 --- a/Tests/ParserTests/TestFiles/simple.feature.xml +++ b/Tests/ParserTests/TestFiles/simple.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario diff --git a/Tests/ParserTests/TestFiles/tableargument.feature.xml b/Tests/ParserTests/TestFiles/tableargument.feature.xml index 550630f01..80100fa21 100644 --- a/Tests/ParserTests/TestFiles/tableargument.feature.xml +++ b/Tests/ParserTests/TestFiles/tableargument.feature.xml @@ -1,6 +1,6 @@  - en + en-US a scenario with a table argument diff --git a/Tests/ParserTests/TestFiles/tags.feature.xml b/Tests/ParserTests/TestFiles/tags.feature.xml index eee79b85b..cb0976035 100644 --- a/Tests/ParserTests/TestFiles/tags.feature.xml +++ b/Tests/ParserTests/TestFiles/tags.feature.xml @@ -1,6 +1,6 @@  - en + en-US ftag1 diff --git a/Tests/ParserTests/TestFiles/whitespaces.feature.xml b/Tests/ParserTests/TestFiles/whitespaces.feature.xml index bde8d594f..188221800 100644 --- a/Tests/ParserTests/TestFiles/whitespaces.feature.xml +++ b/Tests/ParserTests/TestFiles/whitespaces.feature.xml @@ -1,6 +1,6 @@  - en + en-US a simple scenario diff --git a/Tests/RuntimeTests/StepArgumentTypeConverterTests.cs b/Tests/RuntimeTests/StepArgumentTypeConverterTests.cs index 99c1c1975..1847dde2c 100644 --- a/Tests/RuntimeTests/StepArgumentTypeConverterTests.cs +++ b/Tests/RuntimeTests/StepArgumentTypeConverterTests.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using NUnit.Framework; namespace TechTalk.SpecFlow.RuntimeTests @@ -7,38 +8,40 @@ namespace TechTalk.SpecFlow.RuntimeTests public class StepArgumentTypeConverterTests { private IStepArgumentTypeConverter _stepArgumentTypeConverter; + private CultureInfo _enUSCulture; [SetUp] public void SetUp() { - _stepArgumentTypeConverter = new StepStepArgumentTypeConverter(); + _stepArgumentTypeConverter = new StepArgumentTypeConverter(); + _enUSCulture = new CultureInfo("en-US"); } [Test] public void ShouldConvertStringToStringType() { - var result = _stepArgumentTypeConverter.Convert("testValue", typeof(string)); + var result = _stepArgumentTypeConverter.Convert("testValue", typeof(string), _enUSCulture); Assert.That(result, Is.EqualTo("testValue")); } [Test] public void ShouldConvertStringToIntType() { - var result = _stepArgumentTypeConverter.Convert("10", typeof(int)); + var result = _stepArgumentTypeConverter.Convert("10", typeof(int), _enUSCulture); Assert.That(result, Is.EqualTo(10)); } [Test] public void ShouldConvertStringToDateType() { - var result = _stepArgumentTypeConverter.Convert("2009/10/06", typeof (DateTime)); + var result = _stepArgumentTypeConverter.Convert("2009/10/06", typeof(DateTime), _enUSCulture); Assert.That(result, Is.EqualTo(new DateTime(2009, 10, 06))); } [Test] public void ShouldConvertStringToFloatType() { - var result = _stepArgumentTypeConverter.Convert("10.01", typeof(float)); + var result = _stepArgumentTypeConverter.Convert("10.01", typeof(float), _enUSCulture); Assert.That(result, Is.EqualTo(10.01f)); } @@ -50,14 +53,14 @@ private enum TestEnumeration [Test] public void ShouldConvertStringToEnumerationType() { - var result = _stepArgumentTypeConverter.Convert("Value1", typeof(TestEnumeration)); + var result = _stepArgumentTypeConverter.Convert("Value1", typeof(TestEnumeration), _enUSCulture); Assert.That(result, Is.EqualTo(TestEnumeration.Value1)); } [Test] public void ShouldConvertStringToEnumerationTypeWithDifferingCase() { - var result = _stepArgumentTypeConverter.Convert("vALUE1", typeof(TestEnumeration)); + var result = _stepArgumentTypeConverter.Convert("vALUE1", typeof(TestEnumeration), _enUSCulture); Assert.That(result, Is.EqualTo(TestEnumeration.Value1)); } } diff --git a/changelog.txt b/changelog.txt index 37dd580a4..62ec915d2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ New features: + Allow transformation of feature files from command-line and MsBuild (Issue 3) + Merge all command-line tool (generation, reports) to a single executable: specflow.exe + Support for Dutch language ++ Support enumerations in step binding arguments (Issue 28) Fixed issues: + MsTest does not refresh tests automatically (Issue 25)