Пример #1
0
        public void SetDefaultCulture()
        {
            var container = new CultureContentContainer();
            var sut       = new ContentHandler(container);

            //set a couple of cultures
            sut.AddCultureContents(new Dictionary <CultureInfo, ICultureContent> {
                { new CultureInfo("nl-NL"), null },
                { new CultureInfo("ru-KZ"), null },
                { new CultureInfo("en-GB"), null }
            });

            //make sure it is something else before setting
            var cultureInfo = sut.GetDefaultCulture();

            Assert.Equal("nl", cultureInfo.TwoLetterISOLanguageName);
            Assert.Equal("Dutch (Netherlands)", cultureInfo.DisplayName);
            Assert.Equal("nl-NL", cultureInfo.Name);

            sut.SetDefaultCulture(new CultureInfo("ru-KZ"));
            cultureInfo = sut.GetDefaultCulture();
            Assert.Equal("ru", cultureInfo.TwoLetterISOLanguageName);
            Assert.Equal("русский (Казахстан)", cultureInfo.DisplayName);
            Assert.Equal("ru-KZ", cultureInfo.Name);
        }
Пример #2
0
        public void GetDefaultCultureEmpty()
        {
            var container = new CultureContentContainer();
            var sut       = new ContentHandler(container);

            Assert.Throws <IndexOutOfRangeException>(() => sut.GetDefaultCulture());
        }
Пример #3
0
        public void GetDefaultCulture()
        {
            //return the only one available
            var container = new CultureContentContainer();
            var sut       = new ContentHandler(container);

            sut.AddCultureContents(new Dictionary <CultureInfo, ICultureContent> {
                { new CultureInfo("ru-KZ"), null }
            });
            Assert.Equal("ru-KZ", sut.GetDefaultCulture().Name);

            //return the first available
            sut = new ContentHandler(container);
            sut.AddCultureContents(new Dictionary <CultureInfo, ICultureContent> {
                { new CultureInfo("ru-KZ"), null },
                { new CultureInfo("de-DE"), null }
            });
            Assert.Equal("ru-KZ", sut.GetDefaultCulture().Name);

            //set the cultureContents again, the defaultCulture is reset
            sut.AddCultureContents(new Dictionary <CultureInfo, ICultureContent> {
                { new CultureInfo("ru-KZ"), null },
                { new CultureInfo("en-GB"), null }
            });
            Assert.Equal("en-GB", sut.GetDefaultCulture().Name);

            //return one that has a higher priority
            sut = new ContentHandler(container);
            sut.AddCultureContents(new Dictionary <CultureInfo, ICultureContent> {
                { new CultureInfo("ru-KZ"), null },
                { new CultureInfo("en-GB"), null }
            });
            Assert.Equal("en-GB", sut.GetDefaultCulture().Name);

            //return the one set
            sut = new ContentHandler(container);
            sut.AddCultureContents(new Dictionary <CultureInfo, ICultureContent> {
                { new CultureInfo("ru-KZ"), null },
                { new CultureInfo("en-GB"), null }
            });
            sut.SetDefaultCulture(new CultureInfo("ru-KZ"));
            Assert.Equal("ru-KZ", sut.GetDefaultCulture().Name);
        }