예제 #1
0
        public void MultipleAttributesForSingleProperty_NoPrefix()
        {
            var model = _sut.GetTypesWithAttribute <LocalizedResourceAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ResourcesWithNamedKeys)}");

            var properties = model.SelectMany(t => _sut.ScanResources(t)).ToList();

            var namedResource = properties.FirstOrDefault(p => p.Key == "/this/is/xpath/to/resource");

            Assert.NotNull(namedResource);
            Assert.Equal("This is header", namedResource.Translations.DefaultTranslation());
        }
예제 #2
0
        public LocalizedResourceDiscoveryTests()
        {
            var state         = new ScanState();
            var keyBuilder    = new ResourceKeyBuilder(state);
            var oldKeyBuilder = new OldResourceKeyBuilder(keyBuilder);
            var ctx           = new ConfigurationContext();

            ctx.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <DetermineDefaultCulture.Handler>();

            var queryExecutor      = new QueryExecutor(ctx);
            var translationBuilder = new DiscoveredTranslationBuilder(queryExecutor);

            _sut = new TypeDiscoveryHelper(new List <IResourceTypeScanner>
            {
                new LocalizedModelTypeScanner(keyBuilder, oldKeyBuilder, state, ctx, translationBuilder),
                new LocalizedResourceTypeScanner(keyBuilder, oldKeyBuilder, state, ctx, translationBuilder),
                new LocalizedEnumTypeScanner(keyBuilder, translationBuilder),
                new LocalizedForeignResourceTypeScanner(keyBuilder, oldKeyBuilder, state, ctx, translationBuilder)
            }, ctx);

            _expressionHelper = new ExpressionHelper(keyBuilder);

            _types = _sut.GetTypesWithAttribute <LocalizedResourceAttribute>().ToList();
            Assert.NotEmpty(_types);
        }
예제 #3
0
        public void MultipleAttributesForSingleProperty_NoPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedProperties)}");

            var properties = model.SelectMany(t => _sut.ScanResources(t)).ToList();

            var nonexistingProperty = properties.FirstOrDefault(p => p.Key == "DbLocalizationProvider.Tests.NamedResources.ModelWithNamedProperties.PageHeader");

            Assert.Null(nonexistingProperty);

            var namedProperty = properties.FirstOrDefault(p => p.Key == "/this/is/xpath/key");

            Assert.NotNull(namedProperty);
            Assert.Equal("This is page header", namedProperty.Translations.DefaultTranslation());

            var anotherNamedProperty = properties.FirstOrDefault(p => p.Key == "/this/is/another/xpath/key");

            Assert.NotNull(anotherNamedProperty);

            var resourceKeyOnComplexProperty = properties.FirstOrDefault(p => p.Key == "/this/is/complex/type");

            Assert.NotNull(resourceKeyOnComplexProperty);

            var propertyWithDisplayName = properties.FirstOrDefault(p => p.Key == "/simple/property/with/display/name");

            Assert.NotNull(propertyWithDisplayName);
            Assert.Equal("This is simple property", propertyWithDisplayName.Translations.DefaultTranslation());
        }
예제 #4
0
        public void MultipleAttributeForSingleProperty_WithClassPrefix()
        {
            var model = _sut.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedPropertiesWithPrefix)}");

            var properties = model.SelectMany(t => _sut.ScanResources(t)).ToList();

            var firstResource = properties.FirstOrDefault(p => p.Key == "/contenttypes/modelwithnamedpropertieswithprefix/resource1");

            Assert.NotNull(firstResource);
            Assert.Equal("1st resource", firstResource.Translations.DefaultTranslation());

            var secondResource = properties.FirstOrDefault(p => p.Key == "/contenttypes/modelwithnamedpropertieswithprefix/resource2");

            Assert.NotNull(secondResource);
            Assert.Equal("2nd resource", secondResource.Translations.DefaultTranslation());
        }
        public LocalizedResourceDiscoveryTests()
        {
            _sut = new TypeDiscoveryHelper();
            ConfigurationContext.Current.TypeFactory.ForQuery <DetermineDefaultCulture.Query>().SetHandler <DetermineDefaultCulture.Handler>();

            _types = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedResourceAttribute>().ToList();
            Assert.NotEmpty(_types);
        }
예제 #6
0
        public LocalizedModelsDiscoveryTests()
        {
            var types = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>().ToList();

            Assert.NotEmpty(types);

            _properties = types.SelectMany(t => TypeDiscoveryHelper.GetAllProperties(t, contextAwareScanning: false));
        }
예제 #7
0
        public void SingleAttributeForSingleProperty_WithClassPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedPropertiesWithPrefix)}");

            var properties = model.SelectMany(t => _sut.ScanResources(t)).ToList();

            var name           = "/contenttypes/modelwithnamedpropertieswithprefix/properties/pageheader/name";
            var headerProperty = properties.FirstOrDefault(p => p.Key == name);

            Assert.NotNull(headerProperty);
            Assert.Equal("This is page header", headerProperty.Translations.DefaultTranslation());
        }
        public void MultipleAttributesForSingleProperty_WithValidationAttribute()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedResourceAttribute>()
                        .Where(t => t.FullName
                               == $"DbLocalizationProvider.Tests.DataAnnotations.{nameof(ResourcesWithNamedKeysAndValidationAttributeWithPrefix)}");

            var properties = model.SelectMany(t => _sut.ScanResources(t)).ToList();

            Assert.Equal(5, properties.Count);
            Assert.NotNull(properties.Single(_ => _.Key == "/root/name"));
            Assert.NotNull(properties.Single(_ => _.Key == "/root/and/this/is/header"));
            Assert.NotNull(properties.Single(_ => _.Key == "/root/and/this/is/another/header"));
            Assert.NotNull(properties.Single(_ => _.Key == "/root/this/is/email"));
            Assert.NotNull(properties.Single(_ => _.Key == "this/is/email-EmailAddress"));
        }
예제 #9
0
        public void ResourceAttributeToClass_WithClassPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedPropertiesWithPrefixAndKeyOnClass)}");

            var properties = model.SelectMany(t => _sut.ScanResources(t)).ToList();

            var firstResource = properties.FirstOrDefault(p => p.Key == "/contenttypes/modelwithnamedpropertieswithprefixandkeyonclass/name");

            Assert.NotNull(firstResource);

            var secondResource = properties.FirstOrDefault(p => p.Key == "/contenttypes/modelwithnamedpropertieswithprefixandkeyonclass/description");

            Assert.NotNull(secondResource);

            var thirdResource = properties.FirstOrDefault(p => p.Key == "/contenttypes/modelwithnamedpropertieswithprefixandkeyonclass/properties/pageheader/caption");

            Assert.NotNull(thirdResource);
        }
        public void MultipleAttributesForSingleProperty_WithPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedResourceAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ResourcesWithNamedKeysWithPrefix)}");

            var properties = model.SelectMany(t => TypeDiscoveryHelper.GetAllProperties(t)).ToList();

            var namedResource = properties.FirstOrDefault(p => p.Key == "/this/is/root/resource/and/this/is/header");

            Assert.NotNull(namedResource);
            Assert.Equal("This is header", namedResource.Translation);

            var firstResource = properties.FirstOrDefault(p => p.Key == "/this/is/root/resource/and/1stresource");

            Assert.NotNull(firstResource);
            Assert.Equal("Value in attribute", firstResource.Translation);

            var secondResource = properties.FirstOrDefault(p => p.Key == "/this/is/root/resource/and/2ndresource");

            Assert.NotNull(secondResource);
            Assert.Equal("This is property value", secondResource.Translation);
        }
예제 #11
0
 public LocalizedEnumsDiscoveryTests()
 {
     _types = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedResourceAttribute>().ToList();
     Assert.NotEmpty(_types);
 }