Mock implementation of ITextLocalizer with simplest of logic: · Supports single msgid/msgstr pair passed to cstor. · GetText checks that the UserLanguage spec. matches "en" and if so and msgid matches that passed to cstor, then returns the msgstr passed to cstor. Otherwise returns null.
상속: ITextLocalizer
예제 #1
0
        public void NuggetLocalizer_can_translate_unicode_nugget()
        {
            var textLocalizer = new TextLocalizer_Mock_SingleMessage("foo&bar", "blahblah");
            var obj           = new NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);

            // Lookup HtmlEncoded msgid.
            var pre  = "[[[foo\u0026amp;bar]]]";
            var post = obj.ProcessNuggets(pre, languages);

            Assert.AreEqual("blahblah", post);

            // Lookup un-HtmlEncoded msgid.
            pre  = "[[[foo\u0026bar]]]";
            post = obj.ProcessNuggets(pre, languages);
            Assert.AreEqual("blahblah", post);
        }
예제 #2
0
 public void NuggetLocalizer_can_process_nugget_htmlencoded()
 {
     string pre;
     string post;
    // Repo stores un-HtmlEncoded msgid.
     {
        // Arrange.
         ITextLocalizer textLocalizer = new TextLocalizer_Mock_SingleMessage("foo&bar", "blahblah");
         i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);
        // Lookup HtmlEncoded msgid.
         pre = "[[[foo&bar]]]";
         post = obj.ProcessNuggets(pre, languages);
         Assert.AreEqual("blahblah", post);
        // Lookup un-HtmlEncoded msgid.
         pre = "[[[foo&bar]]]";
         post = obj.ProcessNuggets(pre, languages);
         Assert.AreEqual("blahblah", post);
     }
    // Repo stores HtmlEncoded msgid.
     {
        // Arrange.
         ITextLocalizer textLocalizer = new TextLocalizer_Mock_SingleMessage("foo&bar", "blahblah");
         i18n.NuggetLocalizer obj = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);
        // Lookup HtmlEncoded msgid.
         pre = "[[[foo&bar]]]";
         post = obj.ProcessNuggets(pre, languages);
         Assert.AreEqual("blahblah", post);
        // Lookup un-HtmlEncoded msgid.
         //pre = "[[[foo&bar]]]";
         //post = obj.ProcessNuggets(pre, languages);
         //Assert.AreEqual("blahblah", post);
             // NB: this scenario is not supported at present.
             // If it is deemed to be required, add an extra step to the delegate
             // within NuggetLocalizer.ProcessNuggets such that HttpUtility.HtmlEncode(nugget.MsgId)
             // is passed to GetText (and same for nugget.Comment).
     }
 }
예제 #3
0
 public void NuggetLocalizer_can_process_nugget_htmlencoded()
 {
     string pre;
     string post;
     // Repo stores un-HtmlEncoded msgid.
     {
         // Arrange.
         ITextLocalizer       textLocalizer = new TextLocalizer_Mock_SingleMessage("foo&bar", "blahblah");
         i18n.NuggetLocalizer obj           = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);
         // Lookup HtmlEncoded msgid.
         pre  = "[[[foo&bar]]]";
         post = obj.ProcessNuggets(pre, languages);
         Assert.AreEqual("blahblah", post);
         // Lookup un-HtmlEncoded msgid.
         pre  = "[[[foo&bar]]]";
         post = obj.ProcessNuggets(pre, languages);
         Assert.AreEqual("blahblah", post);
     }
     // Repo stores HtmlEncoded msgid.
     {
         // Arrange.
         ITextLocalizer       textLocalizer = new TextLocalizer_Mock_SingleMessage("foo&bar", "blahblah");
         i18n.NuggetLocalizer obj           = new i18n.NuggetLocalizer(new i18nSettings(new WebConfigSettingService()), textLocalizer);
         // Lookup HtmlEncoded msgid.
         pre  = "[[[foo&bar]]]";
         post = obj.ProcessNuggets(pre, languages);
         Assert.AreEqual("blahblah", post);
         // Lookup un-HtmlEncoded msgid.
         //pre = "[[[foo&bar]]]";
         //post = obj.ProcessNuggets(pre, languages);
         //Assert.AreEqual("blahblah", post);
         // NB: this scenario is not supported at present.
         // If it is deemed to be required, add an extra step to the delegate
         // within NuggetLocalizer.ProcessNuggets such that HttpUtility.HtmlEncode(nugget.MsgId)
         // is passed to GetText (and same for nugget.Comment).
     }
 }