public void TestDeserialize() { ObjectOne obj = new ObjectOne(); JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 0.0,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}"); Assert.AreEqual(0.0f, obj.MyValue); Assert.AreEqual(Vector2.Zero, obj.MyVector); Assert.IsNull(obj.MyArray); JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}"); Assert.AreEqual(1.2f, obj.MyValue); Assert.AreEqual(Vector2.Zero, obj.MyVector); Assert.IsNull(obj.MyArray); JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t}\n}"); Assert.AreEqual(1.2f, obj.MyValue); Assert.AreEqual(new Vector2(0.0f, 2.0f), obj.MyVector); Assert.IsNull(obj.MyArray); JsonSerializer.Deserialize(obj, "{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t},\n\t\"MyArray\": [\n\t\t1,\n\t\t2,\n\t\t3,\n\t\t4\n\t]\n}"); Assert.AreEqual(1.2f, obj.MyValue); Assert.AreEqual(new Vector2(0.0f, 2.0f), obj.MyVector); Assert.IsNotNull(obj.MyArray); Assert.IsTrue(Utils.ArraysEqual(obj.MyArray, new[] { 1, 2, 3, 4 })); }
public void TestSerialize() { ObjectOne obj = new ObjectOne(); Assert.AreEqual("{\n\t\"MyValue\": 0.0,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}", FilterLineBreak(JsonSerializer.Serialize(obj))); obj.MyValue = 1.2f; Assert.AreEqual("{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 0.0\n\t}\n}", FilterLineBreak(JsonSerializer.Serialize(obj))); obj.MyVector.Y = 2.0f; Assert.AreEqual("{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t}\n}", FilterLineBreak(JsonSerializer.Serialize(obj))); obj.MyArray = new[] { 1, 2, 3, 4 }; Assert.AreEqual("{\n\t\"MyValue\": 1.2,\n\t\"MyVector\": {\n\t\t\"X\": 0.0,\n\t\t\"Y\": 2.0\n\t},\n\t\"MyArray\": [\n\t\t1,\n\t\t2,\n\t\t3,\n\t\t4\n\t]\n}", FilterLineBreak(JsonSerializer.Serialize(obj))); }
public void TestSerializeDiff() { ObjectOne obj = new ObjectOne(); ObjectOne other = new ObjectOne(); Assert.AreEqual("{}", JsonSerializer.SerializeDiff(obj, other)); obj.MyValue = 2.0f; Assert.AreEqual("{\n\t\"MyValue\": 2.0\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other))); obj.MyValue = 2.0f; other.MyValue = 2.0f; Assert.AreEqual("{}", JsonSerializer.SerializeDiff(obj, other)); other.MyArray = new[] { 1 }; Assert.AreEqual("{\n\t\"MyArray\": null\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other))); obj.MyArray = other.MyArray; Assert.AreEqual("{}", JsonSerializer.SerializeDiff(obj, other)); obj.MyArray = new[] { 1 }; Assert.AreEqual("{}", JsonSerializer.SerializeDiff(obj, other)); obj.MyArray = new[] { 2 }; Assert.AreEqual("{\n\t\"MyArray\": [\n\t\t2\n\t]\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other))); other.MyArray = null; Assert.AreEqual("{\n\t\"MyArray\": [\n\t\t2\n\t]\n}", FilterLineBreak(JsonSerializer.SerializeDiff(obj, other))); }