From 1dfdd1cfc401accd83b1d4f7c409e22902c183a4 Mon Sep 17 00:00:00 2001 From: Gaspar Nagy Date: Wed, 25 Nov 2009 19:25:04 +0100 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFNon-string=20parameters=20for=20bindin?= =?UTF-8?q?gs=20are=20not=20converted=20using=20the=20feature=20language?= =?UTF-8?q?=20(Issue=2026)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Languages.xml | 10 +++--- .../ConfigurationSectionHandler.cs | 3 +- Runtime/FeatureInfo.cs | 8 +++++ Runtime/TestRunner.cs | 3 +- Runtime/Tracing/LanguageHelper.cs | 31 ++++++++++++++++--- changelog.txt | 1 + 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Languages.xml b/Languages.xml index 14cffc667..2c51911a7 100644 --- a/Languages.xml +++ b/Languages.xml @@ -1,6 +1,6 @@  - + Feature Background Scenario @@ -13,7 +13,7 @@ And But - + Funktionalität Grundlage Szenario @@ -25,7 +25,7 @@ Und Aber - + Fonctionnalité Contexte Scénario @@ -37,7 +37,7 @@ Et Mais - + Jellemző Háttér Forgatókönyv @@ -49,7 +49,7 @@ És De - + Functionaliteit Achtergrond Scenario diff --git a/Runtime/Configuration/ConfigurationSectionHandler.cs b/Runtime/Configuration/ConfigurationSectionHandler.cs index f867174c6..4b28f3651 100644 --- a/Runtime/Configuration/ConfigurationSectionHandler.cs +++ b/Runtime/Configuration/ConfigurationSectionHandler.cs @@ -1,5 +1,6 @@ using System; using System.Configuration; +using System.Globalization; using System.IO; using System.Linq; using System.Xml; @@ -15,7 +16,7 @@ public enum MissingOrPendingStepsOutcome public static class ConfigDefaults { - internal const string FeatureLanguage = "en"; + internal const string FeatureLanguage = "en-US"; internal const string ToolLanguage = ""; internal const string UnitTestProviderName = "NUnit"; diff --git a/Runtime/FeatureInfo.cs b/Runtime/FeatureInfo.cs index 6c83e619d..95be7781e 100644 --- a/Runtime/FeatureInfo.cs +++ b/Runtime/FeatureInfo.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Linq; +using TechTalk.SpecFlow.Tracing; namespace TechTalk.SpecFlow { @@ -10,6 +11,13 @@ public class FeatureInfo public string Title { get; private set; } public string Description { get; private set; } public CultureInfo Language { get; private set; } + public CultureInfo CultureInfo + { + get + { + return LanguageHelper.GetSpecificCultureInfo(Language); + } + } public FeatureInfo(CultureInfo language, string title, string description, params string[] tags) { diff --git a/Runtime/TestRunner.cs b/Runtime/TestRunner.cs index 782ea274b..80e2e3d02 100644 --- a/Runtime/TestRunner.cs +++ b/Runtime/TestRunner.cs @@ -391,7 +391,8 @@ private object[] GetExecuteArguments(BindingMatch match) for (int argIndex = 0; argIndex < regexArgs.Length; argIndex++) { - object convertedArg = Convert.ChangeType(regexArgs[argIndex], match.StepBinding.ParameterTypes[argIndex]); + object convertedArg = Convert.ChangeType(regexArgs[argIndex], match.StepBinding.ParameterTypes[argIndex], + FeatureContext.Current.FeatureInfo.CultureInfo); arguments.Add(convertedArg); } diff --git a/Runtime/Tracing/LanguageHelper.cs b/Runtime/Tracing/LanguageHelper.cs index e50d637fa..0b97d562f 100644 --- a/Runtime/Tracing/LanguageHelper.cs +++ b/Runtime/Tracing/LanguageHelper.cs @@ -11,7 +11,10 @@ namespace TechTalk.SpecFlow.Tracing { internal static class LanguageHelper { - class KeywordTranslation : Dictionary {} + class KeywordTranslation : Dictionary + { + public CultureInfo DefaultSpecificCulture { get; set; } + } private static readonly Dictionary translationCache = new Dictionary(); @@ -21,17 +24,33 @@ public static string GetKeyword(CultureInfo language, BindingType bindingType) } public static string GetKeyword(CultureInfo language, StepDefinitionKeyword keyword) + { + KeywordTranslation translation = GetTranslation(language); + return translation[keyword]; + } + + private static KeywordTranslation GetTranslation(CultureInfo language) { KeywordTranslation translation; if (!translationCache.TryGetValue(language, out translation)) { - translation = GetTranslation(language); + translation = LoadTranslation(language); } + return translation; + } - return translation[keyword]; + static public CultureInfo GetSpecificCultureInfo(CultureInfo language) + { + //HACK: we need to have a better solution + if (!language.IsNeutralCulture) + return language; + + KeywordTranslation translation = GetTranslation(language); + return translation.DefaultSpecificCulture; } - private static KeywordTranslation GetTranslation(CultureInfo language) + + private static KeywordTranslation LoadTranslation(CultureInfo language) { var docStream = typeof(LanguageHelper).Assembly.GetManifestResourceStream("TechTalk.SpecFlow.Languages.xml"); if (docStream == null) @@ -47,6 +66,10 @@ private static KeywordTranslation GetTranslation(CultureInfo language) KeywordTranslation result = new KeywordTranslation(); + result.DefaultSpecificCulture = language.IsNeutralCulture ? + new CultureInfo(langElm.Attribute(XName.Get("defaultSpecificCulture", "")).Value) : + language; + foreach (StepDefinitionKeyword keyword in Enum.GetValues(typeof(StepDefinitionKeyword))) { XElement keywordElm = langElm.Element(keyword.ToString()); diff --git a/changelog.txt b/changelog.txt index aee8c6610..89e8d2173 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,7 @@ New features: Fixed issues: + MsTest does not refresh tests automatically (Issue 25) + Fixes in report localization ++ Non-string parameters for bindings are not converted using the feature language (Issue 26) 1.1.0 - 2009/11/11