コード例 #1
0
        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);
        }
コード例 #2
0
        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 TestResourceManagerStringLocalizerFactory(
     IOptions <LocalizationOptions> localizationOptions,
     ResourceLocationAttribute resourceLocationAttribute,
     ILoggerFactory loggerFactory)
     : base(localizationOptions, loggerFactory)
 {
     _resourceLocationAttribute = resourceLocationAttribute;
 }