public void Ignored_WhenInternalSetter_DefaultsToTrue()
        {
            SerializerSettings context = new SerializerSettings();
            ITypeData          handler = context.Types[typeof(NonWritableProperty)];

            Assert.IsTrue(handler.FindProperty("InternalInt").Ignored);
        }
        public void IgnoredBaseProperty_SharedByChildren()
        {
            SerializerSettings context   = new SerializerSettings();
            ITypeData          child     = context.Types[typeof(ChildClass)];
            ITypeData          baseClass = context.Types[typeof(BaseClass)];

            Assert.AreSame(baseClass.FindProperty("IgnoredProperty"), child.FindProperty("IgnoredProperty"), "child IgnoredProperty");
        }
        public void OverridenBaseProperty_NotSharedByChildren()
        {
            SerializerSettings context   = new SerializerSettings();
            ITypeData          child     = context.Types[typeof(ChildClass)];
            ITypeData          baseClass = context.Types[typeof(BaseClass)];

            Assert.AreNotSame(baseClass.FindProperty("OverriddenProperty"), child.FindProperty("OverriddenProperty"), "child OverriddenProperty");
        }
        public void FindProperty_FindsIgnoredProperties()
        {
            SerializerSettings context      = new SerializerSettings();
            ITypeData          handler      = context.Type <IgnoredFieldClass>();
            IPropertyData      fieldHandler = handler.FindProperty("IVal");

            Assert.IsNotNull(fieldHandler, "Ignored property not found");
        }
Beispiel #5
0
        public void DefaultValuesOnPropertyAreConvertedIfNotSameType()
        {
            ISerializerSettings config   = new SerializerSettings();
            ITypeData           typeData = config.Types[typeof(MockDefaultValues)];
            IPropertyData       property = typeData.FindProperty("ConvertedValue");

            Assert.IsFalse(property.ShouldWriteValue(config, (short)32));
            Assert.IsTrue(property.ShouldWriteValue(config, 0));
        }
Beispiel #6
0
        public void WhenDefaultValuesSetByAttributeOnType_PropertyInheritsIt()
        {
            ISerializerSettings config   = new SerializerSettings();
            ITypeData           typeData = config.Types[typeof(MockDefaultValuesCascade)];
            IPropertyData       property = typeData.FindProperty("EmptyString");

            Assert.IsFalse(property.ShouldWriteValue(config, ""));
            Assert.IsTrue(property.ShouldWriteValue(config, null));
        }
        public void AttributeProcessors_CustomProcessor_XmlIgnore()
        {
            SerializerSettings context = new SerializerSettings();

            context.Types.AttributeProcessors.Add(new XmlIgnoreAttributeProcessor());
            ITypeData handler = context.Type <XmlIgnoreMock>();

            Assert.IsTrue(handler.FindProperty("Salary").Ignored, "XmlIgnore attribute not ignored");
        }
Beispiel #8
0
        public void TestDefaultPropertyAttributes()
        {
            ISerializerSettings config     = new SerializerSettings();
            ITypeData           typeData   = config.Types.Type <MockDefaultValues>();
            IPropertyData       intDefault = typeData.FindProperty("IntDefault");

            Assert.AreEqual(DefaultValueOption.SuppressDefaultValues, intDefault.DefaultValueSetting, "IntDefault DefaultValueSetting");
            Assert.IsFalse(intDefault.ShouldWriteValue(config, 0));

            IPropertyData intCustomDefault = typeData.FindProperty("IntCustomDefault");

            Assert.AreEqual(DefaultValueOption.SuppressDefaultValues, intCustomDefault.DefaultValueSetting, "IntCustomDefault DefaultValueSetting");
            Assert.IsFalse(intCustomDefault.ShouldWriteValue(config, 10));

            IPropertyData stringDefaultDisabled = typeData.FindProperty("StringDefaultDisabled");

            Assert.AreEqual(DefaultValueOption.WriteAllValues, stringDefaultDisabled.DefaultValueSetting, "StringDefaultDisabled DefaultValueSetting");
            Assert.IsTrue(stringDefaultDisabled.ShouldWriteValue(config, null));
        }