public void TestMerge() { var js = new JsonSerializer(); js.JsonOptions.Indent = ""; js.JsonOptions.FieldSeparator = ""; var v1 = new SampleMerge(); v1.DI.Add(3, 4); v1.LI.Add(33); v1.M = new Sample1 { X = 768, Y = "ttt" }; var result1 = js.ToString(v1); Assert.AreEqual("{\"DI\":{\"3\":4},\"LI\":[33],\"M\":{\"X\":768}}", result1); var jd = new JsonDeserializer(); var w1 = new SampleMerge(); w1.DI.Add(5, 6); w1.LI.Add(44); w1.M = new Sample1 { X = 999, Y = "qqq" }; jd.FromString(w1, result1); CollectionAssert.AreEqual(new Dictionary<int, int> { { 5, 6 }, { 3, 4 } }, w1.DI); CollectionAssert.AreEqual(new[] { 44, 33 }, w1.LI); Assert.AreEqual(768, w1.M.X); Assert.AreEqual("qqq", w1.M.Y); var w2 = new SampleMerge(); w2.DI.Add(51, 61); w2.LI.Add(55); w2.M = new Sample1 { X = 999, Y = "www" }; SampleMerge_JsonDeserializer.Instance.FromString(w2, result1); CollectionAssert.AreEqual(new Dictionary<int, int> { { 51, 61 }, { 3, 4 } }, w2.DI); CollectionAssert.AreEqual(new[] { 55, 33 }, w2.LI); Assert.AreEqual(768, w2.M.X); Assert.AreEqual("www", w2.M.Y); }
public void TestMerge() { var bs = new BinarySerializer(); var v1 = new SampleMerge(); v1.DI.Add(3, 4); v1.LI.Add(33); v1.M = new Sample1 { X = 768, Y = "ttt" }; var result1 = bs.ToBytes(v1); Assert.AreEqual( "20 01 00 " + XS(typeof(SampleMerge)) + " 03 00 " + XS("DI") + " 22 05 05 " + XS("LI") + " 21 05 " + XS("M", RoughType.Record) + " 01 00 01 00 00 00 03 00 00 00 04 00 00 00 02 00 01 00 00 00 21 00 00 00 03 00 02 00 " + XS(typeof(Sample1)) + " 02 00 " + XS("X", RoughType.Int, "Y", RoughType.String) + " 01 00 00 03 00 00 00 00 00 00", XS(result1)); CheckDeserializers(bd => { var w1 = new SampleMerge(); w1.DI.Add(5, 6); w1.LI.Add(44); w1.M = new Sample1 { X = 999, Y = "qqq" }; bd.FromBytes(w1, result1); CollectionAssert.AreEqual(new Dictionary<int, int> { { 5, 6 }, { 3, 4 } }, w1.DI); CollectionAssert.AreEqual(new[] { 44, 33 }, w1.LI); Assert.AreEqual(768, w1.M.X); Assert.AreEqual("qqq", w1.M.Y); }); }