简体   繁体   English

设计文化/全球化问题的测试

[英]Designing Tests for Culture/Globalisation problems

I'm concerned about the predictability of my application in handling string input in different cultures. 我担心我的应用程序在处理不同文化中的字符串输入时的可预测性。 It has been a problem in older software and I don't want it to be a problem in the new. 这是旧软件中的一个问题,我不希望它成为新版本中的问题。

I have generally two sources of input; 我一般有两种输入来源; Strings entered into a WPF application and Streams, loaded from files, containing text. 字符串输入到WPF应用程序和Streams,从文件加载,包含文本。 These cultured strings are generally entered into an model before being used 这些培养的​​细绳通常在使用前进入模型

public struct MyModel
{
    public String Name;
}

I want to design a meaningful test to ensure some logic can actually handle Result DoSomething(MyModel model); 我想设计一个有意义的测试,以确保一些逻辑可以实际处理Result DoSomething(MyModel model); when it contains text inputted on a different machine. 当它包含在不同机器上输入的文本时。

But how can I show a case where the difference matters? 但是,我怎样才能展示差异重要的案例?

For example the following fails. 例如,以下失败。

 var inNativeCulture= "[Something12345678.9:1] {YeS/nO}";
 var inChineseCulture = inNativeCulture.ToString(new CultureInfo("zh-CN"));
 Assert.That(inChineseCulture, Is.Not.EqualTo(inNativeCulture));

[Question] [题]

How can I test DoSomething such that the test is able to fail if the strings are not converted to InvarientCulture? 我如何测试DoSomething ,以便在字符串未转换为InvarientCulture时测试能够失败?

Should I even bother? 我应该打扰吗? ie the string Something entered on a french keyboard will always equal Something entered on a Chinese keyboard? 即串Something法语键盘上输入将始终等于Something中国的键盘上输入?

What can I test for that will mitigate Globalization problems? 我可以测试什么可以缓解全球化问题?

The ToString method taking a IFormatProvider on a string is essentially a no-op. 在字符串上使用IFormatProvider的ToString方法本质上是一个无操作。 The documentation states "Returns this instance of String; no actual conversion is performed." 文档说明“返回此String实例;不执行实际转换。”

Since you are concerned about avoiding issues here's some general advice. 既然你担心避免问题,这里有一些一般的建议。 First it is very helpful to have a clear distinction in your mind between frontend (user facing) strings and backend (database, wire, file, etc) strings. 首先,在前端(面向用户的)字符串和后端(数据库,电线,文件等)字符串之间明确区分是非常有用的。 Frontend strings should be generated/accepted according to the user's culture / application language. 应根据用户的文化/应用程序语言生成/接受前端字符串。 These strings should not be persisted (with few exceptions like when you are generating a document that will be read only by people and not by machine). 不应该保留这些字符串(除了少数例外情况,例如生成只能由人而不是机器读取的文档)。 Backend strings should always use standard formats that will not change over time. 后端字符串应始终使用不会随时间变化的标准格式。 If you accept the fact that the data used to generate/parse globalized strings changes, then you will isolate yourself from the effects by ensuring that you do not persist user facing strings. 如果您接受用于生成/解析全球化字符串的数据发生更改的事实,那么您将通过确保不保留面向用户的字符串来将自己与效果区分开来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM