public void ResourceManagerStringLocalizer_GetAllStrings_MissingResourceThrows(bool includeParentCultures)
    {
        // Arrange
        var resourceNamesCache = new ResourceNamesCache();
        var baseName           = "testington";
        var resourceAssembly   = new TestAssemblyWrapper();

        resourceAssembly.HasResources = false;
        var resourceManager = new TestResourceManager(baseName, resourceAssembly);
        var logger          = Logger;

        var localizer = new ResourceManagerStringLocalizer(
            resourceManager,
            resourceAssembly.Assembly,
            baseName,
            resourceNamesCache,
            logger);

        // Act & Assert
        var exception = Assert.Throws <MissingManifestResourceException>(() =>
        {
            // We have to access the result so it evaluates.
#pragma warning disable CA1304 // Specify CultureInfo
            localizer.GetAllStrings(includeParentCultures).ToArray();
#pragma warning restore CA1304 // Specify CultureInfo
        });

        var expectedTries = includeParentCultures ? 3 : 1;
        var expected      = includeParentCultures
            ? "No manifests exist for the current culture."
            : $"The manifest 'testington.{CultureInfo.CurrentCulture}.resources' was not found.";

        Assert.Equal(expected, exception.Message);
        Assert.Equal(expectedTries, resourceAssembly.ManifestResourceStreamCallCount);
    }
    public void ResourceManagerStringLocalizer_GetAllStrings_ReturnsExpectedValue(bool includeParentCultures)
    {
        // Arrange
        var baseName              = "test";
        var resourceNamesCache    = new ResourceNamesCache();
        var resourceAssembly      = new TestAssemblyWrapper();
        var resourceManager       = new TestResourceManager(baseName, resourceAssembly);
        var resourceStreamManager = new TestResourceStringProvider(resourceNamesCache, resourceManager, resourceAssembly.Assembly, baseName);
        var logger    = Logger;
        var localizer = new ResourceManagerStringLocalizer(
            resourceManager,
            resourceStreamManager,
            baseName,
            resourceNamesCache,
            logger);

        // Act
        // We have to access the result so it evaluates.
#pragma warning disable CA1304 // Specify CultureInfo
        var strings = localizer.GetAllStrings(includeParentCultures).ToList();
#pragma warning restore CA1304 // Specify CultureInfo

        // Assert
        var value = Assert.Single(strings);
        Assert.Equal("TestName", value.Value);
    }
Example #3
0
        public void EnumeratorCacheIsScopedByAssembly()
        {
            // Arrange
            var resourceNamesCache     = new ResourceNamesCache();
            var baseName               = "test";
            var resourceAssembly1      = new TestAssemblyWrapper("Assembly1");
            var resourceAssembly2      = new TestAssemblyWrapper("Assembly2");
            var resourceManager1       = new TestResourceManager(baseName, resourceAssembly1.Assembly);
            var resourceManager2       = new TestResourceManager(baseName, resourceAssembly2.Assembly);
            var resourceStreamManager1 = new TestResourceStringProvider(resourceNamesCache, resourceAssembly1, baseName);
            var resourceStreamManager2 = new TestResourceStringProvider(resourceNamesCache, resourceAssembly2, baseName);
            var logger     = Logger;
            var localizer1 = new ResourceManagerStringLocalizer(
                resourceManager1,
                resourceStreamManager1,
                baseName,
                resourceNamesCache,
                logger);
            var localizer2 = new ResourceManagerStringLocalizer(
                resourceManager2,
                resourceStreamManager2,
                baseName,
                resourceNamesCache,
                logger);

            // Act
            localizer1.GetAllStrings().ToList();
            localizer2.GetAllStrings().ToList();

            // Assert
            var expectedCallCount = GetCultureInfoDepth(CultureInfo.CurrentUICulture);

            Assert.Equal(expectedCallCount, resourceAssembly1.GetManifestResourceStreamCallCount);
            Assert.Equal(expectedCallCount, resourceAssembly2.GetManifestResourceStreamCallCount);
        }
Example #4
0
        public void EnumeratorCachesCultureWalkForSameAssembly()
        {
            // Arrange
            var resourceNamesCache    = new ResourceNamesCache();
            var baseName              = "test";
            var resourceAssembly      = new TestAssemblyWrapper();
            var resourceManager       = new TestResourceManager(baseName, resourceAssembly.Assembly);
            var resourceStreamManager = new TestResourceStringProvider(resourceNamesCache, resourceAssembly, baseName);
            var logger     = Logger;
            var localizer1 = new ResourceManagerStringLocalizer(resourceManager,
                                                                resourceStreamManager,
                                                                baseName,
                                                                resourceNamesCache,
                                                                logger);
            var localizer2 = new ResourceManagerStringLocalizer(resourceManager,
                                                                resourceStreamManager,
                                                                baseName,
                                                                resourceNamesCache,
                                                                logger);

            // Act
            for (int i = 0; i < 5; i++)
            {
                localizer1.GetAllStrings().ToList();
                localizer2.GetAllStrings().ToList();
            }

            // Assert
            var expectedCallCount = GetCultureInfoDepth(CultureInfo.CurrentUICulture);

            Assert.Equal(expectedCallCount, resourceAssembly.GetManifestResourceStreamCallCount);
        }
        public void ResourceManagerStringLocalizer_GetAllStrings_ReturnsExpectedValue(bool includeParentCultures)
        {
            // Arrange
            var baseName = "test";
            var resourceNamesCache = new ResourceNamesCache();
            var resourceAssembly = new TestAssemblyWrapper();
            var resourceManager = new TestResourceManager(baseName, resourceAssembly.Assembly);
            var localizer = new ResourceManagerStringLocalizer(resourceManager, resourceAssembly, baseName, resourceNamesCache);

            // Act
            // We have to access the result so it evaluates.
            var strings = localizer.GetAllStrings(includeParentCultures).ToList();

            // Assert
            var value = Assert.Single(strings);
            Assert.Equal("TestName", value.Value);
        }
Example #6
0
        public void ResourceManagerStringLocalizer_GetAllStrings_ReturnsExpectedValue(bool includeParentCultures)
        {
            // Arrange
            var baseName           = "test";
            var resourceNamesCache = new ResourceNamesCache();
            var resourceAssembly   = new TestAssemblyWrapper();
            var resourceManager    = new TestResourceManager(baseName, resourceAssembly.Assembly);
            var localizer          = new ResourceManagerStringLocalizer(resourceManager, resourceAssembly, baseName, resourceNamesCache);

            // Act
            // We have to access the result so it evaluates.
            var strings = localizer.GetAllStrings(includeParentCultures).ToList();

            // Assert
            var value = Assert.Single(strings);

            Assert.Equal("TestName", value.Value);
        }
        public void EnumeratorCacheIsScopedByAssembly()
        {
            // Arrange
            var resourceNamesCache = new ResourceNamesCache();
            var baseName = "test";
            var resourceAssembly1 = new TestAssemblyWrapper("Assembly1");
            var resourceAssembly2 = new TestAssemblyWrapper("Assembly2");
            var resourceManager1 = new TestResourceManager(baseName, resourceAssembly1.Assembly);
            var resourceManager2 = new TestResourceManager(baseName, resourceAssembly2.Assembly);
            var localizer1 = new ResourceManagerStringLocalizer(resourceManager1, resourceAssembly1, baseName, resourceNamesCache);
            var localizer2 = new ResourceManagerStringLocalizer(resourceManager2, resourceAssembly2, baseName, resourceNamesCache);

            // Act
            localizer1.GetAllStrings().ToList();
            localizer2.GetAllStrings().ToList();

            // Assert
            var expectedCallCount = GetCultureInfoDepth(CultureInfo.CurrentUICulture);
            Assert.Equal(expectedCallCount, resourceAssembly1.GetManifestResourceStreamCallCount);
            Assert.Equal(expectedCallCount, resourceAssembly2.GetManifestResourceStreamCallCount);
        }
        public void EnumeratorCachesCultureWalkForSameAssembly()
        {
            // Arrange
            var resourceNamesCache = new ResourceNamesCache();
            var baseName = "test";
            var resourceAssembly = new TestAssemblyWrapper();
            var resourceManager = new TestResourceManager(baseName, resourceAssembly.Assembly);
            var localizer1 = new ResourceManagerStringLocalizer(resourceManager, resourceAssembly, baseName, resourceNamesCache);
            var localizer2 = new ResourceManagerStringLocalizer(resourceManager, resourceAssembly, baseName, resourceNamesCache);

            // Act
            for (int i = 0; i < 5; i++)
            {
                localizer1.GetAllStrings().ToList();
                localizer2.GetAllStrings().ToList();
            }

            // Assert
            var expectedCallCount = GetCultureInfoDepth(CultureInfo.CurrentUICulture);
            Assert.Equal(expectedCallCount, resourceAssembly.GetManifestResourceStreamCallCount);
        }
 /// <summary>
 /// Gets all string resources.
 /// </summary>
 /// <param name="includeParentCultures">True for indicating whether to include strings
 /// from parent cultures; else, false.</param>
 /// <returns>The found strings.</returns>
 public IEnumerable <LocalizedString> GetAllStrings(bool includeParentCultures)
 => _resourcesManager.GetAllStrings(includeParentCultures);