static TestPropertyDescriptor CreateTestProperty(string baseName) { var property = new TestPropertyDescriptor(baseName); Assert.AreEqual(baseName, property.Name); Assert.IsNull(property.CustomizedName); return(property); }
public void CustomizationSkippedWhenNoneConvention() { TestPropertyDescriptor property = CreateTestProperty("foo"); IPropertyDescriptorCustomization customization = new JsonMemberNamingConventionAttribute(); customization.Apply(property); Assert.IsNull(property.CustomizedName); }
public void PropertyDescriptorNameCustomizationSkippedOnEmptyName() { TestPropertyDescriptor property = CreateTestProperty("foo"); IPropertyDescriptorCustomization customization = new JsonMemberNameAttribute(); customization.Apply(property); Assert.IsNull(property.CustomizedName); }
public void PropertyDescriptorNameCustomization() { TestPropertyDescriptor property = CreateTestProperty("foo"); IPropertyDescriptorCustomization customization = new JsonMemberNameAttribute("bar"); customization.Apply(property); Assert.AreEqual("bar", property.CustomizedName); }
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))); }
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))); }
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); }
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; }
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)); }
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); }
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); }