Exemplo n.º 1
0
        public void AJson_JsonBuilding_CanBuildListFromArrays()
        {
            Json json = JsonHelper.ParseText("[ { StringThing: \"Foo\", IntThing: 1}, { StringThing: \"Bar\", IntThing: 2}]");

            Assert.IsNotNull(json);
            Assert.IsFalse(json.HasErrors, "Json parse errors:\n" + String.Join("\n\t", json.Errors));
            Assert.IsTrue(json.Data.IsArray, "Json should have parsed an array");

            List <StringAndInt> result = JsonHelper.BuildObjectListForJson <StringAndInt>((JsonArray)json.Data);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);
            Assert.IsNotNull(result);

            Assert.AreEqual("Foo", result[0].StringThing);
            Assert.AreEqual(1, result[0].IntThing);

            Assert.AreEqual("Bar", result[1].StringThing);
            Assert.AreEqual(2, result[1].IntThing);
        }