示例#1
0
        public void WHEN_Localized_Value_Is_Found_SHOULD_Render_LocalizedValue()
        {
            //Arrange
            var localizationProvider = LocalizationProviderFactory.CreateKnowsItAll();
            var helpers = new LocalizeHelper(localizationProvider.Object);

            Handlebars.RegisterHelper(helpers.HelperName, helpers.HelperFunction);

            string cultureName  = "en-CA";
            string categoryName = GetRandom.String(32);
            string keyName      = GetRandom.String(32);
            var    template     = Handlebars.Compile("{{localize CategoryName KeyName}}");

            //Act
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(cultureName);
            var result = template.Invoke(new { CategoryName = categoryName, KeyName = keyName });

            result.Should().Be(string.Format("{0}:{1}.{2}", cultureName, categoryName, keyName), "Because this is the mocked value");
        }
示例#2
0
        public void WHEN_Using_The_Helper_The_Culture_From_The_UIThread_SHOULD_Be_Used(string expectedCultureName)
        {
            //Arrange
            var localizationProvider = LocalizationProviderFactory.CreateKnowsItAll();
            var helpers = new LocalizeHelper(localizationProvider.Object);

            Handlebars.RegisterHelper(helpers.HelperName, helpers.HelperFunction);

            string categoryName = GetRandom.String(32);
            string keyName      = GetRandom.String(32);
            var    template     = Handlebars.Compile("{{localize CategoryName KeyName}}");

            //Act
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(expectedCultureName);
            var result = template.Invoke(new { CategoryName = categoryName, KeyName = keyName });

            //Assert
            result.Should().Be(string.Format("{0}:{1}.{2}", expectedCultureName, categoryName, keyName), "Because no better solution was available at this time");
        }
        public void WHEN_Localized_Value_Is_Not_Null_Or_Empty_Found_SHOULD_Render_Primary_Template()
        {
            //Arrange
            var localizationProvider = LocalizationProviderFactory.CreateKnowsItAll();
            var helpers = new IfIsLocalizedBlockHelper(localizationProvider.Object);

            Handlebars.RegisterHelper(helpers.HelperName, helpers.HelperFunction);

            string categoryName = GetRandom.String(32);
            string keyName      = GetRandom.String(32);

            var template = Handlebars.Compile("{{#if_localized CategoryName KeyName}}Primary{{else}}Inverse{{/if_localized}}");

            //Act
            var result = template.Invoke(new { CategoryName = categoryName, KeyName = keyName });

            //Assert
            result.Should().Be("Primary");
        }
示例#4
0
        public void WHEN_Called_With_Variables_SHOULD_Render_Same_As_With_Literals()
        {
            //Arrange
            var localizationProvider = LocalizationProviderFactory.CreateKnowsItAll();
            var helpers = new LocalizeHelper(localizationProvider.Object);

            Handlebars.RegisterHelper(helpers.HelperName, helpers.HelperFunction);

            string categoryName      = GetRandom.String(32);
            string keyName           = GetRandom.String(32);
            var    templateVariables = Handlebars.Compile("{{localize CategoryName KeyName}}");
            var    templateLiteral   = Handlebars.Compile("{{localize '" + categoryName + "' '" + keyName + "'}}");

            //Act
            var resultFromVariables = templateVariables.Invoke(new { CategoryName = categoryName, KeyName = keyName });
            var resultFromLiteral   = templateLiteral.Invoke(null);

            //Assert
            resultFromVariables.Should().BeEquivalentTo(resultFromLiteral);
        }