diff --git a/src/Microsoft.AspNet.Mvc.Localization/Internal/MvcLocalizationServices.cs b/src/Microsoft.AspNet.Mvc.Localization/Internal/MvcLocalizationServices.cs index 595cb9bb7e..ec6b15687b 100644 --- a/src/Microsoft.AspNet.Mvc.Localization/Internal/MvcLocalizationServices.cs +++ b/src/Microsoft.AspNet.Mvc.Localization/Internal/MvcLocalizationServices.cs @@ -15,6 +15,17 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal IServiceCollection services, LanguageViewLocationExpanderFormat format, Action setupAction) + { + AddMvcLocalizationServices(services, format, setupAction); + + services.AddLocalization(setupAction); + } + + // To enable unit testing only 'MVC' specific services + public static void AddMvcLocalizationServices( + IServiceCollection services, + LanguageViewLocationExpanderFormat format, + Action setupAction) { services.Configure( options => @@ -25,8 +36,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal services.TryAdd(ServiceDescriptor.Singleton()); services.TryAdd(ServiceDescriptor.Transient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>))); services.TryAdd(ServiceDescriptor.Transient()); - - services.AddLocalization(setupAction); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.Localization.Test/Internal/MvcLocalizationServiceCollectionExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.Localization.Test/Internal/MvcLocalizationServiceCollectionExtensionsTest.cs index b685f2076d..d6a7c7c4e4 100644 --- a/test/Microsoft.AspNet.Mvc.Localization.Test/Internal/MvcLocalizationServiceCollectionExtensionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.Localization.Test/Internal/MvcLocalizationServiceCollectionExtensionsTest.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal var collection = new ServiceCollection(); // Act - MvcLocalizationServices.AddLocalizationServices( + MvcLocalizationServices.AddMvcLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, setupAction: null); @@ -53,23 +53,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal Assert.Equal(typeof(IViewLocalizer), service.ServiceType); Assert.Equal(typeof(ViewLocalizer), service.ImplementationType); Assert.Equal(ServiceLifetime.Transient, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IStringLocalizerFactory), service.ServiceType); - Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), service.ImplementationType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IStringLocalizer<>), service.ServiceType); - Assert.Equal(typeof(StringLocalizer<>), service.ImplementationType); - Assert.Equal(ServiceLifetime.Transient, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IOptions<>), service.ServiceType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); }); } @@ -86,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal collection.Add(ServiceDescriptor.Transient(typeof(IViewLocalizer), typeof(TestViewLocalizer))); collection.Add(ServiceDescriptor.Instance(typeof(HtmlEncoder), testEncoder)); - MvcLocalizationServices.AddLocalizationServices( + MvcLocalizationServices.AddMvcLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, setupAction: null); @@ -120,23 +103,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal { Assert.Equal(typeof(IConfigureOptions), service.ServiceType); Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IStringLocalizerFactory), service.ServiceType); - Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), service.ImplementationType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IStringLocalizer<>), service.ServiceType); - Assert.Equal(typeof(StringLocalizer<>), service.ImplementationType); - Assert.Equal(ServiceLifetime.Transient, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IOptions<>), service.ServiceType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); }); } @@ -152,7 +118,7 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal }); // Act - MvcLocalizationServices.AddLocalizationServices( + MvcLocalizationServices.AddMvcLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, setupAction: null); @@ -192,23 +158,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal Assert.Equal(ServiceLifetime.Transient, service.Lifetime); }, service => - { - Assert.Equal(typeof(IStringLocalizerFactory), service.ServiceType); - Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), service.ImplementationType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IStringLocalizer<>), service.ServiceType); - Assert.Equal(typeof(StringLocalizer<>), service.ImplementationType); - Assert.Equal(ServiceLifetime.Transient, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IOptions<>), service.ServiceType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); - }, - service => { Assert.Equal(typeof(IHtmlLocalizer<>), service.ServiceType); Assert.Equal(typeof(TestHtmlLocalizer<>), service.ImplementationType); @@ -235,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal var collection = new ServiceCollection(); // Act - MvcLocalizationServices.AddLocalizationServices( + MvcLocalizationServices.AddMvcLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, options => options.ResourcesPath = "Resources"); @@ -264,28 +213,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal Assert.Equal(typeof(IViewLocalizer), service.ServiceType); Assert.Equal(typeof(ViewLocalizer), service.ImplementationType); Assert.Equal(ServiceLifetime.Transient, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IStringLocalizerFactory), service.ServiceType); - Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), service.ImplementationType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IStringLocalizer<>), service.ServiceType); - Assert.Equal(typeof(StringLocalizer<>), service.ImplementationType); - Assert.Equal(ServiceLifetime.Transient, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IConfigureOptions), service.ServiceType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); - }, - service => - { - Assert.Equal(typeof(IOptions<>), service.ServiceType); - Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); }); } }