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); }
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. localizer.GetAllStrings(includeParentCultures).ToArray(); }); 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. var strings = localizer.GetAllStrings(includeParentCultures).ToList(); // Assert var value = Assert.Single(strings); Assert.Equal("TestName", value.Value); }
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()); }
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); }
public void EnumeratorCachesCultureWalkForSameAssembly() { // Arrange var resourceNamesCache = new ResourceNamesCache(); var baseName = "test"; var resourceAssembly = new TestAssemblyWrapper(); var resourceManager = new TestResourceManager(baseName, resourceAssembly); var resourceStreamManager = new TestResourceStringProvider( resourceNamesCache, resourceManager, resourceAssembly.Assembly, baseName); var logger = Logger; var localizer1 = new ResourceManagerStringLocalizer(resourceManager, resourceStreamManager, baseName, resourceNamesCache, logger); var localizer2 = new ResourceManagerStringLocalizer(resourceManager, resourceStreamManager, baseName, resourceNamesCache, logger); // Act for (var i = 0; i < 5; i++) { localizer1.GetAllStrings().ToList(); localizer2.GetAllStrings().ToList(); } // Assert var expectedCallCount = GetCultureInfoDepth(CultureInfo.CurrentUICulture); Assert.Equal(expectedCallCount, resourceAssembly.ManifestResourceStreamCallCount); }