コード例 #1
0
        static TestPropertyDescriptor CreateTestProperty(string baseName)
        {
            var property = new TestPropertyDescriptor(baseName);

            Assert.AreEqual(baseName, property.Name);
            Assert.IsNull(property.CustomizedName);
            return(property);
        }
コード例 #2
0
        public void CustomizationSkippedWhenNoneConvention()
        {
            TestPropertyDescriptor           property      = CreateTestProperty("foo");
            IPropertyDescriptorCustomization customization = new JsonMemberNamingConventionAttribute();

            customization.Apply(property);
            Assert.IsNull(property.CustomizedName);
        }
コード例 #3
0
        public void PropertyDescriptorNameCustomizationSkippedOnEmptyName()
        {
            TestPropertyDescriptor           property      = CreateTestProperty("foo");
            IPropertyDescriptorCustomization customization = new JsonMemberNameAttribute();

            customization.Apply(property);
            Assert.IsNull(property.CustomizedName);
        }
コード例 #4
0
        public void PropertyDescriptorNameCustomization()
        {
            TestPropertyDescriptor           property      = CreateTestProperty("foo");
            IPropertyDescriptorCustomization customization = new JsonMemberNameAttribute("bar");

            customization.Apply(property);
            Assert.AreEqual("bar", property.CustomizedName);
        }
コード例 #5
0
        private static IObjectMemberExporter CreatePropertyExporter(string name, int value, int defaultValue)
        {
            TestPropertyDescriptor    property  = new TestPropertyDescriptor(name, value);
            JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(defaultValue);

            ((IPropertyDescriptorCustomization)attribute).Apply(property);
            IServiceProvider sp = property;

            return((IObjectMemberExporter)sp.GetService(typeof(IObjectMemberExporter)));
        }
コード例 #6
0
        public void PropertyDescriptorNotCustomizedWhenDefaultValueIsNull()
        {
            TestPropertyDescriptor           property      = new TestPropertyDescriptor("prop", null);
            JsonDefaultValueAttribute        attribute     = new JsonDefaultValueAttribute(null);
            IServiceProvider                 sp            = property;
            IPropertyDescriptorCustomization customization = attribute;

            customization.Apply(property);
            Assert.IsNull(sp.GetService(typeof(IObjectMemberExporter)));
        }
コード例 #7
0
        private static void TestNamingCase(string baseName, NamingConvention testCase, string expected)
        {
            JsonMemberNamingConventionAttribute attribute  = new JsonMemberNamingConventionAttribute(testCase);
            TestPropertyDescriptor           property      = CreateTestProperty(baseName);
            IPropertyDescriptorCustomization customization = attribute;

            customization.Apply(property);

            Assert.AreEqual(expected, property.CustomizedName);
        }
コード例 #8
0
        public void PropertyDescriptorCustomizedAsJsonObjectMemberExporter()
        {
            TestPropertyDescriptor    property  = new TestPropertyDescriptor("prop", 42);
            JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(42);
            IServiceProvider          sp        = property;

            Assert.IsNull(sp.GetService(typeof(IObjectMemberExporter)));
            IPropertyDescriptorCustomization customization = attribute;

            customization.Apply(property);
            IObjectMemberExporter exporter = (IObjectMemberExporter)sp.GetService(typeof(IObjectMemberExporter));

            Assert.IsNotNull(exporter);
        }
 private static TestPropertyDescriptor CreateTestProperty(string baseName) 
 {
     TestPropertyDescriptor property = new TestPropertyDescriptor(baseName);
     Assert.AreEqual(baseName, property.Name);
     Assert.IsNull(property.CustomizedName);
     return property;
 }
コード例 #10
0
 private static IObjectMemberExporter CreatePropertyExporter(string name, int value, int defaultValue)
 {
     TestPropertyDescriptor property = new TestPropertyDescriptor(name, value);
     JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(defaultValue);
     ((IPropertyDescriptorCustomization)attribute).Apply(property);
     IServiceProvider sp = property;
     return (IObjectMemberExporter) sp.GetService(typeof(IObjectMemberExporter));
 }
コード例 #11
0
 public void PropertyDescriptorNotCustomizedWhenDefaultValueIsNull()
 {
     TestPropertyDescriptor property = new TestPropertyDescriptor("prop", null);
     JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(null);
     IServiceProvider sp = property;
     IPropertyDescriptorCustomization customization = attribute;
     customization.Apply(property);
     Assert.IsNull(sp.GetService(typeof(IObjectMemberExporter)));
 }
コード例 #12
0
 public void PropertyDescriptorCustomizedAsJsonObjectMemberExporter()
 {
     TestPropertyDescriptor property = new TestPropertyDescriptor("prop", 42);
     JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(42);
     IServiceProvider sp = property;
     Assert.IsNull(sp.GetService(typeof(IObjectMemberExporter)));
     IPropertyDescriptorCustomization customization = attribute;
     customization.Apply(property);
     IObjectMemberExporter exporter = (IObjectMemberExporter) sp.GetService(typeof(IObjectMemberExporter));
     Assert.IsNotNull(exporter);
 }
コード例 #13
0
        public void MemberImportCustomization()
        {
            TestObjectMemberImporter memberImporter = new TestObjectMemberImporter();
            Hashtable services = new Hashtable();
            services.Add(typeof(IObjectMemberImporter), memberImporter);

            TestTypeDescriptor logicalType = new TestTypeDescriptor();
            PropertyDescriptorCollection properties = logicalType.GetProperties();
            TestPropertyDescriptor property = new TestPropertyDescriptor("prop", typeof(object), services);
            properties.Add(property);
            
            ComponentImporter importer = new ComponentImporter(typeof(Thing), logicalType);
            ImportContext context = new ImportContext();
            context.Register(importer);
            
            JsonRecorder writer = new JsonRecorder();
            writer.WriteStartObject();
            writer.WriteMember("prop");
            writer.WriteString("value");
            writer.WriteEndObject();

            JsonReader reader = writer.CreatePlayer();
            Thing thing = (Thing) context.Import(typeof(Thing), reader);
            
            Assert.AreSame(context, memberImporter.ImportContext);
            Assert.AreSame(reader, memberImporter.ImportReader);
            Assert.AreSame(thing, memberImporter.ImportTarget);
            Assert.AreEqual("value", memberImporter.ImportedValue);
        }