Exemple #1
0
        public static void TestJsonArrayEmptyArrayEnumerator()
        {
            var jsonArray           = new JsonArray();
            var jsonArrayEnumerator = new JsonArrayEnumerator(jsonArray);

            Assert.Null(jsonArrayEnumerator.Current);
            Assert.False(jsonArrayEnumerator.MoveNext());
        }
Exemple #2
0
        public static void TestJsonArrayIEnumerator()
        {
            var jsonArray = new JsonArray()
            {
                1, "value"
            };

            // Test generic IEnumerator:
            IEnumerator <JsonNode> jsonArrayEnumerator = new JsonArrayEnumerator(jsonArray);

            Assert.Null(jsonArrayEnumerator.Current);

            Assert.True(jsonArrayEnumerator.MoveNext());
            Assert.Equal(1, jsonArrayEnumerator.Current);
            Assert.True(jsonArrayEnumerator.MoveNext());
            Assert.Equal("value", jsonArrayEnumerator.Current);
            Assert.False(jsonArrayEnumerator.MoveNext());

            jsonArrayEnumerator.Reset();

            Assert.True(jsonArrayEnumerator.MoveNext());
            Assert.Equal(1, jsonArrayEnumerator.Current);
            Assert.True(jsonArrayEnumerator.MoveNext());
            Assert.Equal("value", jsonArrayEnumerator.Current);

            // Test non-generic IEnumerator:
            IEnumerator jsonArrayEnumerator2 = new JsonArrayEnumerator(jsonArray);

            Assert.Null(jsonArrayEnumerator2.Current);

            jsonArrayEnumerator2.MoveNext();
            Assert.Equal((JsonNumber)1, jsonArrayEnumerator2.Current);
            Assert.True(jsonArrayEnumerator2.MoveNext());
            Assert.Equal((JsonString)"value", jsonArrayEnumerator2.Current);
            Assert.False(jsonArrayEnumerator2.MoveNext());

            jsonArrayEnumerator2.Reset();

            Assert.True(jsonArrayEnumerator2.MoveNext());
            Assert.Equal((JsonNumber)1, jsonArrayEnumerator2.Current);
            Assert.True(jsonArrayEnumerator2.MoveNext());
            Assert.Equal((JsonString)"value", jsonArrayEnumerator2.Current);
            Assert.False(jsonArrayEnumerator2.MoveNext());
        }