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 SerializeMethodsWithAccessModifiers() { IIonStruct serialized = StreamToIonValue(defaultSerializer.Serialize(TestObjects.objectWithMethods)); Assert.AreEqual("Public Value", serialized.GetField("public value").StringValue); Assert.AreEqual("Protected Value", serialized.GetField("protected value").StringValue); Assert.AreEqual("Protected Internal Value", serialized.GetField("protected internal value").StringValue); Assert.AreEqual("Internal Value", serialized.GetField("internal value").StringValue); Assert.AreEqual("Private Value", serialized.GetField("private value").StringValue); Assert.AreEqual("Private Protected Value", serialized.GetField("private protected value").StringValue); }
public void SerializeIonPropertyNamesWithAccessModifiers() { IIonStruct serialized = StreamToIonValue(defaultSerializer.Serialize(TestObjects.objectWithIonPropertyNameAttributes)); Assert.AreEqual("Public Value", serialized.GetField("Public Property").StringValue); Assert.AreEqual("Protected Internal Value", serialized.GetField("Protected Internal Property").StringValue); Assert.AreEqual("Internal Value", serialized.GetField("Internal Property").StringValue); Assert.AreEqual("Protected Value", serialized.GetField("Protected Property").StringValue); Assert.AreEqual("Private Value", serialized.GetField("Private Property").StringValue); Assert.AreEqual("Private Protected Value", serialized.GetField("Private Protected Property").StringValue); }
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")); }
private static IDictionary <Field, Field> ConvertToMultiset(IIonStruct ionStruct, bool strict) { var multiset = new Dictionary <Field, Field>(); foreach (var structField in ionStruct) { var field = new Field(structField, strict); if (multiset.TryGetValue(field, out var existing)) { existing.Count++; } else { multiset.Add(field, field); } } return(multiset); }
private static int CompareStructs(IIonStruct s1, IIonStruct s2, bool strict) { var result = s1.Size - s1.Size; if (result != 0) { return(result); } var multiset = ConvertToMultiset(s1, strict); foreach (var s2Field in s2) { var field = new Field(s2Field, strict); if (!multiset.TryGetValue(field, out var mapped) || mapped.Count <= 0) { return(-1); } mapped.Count--; } return(result); }
public void SerializePropertiesWithOnlySetter() { IIonStruct serialized = StreamToIonValue(defaultSerializer.Serialize(new ClassWithOnlySetProperty("test"))); Assert.IsFalse(serialized.ContainsField("setOnlyProperty")); }