73 lines
2.9 KiB
C#
73 lines
2.9 KiB
C#
// 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.Linq;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.Extensions.Localization.Test
|
|
{
|
|
public class LocalizationServiceCollectionExtensionsTest
|
|
{
|
|
[Fact]
|
|
public void AddLocalization_AddsNeededServices()
|
|
{
|
|
// Arrange
|
|
var collection = new ServiceCollection();
|
|
|
|
// Act
|
|
collection.AddLocalization();
|
|
|
|
// Assert
|
|
var services = collection.ToList();
|
|
Assert.Equal(4, services.Count);
|
|
|
|
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
|
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType);
|
|
Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime);
|
|
|
|
Assert.Equal(typeof(IStringLocalizer<>), services[1].ServiceType);
|
|
Assert.Equal(typeof(StringLocalizer<>), services[1].ImplementationType);
|
|
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
|
|
|
|
Assert.Equal(typeof(IOptions<>), services[2].ServiceType);
|
|
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
|
|
|
|
Assert.Equal(typeof(IOptionsMonitor<>), services[3].ServiceType);
|
|
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddLocalizationWithLocalizationOptions_AddsNeededServices()
|
|
{
|
|
// Arrange
|
|
var collection = new ServiceCollection();
|
|
|
|
// Act
|
|
collection.AddLocalization(options => options.ResourcesPath = "Resources");
|
|
|
|
// Assert
|
|
var services = collection.ToList();
|
|
Assert.Equal(5, services.Count);
|
|
|
|
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
|
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType);
|
|
Assert.Equal(ServiceLifetime.Singleton, services[0].Lifetime);
|
|
|
|
Assert.Equal(typeof(IStringLocalizer<>), services[1].ServiceType);
|
|
Assert.Equal(typeof(StringLocalizer<>), services[1].ImplementationType);
|
|
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
|
|
|
|
Assert.Equal(typeof(IConfigureOptions<LocalizationOptions>), services[2].ServiceType);
|
|
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
|
|
|
|
Assert.Equal(typeof(IOptions<>), services[3].ServiceType);
|
|
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
|
|
|
|
Assert.Equal(typeof(IOptionsMonitor<>), services[4].ServiceType);
|
|
Assert.Equal(ServiceLifetime.Singleton, services[4].Lifetime);
|
|
}
|
|
}
|
|
}
|