public void TestArrayObject() { var js = new JsonGenerator(); Person_Array person_Array = new Person_Array(1, "Jack"); person_Array.AppendCapacity(); person_Array.Children[0] = null; person_Array.AppendCapacity(); person_Array.Children[1] = new Person_Array(2, "Jill"); string[] lines = js.GenerateJson(person_Array, person_Array.GetType().Name).ToString().Split('\n'); Assert.AreEqual("{", lines[0].Trim()); Assert.AreEqual("\"Id\" : 1,", lines[1].Trim()); Assert.AreEqual("\"Name\" : \"Jack\",", lines[2].Trim()); Assert.AreEqual("\"Children\" : [", lines[3].Trim()); Assert.AreEqual("null,", lines[4].Trim()); Assert.AreEqual("{", lines[5].Trim()); Assert.AreEqual("\"Id\" : 2,", lines[6].Trim()); Assert.AreEqual("\"Name\" : \"Jill\",", lines[7].Trim()); Assert.AreEqual("\"Children\" : []", lines[8].Trim()); Assert.AreEqual("}", lines[9].Trim()); Assert.AreEqual("]", lines[10].Trim()); Assert.AreEqual("}", lines[11].Trim()); }
public Person_Array(int id, string name) { Id = id; Name = name; Children = new Person_Array[0]; }