// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.AspNetCore.Mvc.FunctionalTests { public static class MvcWebApplicationBuilderExtensions { /// /// Sets up an that configures the at the /// beginning of the pipeline to change the and /// of the thread so that they match the cultures in and for the rest of the /// . /// /// The culture to use when processing . /// The UI culture to use when processing . /// An instance of this public static IWebHostBuilder UseRequestCulture(this IWebHostBuilder builder, string culture, string uiCulture) where TStartup : class { if (culture == null) { throw new ArgumentNullException(nameof(culture)); } if (uiCulture == null) { throw new ArgumentNullException(nameof(uiCulture)); } builder.ConfigureServices(services => { services.TryAddSingleton(new TestCulture { Culture = culture, UICulture = uiCulture }); services.TryAddEnumerable(ServiceDescriptor.Singleton()); }); return builder; } } }