コード例 #1
0
        public void EnumLocalTexts_Initialize_ThrowsException_IfNoLocalTextRegistryIsRegistered()
        {
            using (new MunqContext())
            {
                var exception = Assert.Throws <KeyNotFoundException>(() =>
                                                                     EnumLocalTextRegistration.Initialize(new[] { this.GetType().Assembly }));

                Assert.Contains(typeof(ILocalTextRegistry).Name, exception.Message);
            }
        }
コード例 #2
0
        public void EnumLocalTexts_Initialize_SearchesOnlyGivenAssemblies()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();

                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

                EnumLocalTextRegistration.Initialize(new[] { typeof(LocalText).Assembly });

                A.CallTo(() => registry.Add(A <string> ._, A <string> .That.Contains("EnumWithoutKey"), A <string> ._))
                .MustNotHaveHappened();
            }
        }
コード例 #3
0
        public void EnumLocalTexts_Initialize_UsesRegisteredLocalTextRegistry()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();

                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

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

                A.CallTo(() => registry.Add(A <string> ._, A <string> ._, A <string> ._))
                .MustHaveHappened(Repeated.AtLeast.Twice);
            }
        }
コード例 #4
0
        public static void InitializeLocalTexts()
        {
            var registrar = Dependency.Resolve <IDependencyRegistrar>();

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

            NestedLocalTextRegistration.Initialize(ExtensibilityHelper.SelfAssemblies);
            EnumLocalTextRegistration.Initialize(ExtensibilityHelper.SelfAssemblies);
            EntityLocalTexts.Initialize();
            JsonLocalTextRegistration.AddFromFilesInFolder(HostingEnvironment.MapPath("~/Scripts/serenity/texts/"));
            JsonLocalTextRegistration.AddFromFilesInFolder(HostingEnvironment.MapPath("~/Scripts/site/texts/"));
        }
コード例 #5
0
        public void EnumLocalTexts_Initialize_UsesKey_IfKeyAttributeIsPresent()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();

                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

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

                string expectedKey = "Enums.My.CoolEnumKey." +
                                     EnumWithKey.WithDescriptionKey.GetName();

                A.CallTo(() => registry.Add(A <string> ._, expectedKey, "Description for WithDescriptionKey"))
                .MustHaveHappened(Repeated.Exactly.Once);
            }
        }
コード例 #6
0
        public void EnumLocalTexts_Initialize_UsesLanguageSpecified()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();

                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

                EnumLocalTextRegistration.Initialize(new[] { this.GetType().Assembly }, "es");

                A.CallTo(() => registry.Add("es", A <string> ._, A <string> ._))
                .MustHaveHappened();

                A.CallTo(() => registry.Add(A <string> .That.Not.IsEqualTo("es"), A <string> ._, A <string> ._))
                .MustNotHaveHappened();
            }
        }
コード例 #7
0
        public void EnumLocalTexts_Initialize_UsesFullName_IfEnumKeyAttributeIsNotPresent()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();

                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

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

                string expectedKey = "Enums." + typeof(EnumWithoutKey).FullName + "." +
                                     EnumWithoutKey.WithDescriptionNoKey.GetName();

                A.CallTo(() => registry.Add(A <string> ._, expectedKey, "Description for WithDescriptionNoKey"))
                .MustHaveHappened(1, Times.Exactly);
            }
        }
コード例 #8
0
        public void EnumLocalTexts_Initialize_SkipsEnumValuesWithoutDescriptionAttribute()
        {
            using (new MunqContext())
            {
                var registry = A.Fake <ILocalTextRegistry>();

                Dependency.Resolve <IDependencyRegistrar>()
                .RegisterInstance(registry);

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

                string unexpectedKey1 = "Enums.My.CoolEnumKey." +
                                        EnumWithKey.NoDescriptionKey.GetName();

                string unexpectedKey2 = "Enums." + typeof(EnumWithoutKey).FullName + "." +
                                        EnumWithoutKey.NoDescriptionNoKey.GetName();

                A.CallTo(() => registry.Add(A <string> ._, unexpectedKey1, A <string> ._))
                .MustNotHaveHappened();

                A.CallTo(() => registry.Add(A <string> ._, unexpectedKey2, A <string> ._))
                .MustNotHaveHappened();
            }
        }