Esempio n. 1
0
        public void DoesNotDoubleSerializeIonFieldsAlreadySerializedByMethods()
        {
            IIonStruct serialized = ToIonValue(new IonSerializer(), TestObjects.Ruler);

            Assert.IsTrue(serialized.ContainsField("length"));
            Assert.IsTrue(serialized.ContainsField("unit"));

            // We should have exactly two fields. ie. we did not double serialize the Ruler's length or unit members.
            Assert.AreEqual(2, serialized.Count);
        }
Esempio n. 2
0
        public void SerializeReadOnlyPropertiesWithAccessModifiers()
        {
            IIonStruct serialized = StreamToIonValue(defaultSerializer.Serialize(TestObjects.objectWithReadonlyProperties));

            Assert.AreEqual("Public Value", serialized.GetField("publicProperty").StringValue);
            Assert.AreEqual("Protected Internal Value", serialized.GetField("protectedInternalProperty").StringValue);
            Assert.AreEqual("Internal Value", serialized.GetField("internalProperty").StringValue);
            Assert.IsFalse(serialized.ContainsField("protectedProperty"));
            Assert.IsFalse(serialized.ContainsField("privateProperty"));
            Assert.IsFalse(serialized.ContainsField("protectedPrivateProperty"));
        }
Esempio n. 3
0
        public void SerializesObjectsWithIgnoreReadOnlyProperties()
        {
            var serializer = new IonSerializer(new IonSerializationOptions {
                IgnoreReadOnlyProperties = true
            });
            IIonStruct serialized = StreamToIonValue(serializer.Serialize(TestObjects.JohnGreenwood));

            Assert.IsTrue(serialized.ContainsField("firstName"));
            Assert.IsTrue(serialized.ContainsField("lastName"));
            Assert.IsFalse(serialized.ContainsField("major"));
        }
Esempio n. 4
0
        public void SerializesObjectsWithIgnoreReadOnlyFields()
        {
            var serializer = new IonSerializer(new IonSerializationOptions {
                IgnoreReadOnlyFields = true, IncludeFields = true
            });

            IIonStruct serialized = StreamToIonValue(serializer.Serialize(TestObjects.drKyler));

            Assert.IsFalse(serialized.ContainsField("firstName"));
            Assert.IsFalse(serialized.ContainsField("lastName"));
            Assert.IsTrue(serialized.ContainsField("department"));
            Assert.IsFalse(serialized.ContainsField("birthDate"));
        }
Esempio n. 5
0
        public void SerializesObjectsWithIgnoreDefaults()
        {
            var serializer = new IonSerializer(new IonSerializationOptions {
                IgnoreDefaults = true
            });
            IIonStruct serialized = StreamToIonValue(serializer.Serialize(new Motorcycle {
                canOffroad = true
            }));

            Assert.IsFalse(serialized.ContainsField("Brand"));
            Assert.IsFalse(serialized.ContainsField("color"));
            Assert.IsTrue(serialized.ContainsField("canOffroad"));
        }
Esempio n. 6
0
        public void SerializePropertiesWithOnlySetter()
        {
            IIonStruct serialized = StreamToIonValue(defaultSerializer.Serialize(new ClassWithOnlySetProperty("test")));

            Assert.IsFalse(serialized.ContainsField("setOnlyProperty"));
        }