public void DeserializeComplex_PrimitiveInt64() { long val = 10; var expressionStr = val.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <long>(expressionStr); Assert.Equal(10, deserialized); }
public void DeserializeComplex_PrimitiveByte() { byte val = 1; var expressionStr = val.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <byte>(expressionStr); Assert.Equal(1, deserialized); }
public void DeserializeComplex_PrimitiveChar() { var val = 'º'; var expressionStr = val.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <char>(expressionStr); Assert.Equal(val, deserialized); }
public void DeserializeComplex_PrimitiveDateTimeOffset() { var val = new DateTimeOffset(2000, 1, 1, 1, 1, 1, new TimeSpan()); var expressionStr = val.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <DateTime>(expressionStr); Assert.Equal(val, deserialized); }
public void DeserializeComplex_PrimitiveLong() { long longVal = long.MaxValue; var expressionStr = longVal.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <long>(expressionStr); Assert.Equal(longVal, deserialized); }
public void DeserializeComplex_PrimitiveDouble() { double val = 99.99D; var expressionStr = val.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <double>(expressionStr); Assert.Equal(val, deserialized); }
public void DeserializeComplex_PrimitiveFloat() { float val = 99.99F; var expressionStr = val.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <float>(expressionStr); Assert.Equal(val, deserialized); }
public void DeserializationComplex1() { var expressionAsString = "\"Int32[].1\" + \"[0]: 1\" + \"[1]: 2\" + \"[2]: 3\""; var deserializer = new ComplexEntityExpressionDeserializer(); var array = deserializer.Deserialize <int[]>(expressionAsString); System.Console.WriteLine(array[0]); System.Console.WriteLine(array[1]); System.Console.WriteLine(array[2]); }
public void DeserializeComplex_ArrayInt() { var array = new int[] { 1, 2, 3 }; var expressionStr = array.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <int[]>(expressionStr); Assert.Equal(1, deserialized[0]); Assert.Equal(2, deserialized[1]); Assert.Equal(3, deserialized[2]); }
public void DeserializeComplex_TypedObject_PublicPropertyNoSetter() { var expressionStr = "\"Complex.1\" + \"PropOnlySet: 2000\" + \"Prop1: 1\" + \"Prop3: 3\" + \"Prop2: 2\" + \"Prop4: 4\" + \"PropNoBackingField: 999\""; var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <PropertyPrivateWithoutSetter>(expressionStr); Assert.Equal(1, deserialized.Prop1); Assert.Equal(2, deserialized.Prop2); Assert.Equal(3, deserialized.GetType().GetProperty("Prop3", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(deserialized)); Assert.Equal(4, deserialized.Prop4); Assert.Equal(2000, deserialized.propOnlyValue); Assert.Equal(2, deserialized.PropNoBackingField); }
public void DeserializeComplex_TypedObject_PropertyIEnumerableAndBackFieldIsList() { var obj = new PropertyTypeDiffBackField(); obj.Set(); var expressionStr = obj.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <PropertyTypeDiffBackField>(expressionStr); Assert.Equal(1, deserialized.IEnumerable.ElementAt(0)); Assert.Equal(2, deserialized.IEnumerable.ElementAt(1)); Assert.Equal(3, deserialized.IEnumerable.ElementAt(2)); }
public void DeserializeComplex_DictionaryPrimitiveObject() { var dic = new Dictionary <string, int>() { { "A", 1 }, { "B", 2 }, }; var expressionStr = dic.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <Dictionary <string, int> >(expressionStr); Assert.Equal(2, deserialized.Count); Assert.Equal(1, deserialized["A"]); Assert.Equal(2, deserialized["B"]); }
public void DeserializeComplex_ArrayJaggedComplexMultidimetional() { int[][] jaggedArray = new int[2][]; jaggedArray[0] = new int[2]; jaggedArray[0][0] = 10; jaggedArray[0][1] = 20; jaggedArray[1] = new int[1]; jaggedArray[1][0] = 30; var expressionStr = jaggedArray.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <int[][]>(expressionStr); Assert.Equal(10, deserialized[0][0]); Assert.Equal(20, deserialized[0][1]); Assert.Equal(30, deserialized[1][0]); }
public void DeserializeComplex_AnonymousObjectWithPrimitivesOnly_NoTyped() { var obj = new { Prop1 = "Value", Prop2 = 100, Prop3 = new { Prop4 = 10.10d, Prop5 = new { Prop6 = 1 }, Prop7 = new { Prop8 = 'a', Prop9 = (string)null, }, } }; var expressionStr = obj.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize(expressionStr); var cast = Dynamic(deserialized); Assert.IsType <ExpandoObject>(deserialized); Assert.Equal("Value", cast.Prop1); Assert.Equal("100", cast.Prop2); var prop3 = Dynamic(cast.Prop3); Assert.Equal("10.1", prop3.Prop4); var prop5 = Dynamic(prop3.Prop5); Assert.Equal("1", prop5.Prop6); var prop7 = Dynamic(prop3.Prop7); Assert.Equal("a", prop7.Prop8); Assert.Equal(null, prop7.Prop9); // var serializeFinal = ((object)cast).AsExpression().DefaultSerializer.Serialize(); }
public void DeserializeComplex_TypedObject_MultiLevel() { var objTyped = new RecursiveClass() { MyProp = 1, RecursiveProperty = new RecursiveClass() { MyProp = 2, RecursiveProperty = new RecursiveClass() { MyProp = 3, RecursiveProperty = new RecursiveClass() { MyProp = 4, RecursiveProperty = null, ZProp = "D" }, ZProp = "C" }, ZProp = "B" }, ZProp = "A" }; var expressionStr = objTyped.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = (RecursiveClass)deserializer.Deserialize(expressionStr, objTyped.GetType()); Assert.IsType <RecursiveClass>(deserialized); Assert.Equal(1, deserialized.MyProp); Assert.Equal("A", deserialized.ZProp); Assert.Equal(2, deserialized.RecursiveProperty.MyProp); Assert.Equal("B", deserialized.RecursiveProperty.ZProp); Assert.Equal(3, deserialized.RecursiveProperty.RecursiveProperty.MyProp); Assert.Equal("C", deserialized.RecursiveProperty.RecursiveProperty.ZProp); Assert.Equal(4, deserialized.RecursiveProperty.RecursiveProperty.RecursiveProperty.MyProp); Assert.Equal("D", deserialized.RecursiveProperty.RecursiveProperty.RecursiveProperty.ZProp); }
public void DeserializeComplex_AnonymousObjectWithComplex_NoTyped() { var obj = new { Prop1 = "Value", Prop2 = new RecursiveClass() { MyProp = 12 } }; var expressionStr = obj.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize(expressionStr); var cast = Dynamic(deserialized); Assert.IsType <ExpandoObject>(deserialized); Assert.Equal("Value", cast.Prop1); var prop2 = Dynamic(cast.Prop2); Assert.Equal("12", prop2.MyProp); }
private void TestMultiLevel(Func <CircularEntity> action) { Clear(); var objA = action(); var serializer = objA.AsExpression().GetSerializer <ComplexEntityExpressionSerializer>(); serializer.GetEntityIdCallback = item => VertexContainer <object> .GetEntityId(item.Entity).Id; var expressionStr = serializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var objB = deserializer.Deserialize <CircularEntity>(expressionStr); var jsonSettings = new JsonSerializerSettings { Formatting = Formatting.Indented, PreserveReferencesHandling = PreserveReferencesHandling.Objects }; var jsonA = JsonConvert.SerializeObject(objA, jsonSettings); var jsonB = JsonConvert.SerializeObject(objB, jsonSettings); Assert.Equal(jsonA, jsonB); }
public void DeserializeComplex_TypedObject_ShowType_None() { var obj = new RecursiveClass { MyProp = 10, RecursiveProperty = new RecursiveClass() { MyProp = 20 }, ZProp = "value" }; var serializer = obj.AsExpression().GetSerializer <ComplexEntityExpressionSerializer>(); serializer.ShowType = ShowTypeOptions.None; var expressionStr = serializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <RecursiveClass>(expressionStr); Assert.Equal(10, deserialized.MyProp); Assert.Equal("value", deserialized.ZProp); Assert.Equal(20, deserialized.RecursiveProperty.MyProp); }
public void DeserializeComplex_DictionaryComplexKeyAndValueObject() { var key = new PublicConstructorWithParameters("value") { Prop1 = 1 }; var value = new PublicConstructorWithParameters("value") { Prop1 = 2 }; var dic = new Dictionary <PublicConstructorWithParameters, PublicConstructorWithParameters>() { { key, value }, }; var anonymous = new { A = dic, PropKey = key, PropValue = value }; var expressionStr = anonymous.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = (ExpandoObject)deserializer.Deserialize(expressionStr, anonymous.GetType()); var A = GetExpandoObjectValue <Dictionary <PublicConstructorWithParameters, PublicConstructorWithParameters> >(deserialized, "A"); var propKey = GetExpandoObjectValue <PublicConstructorWithParameters>(deserialized, "PropKey"); var propValue = GetExpandoObjectValue <PublicConstructorWithParameters>(deserialized, "PropValue"); Assert.Equal(1, A.Keys.ElementAt(0).Prop1); Assert.Equal(2, A.Values.ElementAt(0).Prop1); Assert.Same(propKey, A.Keys.ElementAt(0)); Assert.Same(propValue, A.Values.ElementAt(0)); }
public void DeserializeComplex_ArrayComplex() { var value1 = new PublicConstructorWithParameters("value") { Prop1 = 1 }; var value2 = new PublicConstructorWithParameters("value") { Prop1 = 2 }; var value3 = new PublicConstructorWithParameters("value") { Prop1 = 3 }; var array = new PublicConstructorWithParameters[] { value1, value2, value3 }; var expressionStr = array.AsExpression().DefaultSerializer.Serialize(); var deserializer = new ComplexEntityExpressionDeserializer(); var deserialized = deserializer.Deserialize <PublicConstructorWithParameters[]>(expressionStr); Assert.Equal(1, deserialized[0].Prop1); Assert.Equal(2, deserialized[1].Prop1); Assert.Equal(3, deserialized[2].Prop1); }