public void Serializer_CanSerialize_Arrays() { // Array of strings var thing1 = new string[] { "hi", null, "there" }; var thing2 = Crunch <string[]>(thing1); Assert.AreEqual("hi", thing2[0]); Assert.AreEqual(null, thing2[1]); Assert.AreEqual("there", thing2[2]); Assert.AreEqual(3, thing2.Length); // Empty array thing1 = new string[0]; thing2 = Crunch <string[]>(thing1); Assert.AreEqual(0, thing2.Length); // Array of numbers var numberArray1 = new int[] { 2, 4 }; var numberArray2 = Crunch <int[]>(numberArray1); Assert.AreEqual(2, numberArray2[0]); Assert.AreEqual(4, numberArray2[1]); Assert.AreEqual(2, numberArray2.Length); // Array of objects var graphArray1 = new FooGraph[] { new FooGraph("X"), new FooGraph("Y") }; var graphArray2 = Crunch <FooGraph[]>(graphArray1); Assert.AreEqual("X", graphArray2[0].Name); Assert.AreEqual("Y", graphArray2[1].Name); Assert.AreEqual(2, numberArray2.Length); }
public void Serializer_CanSerialize_ObjectsAndGraphs() { var thingA = new FooGraph("A"); var thingB = new FooGraph("B"); var thingC = new FooGraph("C"); thingA.Left = thingB; thingA.Right = thingC; thingA.Left.Right = thingA; thingA.Right.Left = thingA; thingA.Left.Left = thingB; var thing2 = Crunch <FooGraph>(thingA); Assert.AreEqual("A", thing2.Name); Assert.AreEqual("B", thing2.Left.Name); Assert.AreEqual("C", thing2.Right.Name); Assert.AreEqual("A", thing2.Left.Right.Name); Assert.AreEqual("A", thing2.Right.Left.Name); Assert.AreEqual("B", thing2.Left.Left.Name); Assert.AreEqual(null, thing2.Right.Right); Assert.AreSame(thing2, thing2.Left.Right); }