4

Seems like people are not getting the whole tag concept. Before you mark this as a duplicate, understand that Thread.CurrentThread.CurrentCulture does not exist in WinRT/Windows Runtime.

Want to test following code with a culture other than the default:

public string Now =>
    DateTime.Now.ToString("g", new CultureInfo(CultureInfo.CurrentUICulture.Name));

So far,

[UITestMethod]
public void UI_NowIsLocalizable()
{
    // Arrange
    Clock clock = new Clock();
    Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "de-DE";
    string expected = DateTime.Now.ToString("g");

    // Act
    string actual = clock.Now;

    // Assert
    Assert.AreEqual(expected, actual);
}

While debugging the test, CultureInfo.CurrentUICulture.Name still shows us-en and the test passes (should fail).

O.O
  • 11,077
  • 18
  • 94
  • 182
  • Possible duplicate of [Is there a way of setting culture for a whole application? All current threads and new threads?](http://stackoverflow.com/questions/468791/is-there-a-way-of-setting-culture-for-a-whole-application-all-current-threads-a) – Jonathon Chase Oct 07 '15 at 21:37
  • why aren't you just passing `CultureInfo.CurrentUICulture`? – Daniel A. White Oct 07 '15 at 21:56
  • @JonathonChase not a duplicate - WinRT is different. – Alexei Levenkov Oct 07 '15 at 22:17
  • You ought to check it first against the ApplicationLanguages.ManifestLanguages list. Low odds in a unit test no doubt. – Hans Passant Oct 07 '15 at 23:16
  • How come not to fake the `CurrentInfo.CurrentUICulture.Name` ? That sounds more reasonable as it's a dependency for your method. – akardon Oct 17 '16 at 22:04

0 Answers0