public void ResetValue()
        {
            JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(42);

            attribute.Value = "foobar";
            Assert.AreEqual("foobar", attribute.Value);
        }
        private static void AssertInitialization(object value)
        {
            JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(value);

            Assert.IsNotNull(attribute.Value);
            Assert.IsInstanceOfType(value.GetType(), attribute.Value);
            Assert.AreEqual(value, attribute.Value);
        }
        public void TypedInitialization()
        {
            const string guidString             = "79588595-234b-4abc-9624-d221feb2a816";
            JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(typeof(Guid), guidString);

            Assert.IsNotNull(attribute.Value);
            Assert.IsInstanceOfType(typeof(Guid), attribute.Value);
            Assert.AreEqual(new Guid(guidString), attribute.Value);
        }
        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)));
        }
        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 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));
 }
 private static void AssertInitialization(object value)
 {
     JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(value);
     Assert.IsNotNull(attribute.Value);
     Assert.IsInstanceOfType(value.GetType(), attribute.Value);
     Assert.AreEqual(value, attribute.Value);
 }
 public void TypedInitialization()
 {
     const string guidString = "79588595-234b-4abc-9624-d221feb2a816";
     JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(typeof(Guid), guidString);
     Assert.IsNotNull(attribute.Value);
     Assert.IsInstanceOfType(typeof(Guid), attribute.Value);
     Assert.AreEqual(new Guid(guidString), attribute.Value);
 }
 public void ResetValue()
 {
     JsonDefaultValueAttribute attribute = new JsonDefaultValueAttribute(42);
     attribute.Value = "foobar";
     Assert.AreEqual("foobar", attribute.Value);
 }
 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)));
 }
 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);
 }