Beispiel #1
0
        public void GetCultureTabFromValueTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal("fr-CH", cultures.GetCultureTab("c=fr-CH|uic=en-GB"));
            Assert.Equal("fr-CH", cultures.GetCultureTab("culture=fr-CH&ui-culture=en-GB", false));
        }
Beispiel #2
0
        public void IsSupportedFailTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.False(cultures.IsSupported(null));
            Assert.False(cultures.IsSupported(""));
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <RequestLocalizationOptions>(options =>
            {
                var cultures = new AppSupportedCultures();
                options.DefaultRequestCulture = new RequestCulture(culture: cultures.GetCultureTabForNeutralCulture(), uiCulture: cultures.GetDefaultUiCultureTab());
                options.SupportedCultures     = cultures.GetSupportedCulturesInfo();
                options.SupportedUICultures   = cultures.GetSupportedCulturesInfo();
                //options.FallBackToParentCultures = true;    //default to true - if en-US isn't in list of SupportedCultures then fall-back to en
                //options.FallBackToParentUICultures = true;  //default to true - if en-US isn't in list of SupportedUICultures then fall-back to en
                options.AddInitialRequestCultureProvider(new AppRequestCultureProvider(options));
            });
            services.AddHttpContextAccessor();
            services.AddRazorPages();

            if (Env.IsDevelopment() == false)
            {
                services.AddHsts(options =>
                {
                    options.Preload           = true;
                    options.IncludeSubDomains = true;
                    options.MaxAge            = TimeSpan.FromDays(60);
                    //options.ExcludedHosts.Add("example.com");
                    //options.ExcludedHosts.Add("www.example.com");
                });

                services.AddHttpsRedirection(options =>
                {
                    options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
                    options.HttpsPort          = 5001;
                });
            }
        }
Beispiel #4
0
        public void IsSupportedTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.True(cultures.IsSupported("en-GB"));
            Assert.False(cultures.IsSupported("xx-GB"));
        }
        public void DefaultSelectedTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal(AppSupportedCultures.EnGb, cultures.Selected);
            Assert.Equal(AppSupportedCultures.EnGb, cultures.GetCultureTabForNeutralCulture());
            Assert.Equal(AppSupportedCultures.En, cultures.GetDefaultUiCultureTab());
        }
Beispiel #6
0
        public void GetCulturesValueToSetFailTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal("c=en-GB|uic=en", cultures.GetCulturesEncodedValue(null, null));
            Assert.Equal("c=en-GB|uic=en", cultures.GetCulturesEncodedValue(null, "fr-CH"));   //both parameters must be valid
            Assert.Equal("c=en-GB|uic=en", cultures.GetCulturesEncodedValue("fr-CH", null));   //both parameters must be valid
        }
Beispiel #7
0
 public IndexModel(IHttpContextAccessor httpContextAccessor)
 {
     _rm = null;
     _supportedCultures   = new AppSupportedCultures();
     _supportedTimeZones  = new AppSupportedTimeZones();
     _httpContextAccessor = httpContextAccessor;
     _clock = SystemClock.Instance;
 }
Beispiel #8
0
        public void GetSupportedCulturesInfoTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal(6, cultures.GetSupportedCulturesInfo().Length);
            Assert.Equal("en", cultures.GetSupportedCulturesInfo()[0].Name);
            Assert.Equal("en-GB", cultures.GetSupportedCulturesInfo()[1].Name);
            Assert.Equal("de-CH", cultures.GetSupportedCulturesInfo()[5].Name);
        }
Beispiel #9
0
        public void GetCultureInfoTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal(6, cultures.GetSupportedCultures().Length);

            Assert.Equal("en", cultures.GetCultureInfo("en").Name);
            Assert.Equal("en-GB", cultures.GetCultureInfo("en-GB").Name);
            Assert.Equal("de-CH", cultures.GetCultureInfo("de-CH").Name);

            Assert.Null(cultures.GetCultureInfo("xxx"));
        }
Beispiel #10
0
        public void GetCulturesValueToSetTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal("c=fr-CH|uic=en-GB", cultures.GetCulturesEncodedValue("fr-CH", "en-GB"));
            Assert.Equal("c=en-GB|uic=fr-CH", cultures.GetCulturesEncodedValue("en-GB", "fr-CH"));
            Assert.Equal("c=fr-CH|uic=en-GB", cultures.GetCulturesEncodedValue("fr-CH", "en-GB"));
            Assert.Equal("c=en-GB|uic=fr-CH", cultures.GetCulturesEncodedValue("en-GB", "fr-CH"));

            Assert.Equal("culture=fr-CH&ui-culture=en-GB", cultures.GetCulturesEncodedValue("fr-CH", "en-GB", false));
            Assert.Equal("culture=en-GB&ui-culture=fr-CH", cultures.GetCulturesEncodedValue("en-GB", "fr-CH", false));
        }
Beispiel #11
0
        public void GetUiCultureTabFromValueFailTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal("en", cultures.GetUiCultureTab(""));
            Assert.Equal("en", cultures.GetUiCultureTab(null));

            Assert.Equal("en", cultures.GetUiCultureTab("c=fr-CH£uic=en-GB"));
            Assert.Equal("en", cultures.GetUiCultureTab("c=fr-CH|uic="));
            Assert.Equal("en", cultures.GetUiCultureTab("c=fr-CH|uicx="));
            Assert.Equal("en", cultures.GetUiCultureTab("c=fr-CH"));
            Assert.Equal("en", cultures.GetUiCultureTab("c=en-GB"));
        }
        public void GetNearestMatchUiCultureTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal(AppSupportedCultures.En, cultures.GetNearestMatch("en", true));
            Assert.Equal(AppSupportedCultures.En, cultures.GetNearestMatch("en-GB", true));
            Assert.Equal(AppSupportedCultures.En, cultures.GetNearestMatch("en-US", true));
            Assert.Equal(AppSupportedCultures.En, cultures.GetNearestMatch("en-CH", true));

            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr-CH", true));
            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr-FR", true));

            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr", true));
            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr-CH", true));
            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr-FR", true));

            Assert.Equal(AppSupportedCultures.DeCh, cultures.GetNearestMatch("de", true));
            Assert.Equal(AppSupportedCultures.DeCh, cultures.GetNearestMatch("de-CH", true));
            Assert.Equal(AppSupportedCultures.DeCh, cultures.GetNearestMatch("de-FR", true));

            Assert.Equal(AppSupportedCultures.ItCh, cultures.GetNearestMatch("it", true));
            Assert.Equal(AppSupportedCultures.ItCh, cultures.GetNearestMatch("it-CH", true));
            Assert.Equal(AppSupportedCultures.ItCh, cultures.GetNearestMatch("it-FR", true));
        }
        public void GetNearestMatchCultureTest()
        {
            var cultures = new AppSupportedCultures();

            Assert.Equal(AppSupportedCultures.EnGb, cultures.GetNearestMatch(null));
            Assert.Equal(AppSupportedCultures.EnGb, cultures.GetNearestMatch("xxx"));

            Assert.Equal(AppSupportedCultures.EnGb, cultures.GetNearestMatch("en"));
            Assert.Equal(AppSupportedCultures.EnGb, cultures.GetNearestMatch("en-GB"));
            Assert.Equal(AppSupportedCultures.EnGb, cultures.GetNearestMatch("en-US"));
            Assert.Equal(AppSupportedCultures.EnGb, cultures.GetNearestMatch("en-CH"));

            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr"));
            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr-CH"));
            Assert.Equal(AppSupportedCultures.FrCh, cultures.GetNearestMatch("fr-FR"));

            Assert.Equal(AppSupportedCultures.DeCh, cultures.GetNearestMatch("de"));
            Assert.Equal(AppSupportedCultures.DeCh, cultures.GetNearestMatch("de-CH"));
            Assert.Equal(AppSupportedCultures.DeCh, cultures.GetNearestMatch("de-FR"));

            Assert.Equal(AppSupportedCultures.ItCh, cultures.GetNearestMatch("it"));
            Assert.Equal(AppSupportedCultures.ItCh, cultures.GetNearestMatch("it-CH"));
            Assert.Equal(AppSupportedCultures.ItCh, cultures.GetNearestMatch("it-FR"));
        }
Beispiel #14
0
 public AppRequestCultureProvider(RequestLocalizationOptions options)
 {
     Options            = options;
     _supportedCultures = new AppSupportedCultures();
 }
Beispiel #15
0
 public SettingsModel(IHttpContextAccessor httpContextAccessor)
 {
     _httpContextAccessor  = httpContextAccessor;
     SupportedAppTimeZones = new AppSupportedTimeZones();
     SupportedAppCultures  = new AppSupportedCultures();
 }
Beispiel #16
0
 public SettingsSummaryViewComponent(IHttpContextAccessor httpContextAccessor)
 {
     _supportedCultures   = new AppSupportedCultures();
     _supportedTimeZones  = new AppSupportedTimeZones();
     _httpContextAccessor = httpContextAccessor;
 }