use*_*430 3 c# testing localization resource-file
我有一个需要支持法语和英语的项目.我将所有字符串放入资源文件中.当我在Visual Studio中调试程序时,我可以用法语成功查看该程序.但是,当我运行该程序的测试时,该程序将恢复为英语.我将法语资源dll文件添加到部署中.这允许我用法语调试单个单元测试,但是当我单击Test - > Debug - > All Tests in Solution时,程序将以英语运行.
我试图将[DeploymentItem(@"..\bin\x86\Release\fr","fr-FR")]添加到其中一个测试中,但这没有帮助.有没有人对如何解决这个问题有任何建议?谢谢!
我在这样的using语句中包装语言测试:
[Test]
public void Loads_correct_labels_from_language()
{
using(new LanguageSwitchContext("fr"))
{
var okayString = MyResources.Okay_Button;
Assert.Equals("your localized string here", okayString);
}
}
public class LanguageSwitchContext : IDisposable
{
public CultureInfo PreviousLanguage { get; private set; }
public LanguageSwitchContext(CultureInfo culture)
{
PreviousLanguage = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
}
public LanguageSwitchContext(string language)
{
//create culture from language
}
public void Dispose()
{
System.Threading.CurrentThread.CurrentCulture = PreviousCulture;
}
}
Run Code Online (Sandbox Code Playgroud)
这里有两个潜在的问题:
CurrentUICulture可能无法设置您要测试的语言对于1.您可以确保System.Threading.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");在测试或测试类的初始化中设置.
对于2.使用DeploymentItemAttribute你提到的类似应该工作.确认在使用法语成功运行应用程序时部署的附属程序集是否会在测试部署中使用相同名称和同一子文件夹进行复制.这可能更像是[DeploymentItem(@"bin\fr-FR", "fr-FR")]
| 归档时间: |
|
| 查看次数: |
2511 次 |
| 最近记录: |