public void MultipleAttributesForSingleProperty_NoPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedProperties)}");

            var properties = model.SelectMany(t => TypeDiscoveryHelper.GetAllProperties(t, contextAwareScanning: false)).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.Translation);

            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.Translation);
        }
Beispiel #2
0
        public LocalizedModelsDiscoveryTests()
        {
            var types = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>().ToList();

            Assert.NotEmpty(types);

            _properties = types.SelectMany(t => TypeDiscoveryHelper.GetAllProperties(t, contextAwareScanning: false));
        }
Beispiel #3
0
        public void DiscoverEnumValue_NameAsTranslation()
        {
            var type       = _types.First(t => t.FullName == "DbLocalizationProvider.Tests.SampleStatus");
            var properties = TypeDiscoveryHelper.GetAllProperties(type);

            var openStatus = properties.First(p => p.Key == "DbLocalizationProvider.Tests.SampleStatus.Open");

            Assert.Equal("Open", openStatus.Translation);
        }
Beispiel #4
0
        public void NestedType_ScalarProperties()
        {
            var type = _types.First(t => t.FullName == "DbLocalizationProvider.Tests.PageResources");

            Assert.NotNull(type);

            var property = TypeDiscoveryHelper.GetAllProperties(type).FirstOrDefault(p => p.Key == "DbLocalizationProvider.Tests.PageResources.Header.HelloMessage");

            Assert.NotNull(property);
        }
Beispiel #5
0
        public void SingleLevel_ScalarProperties()
        {
            var type       = _types.First(t => t.FullName == "DbLocalizationProvider.Tests.ResourceKeys");
            var properties = TypeDiscoveryHelper.GetAllProperties(type);

            var staticField = properties.First(p => p.Key == "DbLocalizationProvider.Tests.ResourceKeys.ThisIsConstant");

            Assert.True(TypeDiscoveryHelper.IsStringProperty(staticField.ReturnType));
            Assert.Equal("Default value for constant", staticField.Translation);
        }
        public void MultipleAttributesForSingleProperty_NoPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedResourceAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ResourcesWithNamedKeys)}");

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

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

            Assert.NotNull(namedResource);
            Assert.Equal("This is header", namedResource.Translation);
        }
        public void SingleAttributeForSingleProperty_WithClassPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedPropertiesWithPrefix)}");

            var properties = model.SelectMany(t => TypeDiscoveryHelper.GetAllProperties(t, contextAwareScanning: false)).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.Translation);
        }
Beispiel #8
0
        public void NestedObject_ScalarProperties()
        {
            var type       = _types.First(t => t.FullName == "DbLocalizationProvider.Tests.ResourceKeys");
            var properties = TypeDiscoveryHelper.GetAllProperties(type).ToList();

            var complexPropertySubProperty = properties.FirstOrDefault(p => p.Key == "DbLocalizationProvider.Tests.ResourceKeys.SubResource.SubResourceProperty");

            Assert.NotNull(complexPropertySubProperty);
            Assert.Equal("Sub Resource Property", complexPropertySubProperty.Translation);

            Assert.Contains("DbLocalizationProvider.Tests.ResourceKeys.SubResource.AnotherResource", properties.Select(k => k.Key));
            Assert.Contains("DbLocalizationProvider.Tests.ResourceKeys.SubResource.EvenMoreComplexResource.Amount", properties.Select(k => k.Key));

            // need to check that there is no resource discovered for complex properties itself
            Assert.DoesNotContain("DbLocalizationProvider.Tests.ResourceKeys.SubResource", properties.Select(k => k.Key));
            Assert.DoesNotContain("DbLocalizationProvider.Tests.ResourceKeys.SubResource.EvenMoreComplexResource", properties.Select(k => k.Key));
        }
        public void MultipleAttributeForSingleProperty_WithClassPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedPropertiesWithPrefix)}");

            var properties = model.SelectMany(t => TypeDiscoveryHelper.GetAllProperties(t, contextAwareScanning: false)).ToList();

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

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

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

            Assert.NotNull(secondResource);
            Assert.Equal("2nd resource", secondResource.Translation);
        }
        public void ResourceAttributeToClass_WithClassPrefix()
        {
            var model = TypeDiscoveryHelper.GetTypesWithAttribute <LocalizedModelAttribute>()
                        .Where(t => t.FullName == $"DbLocalizationProvider.Tests.NamedResources.{nameof(ModelWithNamedPropertiesWithPrefixAndKeyOnClass)}");

            var properties = model.SelectMany(t => TypeDiscoveryHelper.GetAllProperties(t, contextAwareScanning: false)).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);
        }