Esempio n. 1
0
        public void EnumeratorCacheIsScopedByAssembly()
        {
            // Arrange
            var resourceNamesCache     = new ResourceNamesCache();
            var baseName               = "test";
            var resourceAssembly1      = new TestAssemblyWrapper(typeof(ResourceManagerStringLocalizerTest));
            var resourceAssembly2      = new TestAssemblyWrapper(typeof(ResourceManagerStringLocalizer));
            var resourceManager1       = new TestResourceManager(baseName, resourceAssembly1);
            var resourceManager2       = new TestResourceManager(baseName, resourceAssembly2);
            var resourceStreamManager1 = new TestResourceStringProvider(resourceNamesCache, resourceManager1, resourceAssembly1.Assembly, baseName);
            var resourceStreamManager2 = new TestResourceStringProvider(resourceNamesCache, resourceManager2, resourceAssembly2.Assembly, 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.ManifestResourceStreamCallCount);
            Assert.Equal(expectedCallCount, resourceAssembly2.ManifestResourceStreamCallCount);
        }
Esempio n. 2
0
        public void GetString_LogsLocationSearched()
        {
            // Arrange
            var baseName              = "Resources.TestResource";
            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
            var value = localizer["a key!"];

            // Assert
            var write = Assert.Single(Sink.Writes);

            Assert.Equal("ResourceManagerStringLocalizer searched for 'a key!' in 'Resources.TestResource' with culture 'en-US'.", write.State.ToString());
        }
Esempio n. 3
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);
            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.
            var strings = localizer.GetAllStrings(includeParentCultures).ToList();

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

            Assert.Equal("TestName", value.Value);
        }
Esempio n. 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);
        }
Esempio n. 5
0
        public void GetString_PopulatesSearchedLocationOnLocalizedString()
        {
            // Arrange
            var baseName              = "Resources.TestResource";
            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
            var value = localizer["name"];

            // Assert
            Assert.Equal("Resources.TestResource", value.SearchedLocation);
        }