public void AddCustomLocalizers_BeforeAddLocalizationServices_AddsNeededServices() { // Arrange var collection = new ServiceCollection(); var testEncoder = new HtmlTestEncoder(); // Act collection.Add(ServiceDescriptor.Singleton(typeof(IHtmlLocalizerFactory), typeof(TestHtmlLocalizerFactory))); collection.Add(ServiceDescriptor.Transient(typeof(IHtmlLocalizer <>), typeof(TestHtmlLocalizer <>))); collection.Add(ServiceDescriptor.Transient(typeof(IViewLocalizer), typeof(TestViewLocalizer))); collection.Add(ServiceDescriptor.Singleton(typeof(HtmlEncoder), testEncoder)); MvcLocalizationServices.AddMvcViewLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, setupAction: null); // Assert Assert.Collection(collection, service => { Assert.Equal(typeof(IHtmlLocalizerFactory), service.ServiceType); Assert.Equal(typeof(TestHtmlLocalizerFactory), service.ImplementationType); Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); }, service => { Assert.Equal(typeof(IHtmlLocalizer <>), service.ServiceType); Assert.Equal(typeof(TestHtmlLocalizer <>), service.ImplementationType); Assert.Equal(ServiceLifetime.Transient, service.Lifetime); }, service => { Assert.Equal(typeof(IViewLocalizer), service.ServiceType); Assert.Equal(typeof(TestViewLocalizer), service.ImplementationType); Assert.Equal(ServiceLifetime.Transient, service.Lifetime); }, service => { Assert.Equal(typeof(HtmlEncoder), service.ServiceType); Assert.Same(testEncoder, service.ImplementationInstance); }, service => { Assert.Equal(typeof(IConfigureOptions <RazorViewEngineOptions>), service.ServiceType); Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); }); }
public void AddLocalizationServices_AddsNeededServices() { // Arrange var collection = new ServiceCollection(); // Act MvcLocalizationServices.AddMvcViewLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, setupAction: null); // Assert AssertContainsSingle(collection, typeof(IHtmlLocalizerFactory), typeof(HtmlLocalizerFactory)); AssertContainsSingle(collection, typeof(IHtmlLocalizer <>), typeof(HtmlLocalizer <>)); AssertContainsSingle(collection, typeof(IViewLocalizer), typeof(ViewLocalizer)); }
public void AddCustomLocalizers_BeforeAddLocalizationServices_AddsNeededServices() { // Arrange var collection = new ServiceCollection(); // Act collection.Add(ServiceDescriptor.Singleton(typeof(IHtmlLocalizerFactory), typeof(TestHtmlLocalizerFactory))); collection.Add(ServiceDescriptor.Transient(typeof(IHtmlLocalizer <>), typeof(TestHtmlLocalizer <>))); collection.Add(ServiceDescriptor.Transient(typeof(IViewLocalizer), typeof(TestViewLocalizer))); MvcLocalizationServices.AddMvcViewLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, setupAction: null); AssertContainsSingle(collection, typeof(IHtmlLocalizerFactory), typeof(TestHtmlLocalizerFactory)); AssertContainsSingle(collection, typeof(IHtmlLocalizer <>), typeof(TestHtmlLocalizer <>)); AssertContainsSingle(collection, typeof(IViewLocalizer), typeof(TestViewLocalizer)); }
public void AddLocalizationServices_AddsNeededServices() { // Arrange var collection = new ServiceCollection(); // Act MvcLocalizationServices.AddMvcViewLocalizationServices( collection, LanguageViewLocationExpanderFormat.Suffix, setupAction: null); // Assert Assert.Collection(collection, service => { Assert.Equal(typeof(IConfigureOptions <RazorViewEngineOptions>), service.ServiceType); Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); }, service => { Assert.Equal(typeof(IHtmlLocalizerFactory), service.ServiceType); Assert.Equal(typeof(HtmlLocalizerFactory), service.ImplementationType); Assert.Equal(ServiceLifetime.Singleton, service.Lifetime); }, service => { Assert.Equal(typeof(IHtmlLocalizer <>), service.ServiceType); Assert.Equal(typeof(HtmlLocalizer <>), service.ImplementationType); Assert.Equal(ServiceLifetime.Transient, service.Lifetime); }, service => { Assert.Equal(typeof(IViewLocalizer), service.ServiceType); Assert.Equal(typeof(ViewLocalizer), service.ImplementationType); Assert.Equal(ServiceLifetime.Transient, service.Lifetime); }); }