public void Create_OverloadsProduceSameResult() { // Arrange var locOptions = new LocalizationOptions(); var options = new Mock <IOptions <LocalizationOptions> >(); options.Setup(o => o.Value).Returns(locOptions); var resourceLocationAttribute = new ResourceLocationAttribute(Path.Combine("My", "Resources")); var loggerFactory = NullLoggerFactory.Instance; var typeFactory = new TestResourceManagerStringLocalizerFactory( options.Object, resourceLocationAttribute, rootNamespaceAttribute: null, loggerFactory: loggerFactory); var stringFactory = new TestResourceManagerStringLocalizerFactory( options.Object, resourceLocationAttribute, rootNamespaceAttribute: null, loggerFactory: loggerFactory); var type = typeof(ResourceManagerStringLocalizerFactoryTest); var assemblyName = new AssemblyName(type.Assembly.FullName); // Act typeFactory.Create(type); stringFactory.Create(type.Name, assemblyName.Name); // Assert Assert.Equal(typeFactory.BaseName, stringFactory.BaseName); Assert.Equal(typeFactory.Assembly !.FullName, stringFactory.Assembly !.FullName); }
public void Create_ResourceLocationAttribute_RootNamespaceIgnoredWhenNoLocation() { // Arrange var locOptions = new LocalizationOptions(); var options = new Mock <IOptions <LocalizationOptions> >(); options.Setup(o => o.Value).Returns(locOptions); var loggerFactory = NullLoggerFactory.Instance; var resourcePath = Path.Combine("My", "Resources"); var rootNamespace = "MyNamespace"; var rootNamespaceAttribute = new RootNamespaceAttribute(rootNamespace); var typeFactory = new TestResourceManagerStringLocalizerFactory( options.Object, resourceLocationAttribute: null, rootNamespaceAttribute: rootNamespaceAttribute, loggerFactory: loggerFactory); var type = typeof(ResourceManagerStringLocalizerFactoryTest); // Act typeFactory.Create(type); // Assert Assert.Equal($"Microsoft.Extensions.Localization.Tests.ResourceManagerStringLocalizerFactoryTest", typeFactory.BaseName); }
public void Create_ResourceLocationAttribute_UsesRootNamespace() { // Arrange var locOptions = new LocalizationOptions(); var options = new Mock <IOptions <LocalizationOptions> >(); options.Setup(o => o.Value).Returns(locOptions); var loggerFactory = NullLoggerFactory.Instance; var resourcePath = Path.Combine("My", "Resources"); var rootNamespace = nameof(MyNamespace); var resourceLocationAttribute = new ResourceLocationAttribute(resourcePath); var rootNamespaceAttribute = new RootNamespaceAttribute(rootNamespace); var typeFactory = new TestResourceManagerStringLocalizerFactory( options.Object, resourceLocationAttribute, rootNamespaceAttribute, loggerFactory); var type = typeof(Model); // Act typeFactory.Create(type); // Assert Assert.Equal($"{rootNamespace}.My.Resources.{nameof(Model)}", typeFactory.BaseName); }
public void Create_FromNameLocation_ResourcesPathDirectorySeparatorToDot() { // Arrange var locOptions = new LocalizationOptions(); locOptions.ResourcesPath = Path.Combine("My", "Resources"); var options = new Mock <IOptions <LocalizationOptions> >(); options.Setup(o => o.Value).Returns(locOptions); var loggerFactory = NullLoggerFactory.Instance; var factory = new TestResourceManagerStringLocalizerFactory( options.Object, resourceLocationAttribute: null, loggerFactory: loggerFactory); // Act var result1 = factory.Create("baseName", location: "Microsoft.Extensions.Localization.Tests"); // Assert Assert.Equal("Microsoft.Extensions.Localization.Tests.My.Resources.baseName", factory.BaseName); }