Skip to content

Commit

Permalink
Non-string parameters for bindings are not converted using the featu…
Browse files Browse the repository at this point in the history
…re language (Issue 26)
  • Loading branch information
gasparnagy committed Nov 25, 2009
1 parent 70b796d commit 1dfdd1c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Languages.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<SpecFlowLanguages>
<Language code="en">
<Language code="en" defaultSpecificCulture="en-US">
<Feature>Feature</Feature>
<Background>Background</Background>
<Scenario>Scenario</Scenario>
Expand All @@ -13,7 +13,7 @@
<And>And</And>
<But>But</But>
</Language>
<Language code="de">
<Language code="de" defaultSpecificCulture="de-DE">
<Feature>Funktionalität</Feature>
<Background>Grundlage</Background>
<Scenario>Szenario</Scenario>
Expand All @@ -25,7 +25,7 @@
<And>Und</And>
<But>Aber</But>
</Language>
<Language code="fr">
<Language code="fr" defaultSpecificCulture="fr-FR">
<Feature>Fonctionnalité</Feature>
<Background>Contexte</Background>
<Scenario>Scénario</Scenario>
Expand All @@ -37,7 +37,7 @@
<And>Et</And>
<But>Mais</But>
</Language>
<Language code="hu">
<Language code="hu" defaultSpecificCulture="hu-HU">
<Feature>Jellemző</Feature>
<Background>Háttér</Background>
<Scenario>Forgatókönyv</Scenario>
Expand All @@ -49,7 +49,7 @@
<And>És</And>
<But>De</But>
</Language>
<Language code="nl">
<Language code="nl" defaultSpecificCulture="nl-NL">
<Feature>Functionaliteit</Feature>
<Background>Achtergrond</Background>
<Scenario>Scenario</Scenario>
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Configuration/ConfigurationSectionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml;
Expand All @@ -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";
Expand Down
8 changes: 8 additions & 0 deletions Runtime/FeatureInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.Linq;
using TechTalk.SpecFlow.Tracing;

namespace TechTalk.SpecFlow
{
Expand All @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion Runtime/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
31 changes: 27 additions & 4 deletions Runtime/Tracing/LanguageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ namespace TechTalk.SpecFlow.Tracing
{
internal static class LanguageHelper
{
class KeywordTranslation : Dictionary<StepDefinitionKeyword, string> {}
class KeywordTranslation : Dictionary<StepDefinitionKeyword, string>
{
public CultureInfo DefaultSpecificCulture { get; set; }
}

private static readonly Dictionary<CultureInfo, KeywordTranslation> translationCache = new Dictionary<CultureInfo, KeywordTranslation>();

Expand All @@ -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)
Expand All @@ -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());
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1dfdd1c

Please sign in to comment.