public void AddCustomLocalizers_BeforeMvcLocalization_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))); collection.Add(ServiceDescriptor.Instance(typeof(IHtmlEncoder), typeof(CommonTestEncoder))); MvcLocalizationServiceCollectionExtensions.AddMvcLocalization(collection); // Assert var services = collection.ToList(); Assert.Equal(7, services.Count); Assert.Equal(typeof(IHtmlLocalizerFactory), services[0].ServiceType); Assert.Equal(typeof(TestHtmlLocalizerFactory), services[0].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime); Assert.Equal(typeof(IHtmlLocalizer <>), services[1].ServiceType); Assert.Equal(typeof(TestHtmlLocalizer <>), services[1].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime); Assert.Equal(typeof(IViewLocalizer), services[2].ServiceType); Assert.Equal(typeof(TestViewLocalizer), services[2].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[2].Lifetime); Assert.Equal(typeof(IHtmlEncoder), services[3].ServiceType); Assert.Equal(typeof(CommonTestEncoder), services[3].ImplementationInstance); Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime); }
public void AddMvcLocalization_AddsNeededServices() { // Arrange var collection = new ServiceCollection(); // Act MvcLocalizationServiceCollectionExtensions.AddMvcLocalization(collection); // Assert var services = collection.ToList(); Assert.Equal(7, services.Count); Assert.Equal(typeof(IConfigureOptions <RazorViewEngineOptions>), services[0].ServiceType); Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime); Assert.Equal(typeof(IHtmlLocalizerFactory), services[1].ServiceType); Assert.Equal(typeof(HtmlLocalizerFactory), services[1].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[1].Lifetime); Assert.Equal(typeof(IHtmlLocalizer <>), services[2].ServiceType); Assert.Equal(typeof(HtmlLocalizer <>), services[2].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[2].Lifetime); Assert.Equal(typeof(IViewLocalizer), services[3].ServiceType); Assert.Equal(typeof(ViewLocalizer), services[3].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[3].Lifetime); Assert.Equal(typeof(IHtmlEncoder), services[4].ServiceType); Assert.Equal(ServiceLifetime.Singleton, services[4].Lifetime); Assert.Equal(typeof(IStringLocalizerFactory), services[5].ServiceType); Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[5].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[5].Lifetime); Assert.Equal(typeof(IStringLocalizer <>), services[6].ServiceType); Assert.Equal(typeof(StringLocalizer <>), services[6].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[6].Lifetime); }
public void AddCustomLocalizers_AfterMvcLocalization_AddsNeededServices() { // Arrange var collection = new ServiceCollection(); collection.Configure <RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new CustomPartialDirectoryViewLocationExpander()); }); // Act MvcLocalizationServiceCollectionExtensions.AddMvcLocalization(collection); collection.Add(ServiceDescriptor.Transient(typeof(IHtmlLocalizer <>), typeof(TestHtmlLocalizer <>))); collection.Add(ServiceDescriptor.Transient(typeof(IHtmlLocalizer), typeof(TestViewLocalizer))); collection.Add(ServiceDescriptor.Instance(typeof(IHtmlEncoder), typeof(CommonTestEncoder))); // Assert var services = collection.ToList(); Assert.Equal(11, services.Count); Assert.Equal(typeof(IConfigureOptions <RazorViewEngineOptions>), services[0].ServiceType); Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime); Assert.Equal(0, ((IConfigureOptions <RazorViewEngineOptions>)services[0].ImplementationInstance).Order); Assert.Equal(typeof(IConfigureOptions <RazorViewEngineOptions>), services[1].ServiceType); Assert.Equal(ServiceLifetime.Singleton, services[1].Lifetime); Assert.Equal(-1000, ((IConfigureOptions <RazorViewEngineOptions>)services[1].ImplementationInstance).Order); Assert.Equal(typeof(IHtmlLocalizerFactory), services[2].ServiceType); Assert.Equal(typeof(HtmlLocalizerFactory), services[2].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime); Assert.Equal(typeof(IHtmlLocalizer <>), services[3].ServiceType); Assert.Equal(typeof(HtmlLocalizer <>), services[3].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[3].Lifetime); Assert.Equal(typeof(IViewLocalizer), services[4].ServiceType); Assert.Equal(typeof(ViewLocalizer), services[4].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[4].Lifetime); Assert.Equal(typeof(IHtmlEncoder), services[5].ServiceType); Assert.Equal(ServiceLifetime.Singleton, services[5].Lifetime); Assert.Equal(typeof(IStringLocalizerFactory), services[6].ServiceType); Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[6].ImplementationType); Assert.Equal(ServiceLifetime.Singleton, services[6].Lifetime); Assert.Equal(typeof(IStringLocalizer <>), services[7].ServiceType); Assert.Equal(typeof(StringLocalizer <>), services[7].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[7].Lifetime); Assert.Equal(typeof(IHtmlLocalizer <>), services[8].ServiceType); Assert.Equal(typeof(TestHtmlLocalizer <>), services[8].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[8].Lifetime); Assert.Equal(typeof(IHtmlLocalizer), services[9].ServiceType); Assert.Equal(typeof(TestViewLocalizer), services[9].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[9].Lifetime); Assert.Equal(typeof(IHtmlEncoder), services[10].ServiceType); Assert.Equal(typeof(CommonTestEncoder), services[10].ImplementationInstance); Assert.Equal(ServiceLifetime.Singleton, services[10].Lifetime); }