public static void TestArrayIterator()
        {
            JsonArray array = new JsonArray {
                1, 2, 3
            };
            JsonElement jsonNodeElement = array.AsJsonElement();
            IEnumerator enumerator      = jsonNodeElement.EnumerateArray();

            array.Add(4);
            Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext());
        }
Пример #2
0
        public static void TestArray()
        {
            var jsonArray = new JsonArray()
            {
                1, 2, 3
            };
            JsonElement jsonArrayElement = jsonArray.AsJsonElement();

            Assert.Equal(2, jsonArrayElement[1].GetInt32());
            Assert.Equal(3, jsonArrayElement.GetArrayLength());

            var         notJsonArray        = new JsonString();
            JsonElement notJsonArrayElement = notJsonArray.AsJsonElement();

            Assert.Throws <InvalidOperationException>(() => notJsonArrayElement[1]);
            Assert.Throws <InvalidOperationException>(() => notJsonArrayElement.GetArrayLength());
        }
Пример #3
0
        public static void TestArrayEnumerator()
        {
            var jsonArray = new JsonArray()
            {
                1, 2, 3
            };
            JsonElement jsonArrayElement = jsonArray.AsJsonElement();

            JsonElement.ArrayEnumerator arrayEnumerator = jsonArrayElement.EnumerateArray();

            for (int i = 1; i <= 3; i++)
            {
                Assert.True(arrayEnumerator.MoveNext());
                Assert.Equal(i, arrayEnumerator.Current.GetInt32());
            }

            Assert.False(arrayEnumerator.MoveNext());
            Assert.False(arrayEnumerator.MoveNext());

            JsonElement notArray = new JsonObject().AsJsonElement();

            Assert.Throws <InvalidOperationException>(() => notArray.EnumerateArray());
        }