locked
Localization test with UnitTest does not change local RRS feed

  • Question

  • Hello,

    WinStore app - ApplicationResourcesCPP - illustrates providing the resources from a WinRT Component. I test this approach in the C# TestUnitLibrary, for this I have to change the initialisation of the resourceLoader to :

    ResourceLoader::GetForViewIndependentUse("AppResourceClassLibrary/Resources");

    - it's needed as UnitTest is not WindowsCore component, the application works fine after those changes.

    Running test method with the code:

    ApplicationLanguages.PrimaryLanguageOverride = "en-US";

    varlib = newAppResourceClassLibrary.Class1();

    varstrLib = "Retrieved from class library: "+ lib.GetString();

    Debug.WriteLine("en-US -> "+ strLib);

    ApplicationLanguages.PrimaryLanguageOverride = "fr-FR";

    strLib =

    "Retrieved from class library: "+ lib.GetString();

    Debug.WriteLine("fr-FR -> "+ strLib);

    lib =

    newAppResourceClassLibrary.Class1();

    strLib =

    "Retrieved from class library: "+ lib.GetString();

    Debug.WriteLine("fr-FR -> "+ strLib);

    always produces the English resource version.

    What could be wrong, specific in the UnitTest and how those tests could be done?

    Sunday, January 4, 2015 4:43 PM

All replies

  • Hi Alexandre,

    Do you get any error message in your side if you debug/run your unit tests?

    >> Always produces the English resource version.

    Instead of “en-US”, if you use “de”, “de-DE” how about the result?

    If you use “US”, how about the result?

    >> ApplicationLanguages.PrimaryLanguageOverride = "en-US";

    It seems that ApplicationLanguages.PrimaryLanguageOverride expects a BCP-47 language tag, whether it is related to the BCP-47 language tag.

    Reference:

    http://blog.instance-factory.com/?cat=45

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

    Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 5, 2015 8:16 AM
  • Hi Jack,

    Thank you for your reply.

    Finally the c++ cx resource library started working rendering the correct language resources in c# unity tests :

    setting ApplicationLanguages.PrimaryLanguageOverride  to fr, fr-FR - produced French resources, while

    setting ApplicationLanguages.PrimaryLanguageOverride to en, en-US, US - English once BUT only in Debug mode:

    en-US set
    new res -> Hello World
    FR set
    res -> Bonjour, Monde
    new res -> Bonjour, Monde
    US set
    res -> Hello World
    new res -> Hello World
    fr set
    res -> Bonjour, Monde
    new res -> Bonjour, Monde
    en set
    res -> Hello World
    new res -> Hello World

    In Run mode - it's mixed (???):

    en-US set
    new res -> Hello World
    FR set
    res -> Hello World
    new res -> Hello World
    US set
    res -> Bonjour, Monde
    new res -> Bonjour, Monde
    fr set
    res -> Hello World
    new res -> Hello World
    en set
    res -> Bonjour, Monde
    new res -> Bonjour, Monde

    curiously it's two steps delayed!?

    The test method:

    [TestMethod]
    public void TestMethod1()
    {
     {
      ApplicationLanguages.PrimaryLanguageOverride = "en-US";
      Debug.WriteLine("en-US set");
     }
     var lib = new AppResourceClassLibrary.Class1();
     Debug.WriteLine("new res -> " + lib.GetString());

     {
      ApplicationLanguages.PrimaryLanguageOverride = "FR";
      Debug.WriteLine("FR set");
     }
     Debug.WriteLine("res -> " + lib.GetString());

     lib = new AppResourceClassLibrary.Class1();
     Debug.WriteLine("new res -> " + lib.GetString());
     {
      ApplicationLanguages.PrimaryLanguageOverride = "US";
      Debug.WriteLine("US set");
     }
     Debug.WriteLine("res -> " + lib.GetString());

     lib = new AppResourceClassLibrary.Class1();
     Debug.WriteLine("new res -> " + lib.GetString());
     {
      ApplicationLanguages.PrimaryLanguageOverride = "fr";
      Debug.WriteLine("fr set");
     }
     Debug.WriteLine("res -> " + lib.GetString());

     lib = new AppResourceClassLibrary.Class1();
     Debug.WriteLine("new res -> " + lib.GetString());
     {
      ApplicationLanguages.PrimaryLanguageOverride = "en";
      Debug.WriteLine("en set");
     }
     Debug.WriteLine("res -> " + lib.GetString());

     lib = new AppResourceClassLibrary.Class1();
     Debug.WriteLine("new res -> " + lib.GetString());

    }

    What could be the reason?

    Thanks in advance

    Monday, January 5, 2015 1:12 PM
  • Hi Alexandre,

    To really repro this issue, it would require the previous windows store app, would you mind sharing us a simple sample? So I could test it in my side with the same Environment.

    Please tell me the real windows Environment and the VS version in your side.

    Please attach your Visual Studio project, you can upload it to the one drive, and then share the download link in your post. Please also attach a screenshot image in your post about the result in your side.

    If you got error messages, please also show the whole error messages in your post.

    If there's any concern, please feel free to let me know.

    Best Regards,

    Jack 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 6, 2015 8:09 AM