public void TestSerializeItemIf() { TestGen(cl => { var src = new SampleCollection <int> { 5, 2, 4, 1 }; var dst1 = cl.Deep(src); Assert.AreNotEqual(src, dst1); Assert.AreEqual(src.Count, dst1.Count); CollectionAssert.AreEqual(src.ToList(), dst1.ToList()); src.Filter = 1; var dst2 = cl.Deep(src); CollectionAssert.AreEqual(new List <int> { 5, 4 }, dst2.ToList()); src.Filter = 2; var dst3 = cl.Deep(src); CollectionAssert.AreEqual(new List <int> { 2, 4 }, dst3.ToList()); src.Filter = 3; var dst4 = cl.Deep(src); Assert.AreEqual(0, dst4.Count); }); TestGen(cl => { var src = new SampleCollection <Sample1>(); foreach (var i in new List <int> { 5, 2, 4, 1 }) { src.Add(new Sample1 { X = i }); } var dst1 = cl.Deep(src); Assert.AreNotEqual(src, dst1); Assert.AreEqual(src.Count, dst1.Count); foreach (var t in src.Zip(dst1, Tuple.Create)) { Assert.AreEqual(t.Item1.X, t.Item2.X); } src.Filter = 1; var dst2 = cl.Deep(src); Assert.AreEqual(2, dst2.Count); Assert.AreEqual(5, dst2.First().X); Assert.AreEqual(4, dst2.ElementAt(1).X); src.Filter = 3; var dst4 = cl.Deep(src); Assert.AreEqual(0, dst4.Count); }); TestGen(cl => { var src = new SampleWithCollectionMerge(); foreach (var i in new List <int> { 5, 2, 4, 1 }) { src.A.Add(i); } var dst1 = cl.Deep(src); Assert.AreNotEqual(src, dst1); Assert.AreEqual(src.A.Count, dst1.A.Count); CollectionAssert.AreEqual(src.A.ToList(), dst1.A.ToList()); src.A.Filter = 1; var dst2 = cl.Deep(src); CollectionAssert.AreEqual(new List <int> { 5, 4 }, dst2.A.ToList()); src.A.Filter = 2; var dst3 = cl.Deep(src); CollectionAssert.AreEqual(new List <int> { 2, 4 }, dst3.A.ToList()); src.A.Filter = 3; var dst4 = cl.Deep(src); Assert.AreEqual(0, dst4.A.Count); }); }
public SampleWithCollectionDefaultNonSerializable() { B.Add(1); B.Filter = 3; }
public void TestMerge() { TestGen(cl => { var src = new SampleMerge(); src.DI.Add(3, 4); src.LI.Add(33); src.M = new Sample1 { X = 768, Y = "ttt" }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); CollectionAssert.AreEqual(src.DI, dst.DI); CollectionAssert.AreEqual(src.LI, dst.LI); Assert.AreNotEqual(src.M, dst.M); Assert.IsNull(dst.M); }, useBinary: false); TestGen(cl => { cl.Options.Meta = new MetaOptions().AddOverride(typeof(SampleMerge), o => o.AddItem(nameof(SampleMerge.Make), i => i.AddAttr(new YuzuFactory())) ); var src = new SampleMerge(); src.DI.Add(3, 4); src.LI.Add(33); src.M = new Sample1 { X = 768, Y = "ttt" }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); CollectionAssert.AreEqual(src.DI, dst.DI); CollectionAssert.AreEqual(src.LI, dst.LI); Assert.AreNotEqual(src.M, dst.M); // Generated cloner is not affected by meta override. if (cl is ClonerGenBase) { Assert.IsNull(dst.M); } else { Assert.AreEqual(src.M.X, dst.M.X); } }); TestGen(cl => { var src = new SampleMergeNonPrimitive(); src.DI.Add(3, new Sample1 { X = 13 }); src.LI.Add(new Sample1 { X = 14 }); src.M = new Sample1 { X = 15 }; var dst = cl.Deep(src); Assert.AreNotEqual(src, dst); Assert.AreEqual(src.DI.Count, dst.DI.Count); Assert.AreEqual(src.DI[3].X, dst.DI[3].X); Assert.AreEqual(src.LI.Count, dst.LI.Count); Assert.AreEqual(src.LI[0].X, dst.LI[0].X); Assert.AreNotEqual(src.M, dst.M); Assert.AreEqual(src.M.X, dst.M.X); }); TestGen(cl => { var src = new SampleCollection <int>(); src.Add(3); src.Add(4); src.Filter = 1; var dst = new SampleCollection <int>(); dst.Add(5); cl.Merge(dst, src); Assert.AreNotEqual(src, dst); CollectionAssert.AreEqual(new List <int> { 5, 3 }, dst.ToList()); }); }