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); }
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")); }
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")); }
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")); }
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")); }
public void SerializePropertiesWithOnlySetter() { IIonStruct serialized = StreamToIonValue(defaultSerializer.Serialize(new ClassWithOnlySetProperty("test"))); Assert.IsFalse(serialized.ContainsField("setOnlyProperty")); }