public void NestedLocalTextRegistration_Initialize_RemovesLastUnderscoreFromClassName()
        {
            using (new MunqContext())
            {
                var registry1 = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry1);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                A.CallTo(() => registry1.Add(LocalText.InvariantLanguageID, "Y4", "4"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry1.Add(LocalText.InvariantLanguageID, "Y4.Y5", "5"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
        public void NestedLocalTextRegistration_Initialize_SkipsClassesWithoutNestedLocalTextsAttribute()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                A.CallTo(() => registry.Add(LocalText.InvariantLanguageID, "N.N1", "5"))
                .MustNotHaveHappened();

                A.CallTo(() => registry.Add(LocalText.InvariantLanguageID, "Y.Y1", "1"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
        public void NestedLocalTextRegistration_Initialize_ReplacesLocalTextObjectsWithInitializedLocalTextObjects()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                Assert.IsType <InitializedLocalText>(Texts.Y.Y1);
                Assert.IsType <InitializedLocalText>(Texts.Y.Y2);
                Assert.IsType <InitializedLocalText>(Texts.Y.YI.Y3);
                Assert.IsType <InitializedLocalText>(Texts.Y4);

                Assert.Equal("Y.Y1", Texts.Y.Y1.Key);
                Assert.Equal("1", ((InitializedLocalText)Texts.Y.Y1).InitialText);
            }
        }
Example #4
0
        public static void InitializeLocalTexts()
        {
            var registrar = Dependency.Resolve <IDependencyRegistrar>();

            var registry = Dependency.TryResolve <ILocalTextRegistry>();

            if (registry == null)
            {
                registry = new LocalTextRegistry();
                registrar.RegisterInstance <ILocalTextRegistry>(registry);
            }

            NestedLocalTextRegistration.Initialize(ExtensibilityHelper.SelfAssemblies);
            NestedPermissionKeyRegistration.AddNestedPermissions(registry, ExtensibilityHelper.SelfAssemblies);
            EnumLocalTextRegistration.Initialize(ExtensibilityHelper.SelfAssemblies);
            EntityLocalTexts.Initialize();
            JsonLocalTextRegistration.AddFromFilesInFolder(HostingEnvironment.MapPath("~/Scripts/serenity/texts/"));
            JsonLocalTextRegistration.AddFromFilesInFolder(HostingEnvironment.MapPath("~/Scripts/site/texts/"));
            JsonLocalTextRegistration.AddFromFilesInFolder(HostingEnvironment.MapPath("~/App_Data/texts/"));
        }
        public void NestedLocalTextRegistration_Initialize_CanBeCalledMoreThanOnce()
        {
            using (new MunqContext())
            {
                var registry1 = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry1);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                A.CallTo(() => registry1.Add(LocalText.InvariantLanguageID, "Y.Y1", "1"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry1.Add(LocalText.InvariantLanguageID, "Y.Y2", "2"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry1.Add(LocalText.InvariantLanguageID, "Y.YI.Y3", "3"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry1.Add(LocalText.InvariantLanguageID, "Y4", "4"))
                .MustHaveHappened(Repeated.Exactly.Once);

                var registry2 = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry2);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                A.CallTo(() => registry2.Add(LocalText.InvariantLanguageID, "Y.Y1", "1"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry2.Add(LocalText.InvariantLanguageID, "Y.Y2", "2"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry2.Add(LocalText.InvariantLanguageID, "Y.YI.Y3", "3"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry2.Add(LocalText.InvariantLanguageID, "Y4", "4"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
        public void NestedLocalTextRegistration_Initialize_UsesLanguageAndPrefixIfSpecified()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                A.CallTo(() => registry.Add("jp", "x.X.X1", "1"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry.Add("jp", "x.X.X2", "2"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry.Add("jp", "x.X.XI.X3", "3"))
                .MustHaveHappened(Repeated.Exactly.Once);

                A.CallTo(() => registry.Add("jp", "x.X4", "4"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
        public void NestedLocalTextRegistration_Initialize_UsesInvariantLanguageAndNoPrefixByDefault()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                A.CallTo(() => registry.Add(LocalText.InvariantLanguageID, "Y.Y1", "1"))
                .MustHaveHappened(1, Times.Exactly);

                A.CallTo(() => registry.Add(LocalText.InvariantLanguageID, "Y.Y2", "2"))
                .MustHaveHappened(1, Times.Exactly);

                A.CallTo(() => registry.Add(LocalText.InvariantLanguageID, "Y.YI.Y3", "3"))
                .MustHaveHappened(1, Times.Exactly);

                A.CallTo(() => registry.Add(LocalText.InvariantLanguageID, "Y4", "4"))
                .MustHaveHappened(1, Times.Exactly);
            }
        }
        public void NestedLocalTextRegistration_Initialize_UsesLanguageIfSpecified()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();
                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

                NestedLocalTextRegistration.Initialize(new[] { this.GetType().Assembly });

                A.CallTo(() => registry.Add("es", "Z.Z1", "1"))
                .MustHaveHappened(1, Times.Exactly);

                A.CallTo(() => registry.Add("es", "Z.Z2", "2"))
                .MustHaveHappened(1, Times.Exactly);

                A.CallTo(() => registry.Add("es", "Z.ZI.Z3", "3"))
                .MustHaveHappened(1, Times.Exactly);

                A.CallTo(() => registry.Add("es", "Z4", "4"))
                .MustHaveHappened(1, Times.Exactly);
            }
        }