07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Test</strong>ing for Globalization Best Practices 163<br />

<strong>Test</strong> case<br />

Verify that the collection classes<br />

use culture-independent operations<br />

to sort the keys.<br />

Example<br />

For example, the .NET Framework SortedList class represents<br />

a collection of key/value pairs that are sorted by<br />

the keys. A SortedList element can be accessed by its key<br />

or by its index. When you use a SortedList object whose<br />

keys are strings, the sorting and lookup operations can be<br />

affected by the Thread.CurrentCulture property. To obtain<br />

culture-independent behavior from a SortedList object,<br />

create it with one of the constructors that accepts an<br />

IComparer interface as a parameter. This parameter specifies<br />

the IComparer implementation to use when comparing<br />

keys. For the IComparer parameter, specify a custom<br />

comparer class that uses the CultureInfo.InvariantCulture<br />

property to compare keys. The following example illustrates<br />

a custom culture-insensitive implementation of the<br />

IComparer interface that you can specify as the IComparer<br />

parameter to a SortedList constructor.<br />

internal class InvariantComparer : IComparer<br />

{<br />

private CompareInfo m_compareInfo;<br />

internal static readonly InvariantComparer<br />

Default = new<br />

InvariantComparer();<br />

internal InvariantComparer()<br />

{<br />

m_compareInfo = CultureInfo.Invariant-<br />

Culture.CompareInfo;<br />

}<br />

}<br />

public int Compare(Object a, Object b)<br />

{<br />

String sa = a as String;<br />

String sb = b as String;<br />

return m_compareInfo.Compare(sa, sb);<br />

}<br />

Pseudo-Localization <strong>Test</strong>ing<br />

Pseudo-localization may be the most effective way of finding localizability bugs.<br />

This technique involves translating the application block’s localizable resources into<br />

something readable but drastically different from normal text. For example, you<br />

could replace every “a” with an “â”. Pseudo-localization also adds extra padding<br />

characters to the ends of strings. The types of errors that pseudo-localization helps<br />

you find are hard-coded strings that need internationalization, strings that should<br />

not be translated, non-Latin characters, and errors handling longer language strings.<br />

A pseudo-localized version of an application block should behave the same as the<br />

original version.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!