public void TestGetBestLanguage() { var dictionary = new LocalizableStringCollection { { "de", "germanValue" }, { "de-DE", "germanyValue" }, { "en-US", "americaValue" }, { "en-GB", "gbValue" }, "neutralValue" }; dictionary.GetBestLanguage(LocalizableString.DefaultLanguage).Should().Be("neutralValue", because: "Unspecified language should default to English generic"); dictionary.GetBestLanguage(new CultureInfo("en-US")).Should().Be("americaValue"); dictionary.GetBestLanguage(new CultureInfo("en-CA")).Should().Be("neutralValue", because: "No exact match, should fall back to English generic"); dictionary.GetBestLanguage(new CultureInfo("en-GB")).Should().Be("gbValue"); dictionary.GetBestLanguage(new CultureInfo("de")).Should().Be("germanValue"); dictionary.GetBestLanguage(new CultureInfo("de-DE")).Should().Be("germanyValue", because: "No exact match, should fall back to German generic"); dictionary.GetBestLanguage(new CultureInfo("de-AT")).Should().Be("germanValue", because: "No exact match, should fall back to German generic"); dictionary.GetBestLanguage(new CultureInfo("es-ES")).Should().Be("neutralValue", because: "No match, should fall back to English generic"); dictionary.Set(LocalizableString.DefaultLanguage, null); dictionary.GetBestLanguage(new CultureInfo("es-ES")).Should().Be("americaValue", because: "No English generic, should fall back to English US"); dictionary.Set(new CultureInfo("en-US"), null); dictionary.GetBestLanguage(new CultureInfo("es-ES")).Should().Be("germanValue", because: "No English US, should fall back to first entry in collection"); }
public void TestRemoveRange() { var dictionary = new LocalizableStringCollection { "neutralValue", { "de-DE", "germanyValue" }, // Intential duplicates (should be ignored) "neutralValue", { "de-DE", "germanyValue" } }; dictionary.Set(LocalizableString.DefaultLanguage, null); dictionary.ContainsExactLanguage(LocalizableString.DefaultLanguage).Should().BeFalse(because: "Unspecified language should default to English generic"); dictionary.Set(new CultureInfo("de-DE"), null); dictionary.ContainsExactLanguage(new CultureInfo("de-DE")).Should().BeFalse(); }
public void TestSet() { var dictionary = new LocalizableStringCollection { "neutralValue", { "de-DE", "germanyValue" }, // Intential duplicates (should be removed) "neutralValue", { "de-DE", "germanyValue" } }; dictionary.Set(LocalizableString.DefaultLanguage, "neutralValue2"); dictionary.Set(new CultureInfo("de-DE"), "germanyValue2"); dictionary.GetExactLanguage(LocalizableString.DefaultLanguage).Should().Be("neutralValue2"); dictionary.GetExactLanguage(new CultureInfo("de-DE")).Should().Be("germanyValue2"); }