Fix localization tests
This commit is contained in:
parent
57b88baad0
commit
f2bb90fa55
|
|
@ -15,6 +15,17 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
IServiceCollection services,
|
IServiceCollection services,
|
||||||
LanguageViewLocationExpanderFormat format,
|
LanguageViewLocationExpanderFormat format,
|
||||||
Action<LocalizationOptions> setupAction)
|
Action<LocalizationOptions> 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<LocalizationOptions> setupAction)
|
||||||
{
|
{
|
||||||
services.Configure<RazorViewEngineOptions>(
|
services.Configure<RazorViewEngineOptions>(
|
||||||
options =>
|
options =>
|
||||||
|
|
@ -25,8 +36,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
services.TryAdd(ServiceDescriptor.Singleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>());
|
services.TryAdd(ServiceDescriptor.Singleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>());
|
||||||
services.TryAdd(ServiceDescriptor.Transient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>)));
|
services.TryAdd(ServiceDescriptor.Transient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>)));
|
||||||
services.TryAdd(ServiceDescriptor.Transient<IViewLocalizer, ViewLocalizer>());
|
services.TryAdd(ServiceDescriptor.Transient<IViewLocalizer, ViewLocalizer>());
|
||||||
|
|
||||||
services.AddLocalization(setupAction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
var collection = new ServiceCollection();
|
var collection = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
MvcLocalizationServices.AddLocalizationServices(
|
MvcLocalizationServices.AddMvcLocalizationServices(
|
||||||
collection,
|
collection,
|
||||||
LanguageViewLocationExpanderFormat.Suffix,
|
LanguageViewLocationExpanderFormat.Suffix,
|
||||||
setupAction: null);
|
setupAction: null);
|
||||||
|
|
@ -53,23 +53,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
Assert.Equal(typeof(IViewLocalizer), service.ServiceType);
|
Assert.Equal(typeof(IViewLocalizer), service.ServiceType);
|
||||||
Assert.Equal(typeof(ViewLocalizer), service.ImplementationType);
|
Assert.Equal(typeof(ViewLocalizer), service.ImplementationType);
|
||||||
Assert.Equal(ServiceLifetime.Transient, service.Lifetime);
|
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.Transient(typeof(IViewLocalizer), typeof(TestViewLocalizer)));
|
||||||
collection.Add(ServiceDescriptor.Instance(typeof(HtmlEncoder), testEncoder));
|
collection.Add(ServiceDescriptor.Instance(typeof(HtmlEncoder), testEncoder));
|
||||||
|
|
||||||
MvcLocalizationServices.AddLocalizationServices(
|
MvcLocalizationServices.AddMvcLocalizationServices(
|
||||||
collection,
|
collection,
|
||||||
LanguageViewLocationExpanderFormat.Suffix,
|
LanguageViewLocationExpanderFormat.Suffix,
|
||||||
setupAction: null);
|
setupAction: null);
|
||||||
|
|
@ -120,23 +103,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
{
|
{
|
||||||
Assert.Equal(typeof(IConfigureOptions<RazorViewEngineOptions>), service.ServiceType);
|
Assert.Equal(typeof(IConfigureOptions<RazorViewEngineOptions>), service.ServiceType);
|
||||||
Assert.Equal(ServiceLifetime.Singleton, service.Lifetime);
|
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
|
// Act
|
||||||
MvcLocalizationServices.AddLocalizationServices(
|
MvcLocalizationServices.AddMvcLocalizationServices(
|
||||||
collection,
|
collection,
|
||||||
LanguageViewLocationExpanderFormat.Suffix,
|
LanguageViewLocationExpanderFormat.Suffix,
|
||||||
setupAction: null);
|
setupAction: null);
|
||||||
|
|
@ -192,23 +158,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
Assert.Equal(ServiceLifetime.Transient, service.Lifetime);
|
Assert.Equal(ServiceLifetime.Transient, service.Lifetime);
|
||||||
},
|
},
|
||||||
service =>
|
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(IHtmlLocalizer<>), service.ServiceType);
|
||||||
Assert.Equal(typeof(TestHtmlLocalizer<>), service.ImplementationType);
|
Assert.Equal(typeof(TestHtmlLocalizer<>), service.ImplementationType);
|
||||||
|
|
@ -235,7 +184,7 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
var collection = new ServiceCollection();
|
var collection = new ServiceCollection();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
MvcLocalizationServices.AddLocalizationServices(
|
MvcLocalizationServices.AddMvcLocalizationServices(
|
||||||
collection,
|
collection,
|
||||||
LanguageViewLocationExpanderFormat.Suffix,
|
LanguageViewLocationExpanderFormat.Suffix,
|
||||||
options => options.ResourcesPath = "Resources");
|
options => options.ResourcesPath = "Resources");
|
||||||
|
|
@ -264,28 +213,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||||
Assert.Equal(typeof(IViewLocalizer), service.ServiceType);
|
Assert.Equal(typeof(IViewLocalizer), service.ServiceType);
|
||||||
Assert.Equal(typeof(ViewLocalizer), service.ImplementationType);
|
Assert.Equal(typeof(ViewLocalizer), service.ImplementationType);
|
||||||
Assert.Equal(ServiceLifetime.Transient, service.Lifetime);
|
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<LocalizationOptions>), service.ServiceType);
|
|
||||||
Assert.Equal(ServiceLifetime.Singleton, service.Lifetime);
|
|
||||||
},
|
|
||||||
service =>
|
|
||||||
{
|
|
||||||
Assert.Equal(typeof(IOptions<>), service.ServiceType);
|
|
||||||
Assert.Equal(ServiceLifetime.Singleton, service.Lifetime);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue