From 0b013ae769273c426ada96d41a824cd9a37777a0 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Thu, 10 Dec 2015 22:10:07 -0800 Subject: [PATCH] Usability improvements: - Remove the defaultRequestCulture parameter from IApplicationBuilder.UseRequestLocalization and make it a property on RequestLocalizationOptions instead - Have just a single overload for IApplicationBuilder.UseRequestLocalization that takes the options - #164 --- samples/LocalizationSample/Startup.cs | 4 +- .../ApplicationBuilderExtensions.cs | 39 +------ .../RequestLocalizationMiddleware.cs | 19 +--- .../RequestLocalizationOptions.cs | 44 +++++-- .../StartupResourcesAtRootFolder.cs | 3 +- .../StartupResourcesInFolder.cs | 3 +- ...anguageHeaderRequestCultureProviderTest.cs | 12 +- .../CookieRequestCultureProviderTest.cs | 9 +- .../CustomRequestCultureProviderTest.cs | 3 +- .../QueryStringRequestCultureProviderTest.cs | 28 +++-- .../RequestLocalizationOptionsTest.cs | 107 ++++++++++++++++++ 11 files changed, 189 insertions(+), 82 deletions(-) create mode 100644 test/Microsoft.AspNet.Localization.Tests/RequestLocalizationOptionsTest.cs diff --git a/samples/LocalizationSample/Startup.cs b/samples/LocalizationSample/Startup.cs index 41fbedb3..a86f92ff 100644 --- a/samples/LocalizationSample/Startup.cs +++ b/samples/LocalizationSample/Startup.cs @@ -24,6 +24,8 @@ public void Configure(IApplicationBuilder app, IStringLocalizer SR) { var options = new RequestLocalizationOptions { + DefaultRequestCulture = new RequestCulture("en-US"), + // Set options here to change middleware behavior SupportedCultures = new List { @@ -58,7 +60,7 @@ public void Configure(IApplicationBuilder app, IStringLocalizer SR) //})); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Use(async (context, next) => { diff --git a/src/Microsoft.AspNet.Localization/ApplicationBuilderExtensions.cs b/src/Microsoft.AspNet.Localization/ApplicationBuilderExtensions.cs index 0076668f..2f4d77dd 100644 --- a/src/Microsoft.AspNet.Localization/ApplicationBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Localization/ApplicationBuilderExtensions.cs @@ -12,46 +12,16 @@ namespace Microsoft.AspNet.Builder /// public static class ApplicationBuilderExtensions { - /// - /// Adds the to automatically set culture information for - /// requests based on information provided by the client using the default options. - /// - /// The . - /// The default to use if none of the - /// requested cultures match supported cultures. - /// The . - public static IApplicationBuilder UseRequestLocalization( - this IApplicationBuilder app, - RequestCulture defaultRequestCulture) - { - if (app == null) - { - throw new ArgumentNullException(nameof(app)); - } - - if (defaultRequestCulture == null) - { - throw new ArgumentNullException(nameof(defaultRequestCulture)); - } - - var options = new RequestLocalizationOptions(); - - return UseRequestLocalization(app, options, defaultRequestCulture); - } - /// /// Adds the to automatically set culture information for /// requests based on information provided by the client. /// /// The . /// The options to configure the middleware with. - /// The default to use if none of the - /// requested cultures match supported cultures. /// The . public static IApplicationBuilder UseRequestLocalization( this IApplicationBuilder app, - RequestLocalizationOptions options, - RequestCulture defaultRequestCulture) + RequestLocalizationOptions options) { if (app == null) { @@ -63,12 +33,7 @@ public static IApplicationBuilder UseRequestLocalization( throw new ArgumentNullException(nameof(options)); } - if (defaultRequestCulture == null) - { - throw new ArgumentNullException(nameof(defaultRequestCulture)); - } - - return app.UseMiddleware(options, defaultRequestCulture); + return app.UseMiddleware(options); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Localization/RequestLocalizationMiddleware.cs b/src/Microsoft.AspNet.Localization/RequestLocalizationMiddleware.cs index 37bc88a6..e3d5e298 100644 --- a/src/Microsoft.AspNet.Localization/RequestLocalizationMiddleware.cs +++ b/src/Microsoft.AspNet.Localization/RequestLocalizationMiddleware.cs @@ -6,7 +6,6 @@ using System.Globalization; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.Extensions.Globalization; @@ -21,7 +20,6 @@ public class RequestLocalizationMiddleware { private readonly RequestDelegate _next; private readonly RequestLocalizationOptions _options; - private readonly RequestCulture _defaultRequestCulture; /// /// Creates a new . @@ -29,12 +27,9 @@ public class RequestLocalizationMiddleware /// The representing the next middleware in the pipeline. /// The representing the options for the /// . - /// The default to use if none of the - /// requested cultures match supported cultures. public RequestLocalizationMiddleware( RequestDelegate next, - RequestLocalizationOptions options, - RequestCulture defaultRequestCulture) + RequestLocalizationOptions options) { if (next == null) { @@ -46,14 +41,8 @@ public RequestLocalizationMiddleware( throw new ArgumentNullException(nameof(options)); } - if (defaultRequestCulture == null) - { - throw new ArgumentNullException(nameof(defaultRequestCulture)); - } - _next = next; _options = options; - _defaultRequestCulture = defaultRequestCulture; } /// @@ -68,7 +57,7 @@ public async Task Invoke(HttpContext context) throw new ArgumentNullException(nameof(context)); } - var requestCulture = _defaultRequestCulture; + var requestCulture = _options.DefaultRequestCulture; IRequestCultureProvider winningProvider = null; @@ -100,11 +89,11 @@ public async Task Invoke(HttpContext context) } if (cultureInfo == null && uiCultureInfo != null) { - cultureInfo = _defaultRequestCulture.Culture; + cultureInfo = _options.DefaultRequestCulture.Culture; } if (cultureInfo != null && uiCultureInfo == null) { - uiCultureInfo = _defaultRequestCulture.UICulture; + uiCultureInfo = _options.DefaultRequestCulture.UICulture; } var result = new RequestCulture(cultureInfo, uiCultureInfo); diff --git a/src/Microsoft.AspNet.Localization/RequestLocalizationOptions.cs b/src/Microsoft.AspNet.Localization/RequestLocalizationOptions.cs index 03eed4c3..8c243ea4 100644 --- a/src/Microsoft.AspNet.Localization/RequestLocalizationOptions.cs +++ b/src/Microsoft.AspNet.Localization/RequestLocalizationOptions.cs @@ -1,6 +1,7 @@ // 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 System.Collections.Generic; using System.Globalization; @@ -11,6 +12,9 @@ namespace Microsoft.AspNet.Localization /// public class RequestLocalizationOptions { + private RequestCulture _defaultRequestCulture = + new RequestCulture(CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture); + /// /// Creates a new with default values. /// @@ -25,20 +29,40 @@ public RequestLocalizationOptions() } /// - /// The cultures supported by the application. If this value is non-null, the - /// will only set the current request culture to an entry in this - /// list. A value of null means all cultures are supported. - /// Defaults to null. + /// Gets or sets the default culture to use for requests when a supported culture could not be determined by + /// one of the configured s. + /// Defaults to and . + /// + public RequestCulture DefaultRequestCulture + { + get + { + return _defaultRequestCulture; + } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _defaultRequestCulture = value; + } + } + + /// + /// The cultures supported by the application. The will only set + /// the current request culture to an entry in this list. + /// Defaults to . /// - public IList SupportedCultures { get; set; } + public IList SupportedCultures { get; set; } = new List { CultureInfo.CurrentCulture }; /// - /// The UI cultures supported by the application. If this value is non-null, the - /// will only set the current request culture to an entry in this - /// list. A value of null means all cultures are supported. - /// Defaults to null. + /// The UI cultures supported by the application. The will only set + /// the current request culture to an entry in this list. + /// Defaults to . /// - public IList SupportedUICultures { get; set; } + public IList SupportedUICultures { get; set; } = new List { CultureInfo.CurrentUICulture }; /// /// An ordered list of providers used to determine a request's culture information. The first provider that diff --git a/test/LocalizationWebsite/StartupResourcesAtRootFolder.cs b/test/LocalizationWebsite/StartupResourcesAtRootFolder.cs index 6efa759b..4c597151 100644 --- a/test/LocalizationWebsite/StartupResourcesAtRootFolder.cs +++ b/test/LocalizationWebsite/StartupResourcesAtRootFolder.cs @@ -31,6 +31,7 @@ public void Configure( var options = new RequestLocalizationOptions { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List() { new CultureInfo("fr-FR") @@ -41,7 +42,7 @@ public void Configure( } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); var stringLocalizer = stringLocalizerFactory.Create("Test", location: null); diff --git a/test/LocalizationWebsite/StartupResourcesInFolder.cs b/test/LocalizationWebsite/StartupResourcesInFolder.cs index d8027ab7..32f2dd92 100644 --- a/test/LocalizationWebsite/StartupResourcesInFolder.cs +++ b/test/LocalizationWebsite/StartupResourcesInFolder.cs @@ -31,6 +31,7 @@ public void Configure( var options = new RequestLocalizationOptions { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List() { new CultureInfo("fr-FR") @@ -41,7 +42,7 @@ public void Configure( } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); var stringLocalizer = stringLocalizerFactory.Create("Test", location: null); diff --git a/test/Microsoft.AspNet.Localization.Tests/AcceptLanguageHeaderRequestCultureProviderTest.cs b/test/Microsoft.AspNet.Localization.Tests/AcceptLanguageHeaderRequestCultureProviderTest.cs index 288bc6f8..d5d9ba20 100644 --- a/test/Microsoft.AspNet.Localization.Tests/AcceptLanguageHeaderRequestCultureProviderTest.cs +++ b/test/Microsoft.AspNet.Localization.Tests/AcceptLanguageHeaderRequestCultureProviderTest.cs @@ -21,13 +21,14 @@ public async void GetFallbackLanguage_ReturnsFirstNonNullCultureFromSupportedCul { var options = new RequestLocalizationOptions { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA"), new CultureInfo("en-US") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -52,13 +53,14 @@ public async void GetFallbackLanguage_ReturnsFromSupportedCulture_AcceptLanguage { var options = new RequestLocalizationOptions { + DefaultRequestCulture = new RequestCulture("fr-FR"), SupportedCultures = new List { new CultureInfo("ar-SA"), new CultureInfo("en-US") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("fr-FR")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -82,13 +84,14 @@ public async void GetFallbackLanguage_ReturnsDefault_AcceptLanguageListDoesnotCo { var options = new RequestLocalizationOptions { + DefaultRequestCulture = new RequestCulture("fr-FR"), SupportedCultures = new List { new CultureInfo("ar-SA"), new CultureInfo("af-ZA") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("fr-FR")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -113,6 +116,7 @@ public async void OmitDefaultRequestCultureShouldNotThrowNullReferenceException_ { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-YE") @@ -122,7 +126,7 @@ public async void OmitDefaultRequestCultureShouldNotThrowNullReferenceException_ new CultureInfo("ar-YE") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); diff --git a/test/Microsoft.AspNet.Localization.Tests/CookieRequestCultureProviderTest.cs b/test/Microsoft.AspNet.Localization.Tests/CookieRequestCultureProviderTest.cs index 13276395..6012cacf 100644 --- a/test/Microsoft.AspNet.Localization.Tests/CookieRequestCultureProviderTest.cs +++ b/test/Microsoft.AspNet.Localization.Tests/CookieRequestCultureProviderTest.cs @@ -22,6 +22,7 @@ public async void GetCultureInfoFromPersistentCookie() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -34,7 +35,7 @@ public async void GetCultureInfoFromPersistentCookie() var provider = new CookieRequestCultureProvider(); provider.CookieName = "Preferences"; options.RequestCultureProviders.Insert(0, provider); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -61,6 +62,7 @@ public async void GetDefaultCultureInfoIfCultureKeysAreMissingOrInvalid() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -73,7 +75,7 @@ public async void GetDefaultCultureInfoIfCultureKeysAreMissingOrInvalid() var provider = new CookieRequestCultureProvider(); provider.CookieName = "Preferences"; options.RequestCultureProviders.Insert(0, provider); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -96,6 +98,7 @@ public async void GetDefaultCultureInfoIfCookieDoesNotExist() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -108,7 +111,7 @@ public async void GetDefaultCultureInfoIfCookieDoesNotExist() var provider = new CookieRequestCultureProvider(); provider.CookieName = "Preferences"; options.RequestCultureProviders.Insert(0, provider); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); diff --git a/test/Microsoft.AspNet.Localization.Tests/CustomRequestCultureProviderTest.cs b/test/Microsoft.AspNet.Localization.Tests/CustomRequestCultureProviderTest.cs index f668f908..72e0a925 100644 --- a/test/Microsoft.AspNet.Localization.Tests/CustomRequestCultureProviderTest.cs +++ b/test/Microsoft.AspNet.Localization.Tests/CustomRequestCultureProviderTest.cs @@ -24,6 +24,7 @@ public async void CustomRequestCultureProviderThatGetsCultureInfoFromUrl() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar") @@ -39,7 +40,7 @@ public async void CustomRequestCultureProviderThatGetsCultureInfoFromUrl() var requestCulture = new ProviderCultureResult(culture); return Task.FromResult(requestCulture); })); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); diff --git a/test/Microsoft.AspNet.Localization.Tests/QueryStringRequestCultureProviderTest.cs b/test/Microsoft.AspNet.Localization.Tests/QueryStringRequestCultureProviderTest.cs index a71664e6..282e194e 100644 --- a/test/Microsoft.AspNet.Localization.Tests/QueryStringRequestCultureProviderTest.cs +++ b/test/Microsoft.AspNet.Localization.Tests/QueryStringRequestCultureProviderTest.cs @@ -21,6 +21,7 @@ public async void GetCultureInfoFromQueryString() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -31,7 +32,7 @@ public async void GetCultureInfoFromQueryString() } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -52,8 +53,11 @@ public async void GetDefaultCultureInfoIfCultureKeysAreMissing() { using (var server = TestServer.Create(app => { - var options = new RequestLocalizationOptions(); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + var options = new RequestLocalizationOptions + { + DefaultRequestCulture = new RequestCulture("en-US"), + }; + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -76,6 +80,7 @@ public async void GetDefaultCultureInfoIfCultureIsInSupportedCultureList() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -85,7 +90,7 @@ public async void GetDefaultCultureInfoIfCultureIsInSupportedCultureList() new CultureInfo("ar-SA") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -107,6 +112,7 @@ public async void GetDefaultCultureInfoIfUICultureIsNotInSupportedList() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -116,7 +122,7 @@ public async void GetDefaultCultureInfoIfUICultureIsNotInSupportedList() new CultureInfo("ar-SA") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -138,6 +144,7 @@ public async void GetSameCultureInfoIfCultureKeyIsMissing() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -147,7 +154,7 @@ public async void GetSameCultureInfoIfCultureKeyIsMissing() new CultureInfo("ar-SA") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -170,6 +177,7 @@ public async void GetSameCultureInfoIfUICultureKeyIsMissing() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -179,7 +187,7 @@ public async void GetSameCultureInfoIfUICultureKeyIsMissing() new CultureInfo("ar-SA") } }; - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -202,6 +210,7 @@ public async void GetCultureInfoFromQueryStringWithCustomKeys() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("ar-SA") @@ -215,7 +224,7 @@ public async void GetCultureInfoFromQueryStringWithCustomKeys() provider.QueryStringKey = "c"; provider.UIQueryStringKey = "uic"; options.RequestCultureProviders.Insert(0, provider); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); @@ -238,6 +247,7 @@ public async void GetTheRightCultureInfoRegardlessOfCultureNameCasing() { var options = new RequestLocalizationOptions() { + DefaultRequestCulture = new RequestCulture("en-US"), SupportedCultures = new List { new CultureInfo("FR") @@ -251,7 +261,7 @@ public async void GetTheRightCultureInfoRegardlessOfCultureNameCasing() provider.QueryStringKey = "c"; provider.UIQueryStringKey = "uic"; options.RequestCultureProviders.Insert(0, provider); - app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US")); + app.UseRequestLocalization(options); app.Run(context => { var requestCultureFeature = context.Features.Get(); diff --git a/test/Microsoft.AspNet.Localization.Tests/RequestLocalizationOptionsTest.cs b/test/Microsoft.AspNet.Localization.Tests/RequestLocalizationOptionsTest.cs new file mode 100644 index 00000000..85fb33a2 --- /dev/null +++ b/test/Microsoft.AspNet.Localization.Tests/RequestLocalizationOptionsTest.cs @@ -0,0 +1,107 @@ +// 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 System.Globalization; +using System.Threading; +using Xunit; + +namespace Microsoft.AspNet.Localization.Tests +{ + public class RequestLocalizationOptionsTest : IDisposable + { + private readonly CultureInfo _initialCulture; + private readonly CultureInfo _initialUICulture; + + public RequestLocalizationOptionsTest() + { + _initialCulture = CultureInfo.CurrentCulture; + _initialUICulture = CultureInfo.CurrentUICulture; + } + + [Fact] + public void DefaultRequestCulture_DefaultsToCurrentCulture() + { + // Arrange/Act + var options = new RequestLocalizationOptions(); + + // Assert + Assert.NotNull(options.DefaultRequestCulture); + Assert.Equal(CultureInfo.CurrentCulture, options.DefaultRequestCulture.Culture); + Assert.Equal(CultureInfo.CurrentUICulture, options.DefaultRequestCulture.UICulture); + } + + [Fact] + public void DefaultRequestCulture_DefaultsToCurrentCultureWhenExplicitlySet() + { + // Arrange + var explicitCulture = new CultureInfo("fr-FR"); +#if DNX451 + Thread.CurrentThread.CurrentCulture = explicitCulture; + Thread.CurrentThread.CurrentUICulture = explicitCulture; +#else + CultureInfo.CurrentCulture = explicitCulture; + CultureInfo.CurrentUICulture = explicitCulture; +#endif + // Act + var options = new RequestLocalizationOptions(); + + // Assert + Assert.Equal(explicitCulture, options.DefaultRequestCulture.Culture); + Assert.Equal(explicitCulture, options.DefaultRequestCulture.UICulture); + } + + [Fact] + public void DefaultRequestCulture_ThrowsWhenTryingToSetToNull() + { + // Arrange + var options = new RequestLocalizationOptions(); + + // Act/Assert + Assert.Throws(typeof(ArgumentNullException), () => options.DefaultRequestCulture = null); + } + + [Fact] + public void SupportedCultures_DefaultsToCurrentCulture() + { + // Arrange/Act + var options = new RequestLocalizationOptions(); + + // Assert + Assert.Collection(options.SupportedCultures, item => Assert.Equal(CultureInfo.CurrentCulture, item)); + Assert.Collection(options.SupportedUICultures, item => Assert.Equal(CultureInfo.CurrentUICulture, item)); + } + + [Fact] + public void SupportedCultures_DefaultsToCurrentCultureWhenExplicitlySet() + { + // Arrange + var explicitCulture = new CultureInfo("fr-FR"); +#if DNX451 + Thread.CurrentThread.CurrentCulture = explicitCulture; + Thread.CurrentThread.CurrentUICulture = explicitCulture; +#else + CultureInfo.CurrentCulture = explicitCulture; + CultureInfo.CurrentUICulture = explicitCulture; +#endif + + // Act + var options = new RequestLocalizationOptions(); + + // Assert + Assert.Collection(options.SupportedCultures, item => Assert.Equal(explicitCulture, item)); + Assert.Collection(options.SupportedUICultures, item => Assert.Equal(explicitCulture, item)); + } + + public void Dispose() + { +#if DNX451 + Thread.CurrentThread.CurrentCulture = _initialCulture; + Thread.CurrentThread.CurrentUICulture = _initialUICulture; +#else + CultureInfo.CurrentCulture = _initialCulture; + CultureInfo.CurrentUICulture = _initialUICulture; +#endif + } + } +}