Пример #1
0
    public void AddInitialRequestCultureProvider_ShouldBeInsertedAtFirstPostion()
    {
        // Arrange
        var options  = new RequestLocalizationOptions();
        var provider = new CustomRequestCultureProvider(context => Task.FromResult(new ProviderCultureResult("ar-YE")));

        // Act
        options.AddInitialRequestCultureProvider(provider);

        // Assert
        Assert.Same(provider, options.RequestCultureProviders[0]);
    }
        void ConfigureRequestLocalizationProvider(IServiceCollection services)
        {
            LanguageItem[] LangItems = Languages.Items;

            CustomRequestCultureProvider Provider = new CustomRequestCultureProvider(async(HttpContext) => {
                await Task.Yield();
                return(new ProviderCultureResult(Session.Language.CultureCode));
            });

            services.Configure <RequestLocalizationOptions>(options =>
            {
                options.DefaultRequestCulture = new RequestCulture(LangItems[0].CultureCode);
                options.SupportedCultures     = LangItems.Select(item => item.GetCulture()).ToList();
                options.SupportedUICultures   = options.SupportedCultures;

                //options.RequestCultureProviders.Clear();
                options.RequestCultureProviders.Insert(0, Provider);
            });
        }