Exemple #1
0
        public void ConvertToLikeClause()
        {
            Localizable.ConvertToLikeClause("en", "pi__a", '#').Should().Be.EqualTo("%#en##pi__a#%");
            Localizable.ConvertToLikeClause(new CultureInfo("en"), "pi__a", '#').Should().Be.EqualTo("%#en##pi__a#%");

            // should use the DefaultKeyValueEncloser
            Localizable.ConvertToLikeClause("en", "pi__a").Should().Be.EqualTo("%~en~~pi__a~%");
            Localizable.ConvertToLikeClause(new CultureInfo("en"), "pi__a").Should().Be.EqualTo("%~en~~pi__a~%");

            // with default values
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            "pi__a".ToLocalizableLikeClause('#')
            .Should("should use the CurrentCulture").Be.EqualTo("%#en-US##pi__a#%");

            "pi__a".ToLocalizableLikeClause()
            .Should("should use the CurrentCulture and DefaultKeyValueEncloser").Be.EqualTo("%~en-US~~pi__a~%");
        }
        public void QueryWithHql()
        {
            FillDb();
            using (ISession s = OpenSession())
            {
                s.CreateQuery("from EntityWithLocalizableProperty e where e.LocalizableDescriptions like :pTemplate")
                .SetString("pTemplate", Localizable.ConvertToLikeClause("en-US", "H_l%"))
                .List()
                .Count
                .Should().Be.EqualTo(1);

                s.CreateQuery("from EntityWithLocalizableProperty e where e.LocalizableDescriptions like :pTemplate")
                .SetString("pTemplate", Localizable.ConvertToLikeClause("en-US", "H_l_"))
                .List()
                .Count
                .Should().Be.EqualTo(0);
            }
            Cleanup();
        }