Add USE_REAL_RESOURCES to easily test if `[Display]` usability has improved

- `[Display]` works only with `public` resources (classes and properties)
- also change `TestResources` to make `Resources` the single source of truth
This commit is contained in:
Doug Bunting 2015-03-21 16:05:55 -07:00
parent 7dd3afe3d1
commit ec6f1907c5
2 changed files with 20 additions and 6 deletions

View File

@ -156,8 +156,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
var display = new DisplayAttribute()
{
Name = "DisplayAttribute_Name",
#if USE_REAL_RESOURCES
Name = nameof(Test.Resources.DisplayAttribute_Name),
ResourceType = typeof(Test.Resources),
#else
Name = nameof(Test.Resources.DisplayAttribute_Name),
ResourceType = typeof(Test.TestResources),
#endif
};
var attributes = new Attribute[] { display };
@ -180,8 +185,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
var display = new DisplayAttribute()
{
Description = "DisplayAttribute_Description",
#if USE_REAL_RESOURCES
Description = nameof(Test.Resources.DisplayAttribute_Description),
ResourceType = typeof(Test.Resources),
#else
Description = nameof(Test.Resources.DisplayAttribute_Description),
ResourceType = typeof(Test.TestResources),
#endif
};
var attributes = new Attribute[] { display };
@ -568,7 +578,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
[Display(Name = "menos uno")]
MinusOne = -1,
#if USE_REAL_RESOURCES
[Display(Name = nameof(Test.Resources.DisplayAttribute_Name), ResourceType = typeof(Test.Resources))]
#else
[Display(Name = nameof(Test.TestResources.DisplayAttribute_Name), ResourceType = typeof(Test.TestResources))]
#endif
MinusTwo = -2,
}

View File

@ -3,12 +3,12 @@
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{
// This class is a 'fake' resources for testing DisplayAttribute. We can't use actual resources
// because our generator makes it an internal class, which doesn't work with DisplayAttribute.
// Wrap resources to make them available as public properties for [Display]. That attribute does not support
// internal properties.
public static class TestResources
{
public static string DisplayAttribute_Description { get; } = "description from resources";
public static string DisplayAttribute_Description { get; } = Resources.DisplayAttribute_Description;
public static string DisplayAttribute_Name { get; } = "name from resources";
public static string DisplayAttribute_Name { get; } = Resources.DisplayAttribute_Name;
}
}