public void NonMemberImport()
        {
            var          importer = new ComponentImporter(typeof(DynamicThing));
            var          context  = new ImportContext();
            const string json     = "{ str1: value1, str2: value2, num: 42 }";
            var          thing    = (DynamicThing)importer.Import(context, JsonText.CreateReader(json));

            Assert.AreEqual(2, thing.NonMembers.Count);
            Assert.AreEqual("value1", thing.NonMembers["str1"]);
            Assert.AreEqual("value2", thing.NonMembers["str2"]);
        }
        public void SkipsReadOnlyProperty()
        {
            var thingType  = typeof(Thing);
            var reader     = new JsonTextReader(new StringReader("{ Id : 42 }"));
            var descriptor = new TestTypeDescriptor();

            descriptor.GetProperties().Add(new ReadOnlyPropertyDescriptor("Id"));
            var importer = new ComponentImporter(thingType, descriptor);

            importer.Import(new ImportContext(), reader);
            Assert.IsFalse(((ReadOnlyPropertyDescriptor)descriptor.GetProperties().Find("Id", false)).SetValueCalled);
        }
Пример #3
0
 public void ImportNull()
 {
     ComponentImporter importer = new ComponentImporter(typeof(object));
     Assert.IsNull(importer.Import(new ImportContext(), CreateReader("null")));
 }
Пример #4
0
 public void NonMemberImport()
 {
     ComponentImporter importer = new ComponentImporter(typeof(DynamicThing));
     ImportContext context = new ImportContext();
     const string json = "{ str1: value1, str2: value2, num: 42 }";
     DynamicThing thing = (DynamicThing) importer.Import(context, JsonText.CreateReader(json));
     Assert.AreEqual(2, thing.NonMembers.Count);
     Assert.AreEqual("value1", thing.NonMembers["str1"]);
     Assert.AreEqual("value2", thing.NonMembers["str2"]);
 }
Пример #5
0
 public void SkipsReadOnlyProperty()
 {
     Type thingType = typeof(Thing);
     JsonTextReader reader = new JsonTextReader(new StringReader("{ Id : 42 }"));
     TestTypeDescriptor descriptor = new TestTypeDescriptor();
     descriptor.GetProperties().Add(new ReadOnlyPropertyDescriptor("Id"));
     ComponentImporter importer = new ComponentImporter(thingType, descriptor);
     importer.Import(new ImportContext(), reader);
     Assert.IsFalse(((ReadOnlyPropertyDescriptor) descriptor.GetProperties().Find("Id", false)).SetValueCalled);
 }
        public void ImportNull()
        {
            var importer = new ComponentImporter(typeof(object));

            Assert.IsNull(importer.Import(new ImportContext(), CreateReader("null")));
        }