public void AddLocalizationWithLocalizationOptions_AddsNeededServices()
        {
            // Arrange
            var collection = new ServiceCollection();

            // Act
            LocalizationServiceCollectionExtensions.AddLocalizationServices(
                collection,
                options => options.ResourcesPath = "Resources");

            // Assert
            var services = collection.ToList();

            Assert.Equal(3, 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);
        }
コード例 #2
0
    public void AddLocalization_AddsNeededServices()
    {
        // Arrange
        var collection = new ServiceCollection();

        // Act
        LocalizationServiceCollectionExtensions.AddLocalizationServices(collection);

        // Assert
        AssertContainsSingle(collection, typeof(IStringLocalizerFactory), typeof(ResourceManagerStringLocalizerFactory));
        AssertContainsSingle(collection, typeof(IStringLocalizer <>), typeof(StringLocalizer <>));
    }