public static void When_read_empty_array(string json) { // Read using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { var actual = jr.ReadArray(() => (int)jr.Value); Assert.Empty(actual); } // Enumerate using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { var actual = jr.EnumerateArray(() => (int)jr.Value); Assert.Empty(actual); } // Process using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { var actualCount = 0; jr.ProcessArray(() => actualCount++); Assert.Equal(0, actualCount); } }
public static void When_read_simple_array() { // Read using (var tr = new StringReader(jsonArray)) using (var jr = new JsonTextReader(tr)) { var actual = jr.ReadArray(() => jr.Value); Assert.Collection(actual, n => Assert.Equal("joe", n), n => Assert.Null(n), n => Assert.Equal(string.Empty, n), n => Assert.True((bool)n), n => Assert.Equal(99L, n)); } // Enumerate using (var tr = new StringReader(jsonArray)) using (var jr = new JsonTextReader(tr)) { var actual = jr.EnumerateArray(() => jr.Value); Assert.Collection(actual, n => Assert.Equal("joe", n), n => Assert.Null(n), n => Assert.Equal(string.Empty, n), n => Assert.True((bool)n), n => Assert.Equal(99L, n)); } // Process using (var tr = new StringReader(jsonArray)) using (var jr = new JsonTextReader(tr)) { var actual = new List <object>(); jr.ProcessArray(() => actual.Add(jr.Value)); Assert.Collection(actual, n => Assert.Equal("joe", n), n => Assert.Null(n), n => Assert.Equal(string.Empty, n), n => Assert.True((bool)n), n => Assert.Equal(99L, n)); } }
public static void When_read_null_array(string json) { // Read using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { var actual = jr.ReadArray(() => (string)jr.Value); Assert.Equal(new string[] { null }, actual); } // Enumerate using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { var actual = jr.EnumerateArray(() => (string)jr.Value); Assert.Equal(new string[] { null }, actual); } // Process using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { var actual = new List <string>(); jr.ProcessArray(() => actual.Add((string)jr.Value)); Assert.Equal(new string[] { null }, actual); } }
public static void When_read_empty_array(string json) { // Read using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { IReadOnlyList <int> actual = jr.ReadArray(() => (int)jr.Value); Assert.Empty(actual); } // Enumerate using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { IEnumerable <int> actual = jr.EnumerateArray(() => (int)jr.Value); Assert.Empty(actual); } // Process using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { int actualCount = 0; jr.ReadArray(() => actualCount++); Assert.Equal(0, actualCount); } // Skip using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { int actualCount = jr.SkipCountArray(); Assert.True(jr.TokenType == JsonToken.EndArray); Assert.Equal(0, actualCount); } }
public static void When_read_simple_array() { // Read using (var tr = new StringReader(JsonArray)) using (var jr = new JsonTextReader(tr)) { IReadOnlyList <object> actual = jr.ReadArray(() => jr.Value); Assert.Collection(actual, n => Assert.Equal("joe", n), n => Assert.Null(n), n => Assert.Equal(string.Empty, n), n => Assert.True((bool)n), n => Assert.Equal(99L, n)); } // Enumerate using (var tr = new StringReader(JsonArray)) using (var jr = new JsonTextReader(tr)) { IEnumerable <object> actual = jr.EnumerateArray(() => jr.Value); Assert.Collection(actual, n => Assert.Equal("joe", n), n => Assert.Null(n), n => Assert.Equal(string.Empty, n), n => Assert.True((bool)n), n => Assert.Equal(99L, n)); } // Process using (var tr = new StringReader(JsonArray)) using (var jr = new JsonTextReader(tr)) { var actual = new List <object>(); jr.ReadArray(() => actual.Add(jr.Value)); Assert.Collection(actual, n => Assert.Equal("joe", n), n => Assert.Null(n), n => Assert.Equal(string.Empty, n), n => Assert.True((bool)n), n => Assert.Equal(99L, n)); } // Skip using (var tr = new StringReader(JsonArray)) using (var jr = new JsonTextReader(tr)) { int actualCount = jr.SkipCountArray(); Assert.True(jr.TokenType == JsonToken.EndArray); Assert.Equal(5, actualCount); } }
public static void When_read_null_array(string json) { // Read using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { IReadOnlyList <string> actual = jr.ReadArray(() => (string)jr.Value); Assert.Equal(new string[] { null }, actual); } // Enumerate using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { IEnumerable <string> actual = jr.EnumerateArray(() => (string)jr.Value); Assert.Equal(new string[] { null }, actual); } // Process using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { var actual = new List <string>(); jr.ReadArray(() => actual.Add((string)jr.Value)); Assert.Equal(new string[] { null }, actual); } // Skip using (var tr = new StringReader(json)) using (var jr = new JsonTextReader(tr)) { int actualCount = jr.SkipCountArray(); Assert.True(jr.TokenType == JsonToken.EndArray); Assert.Equal(1, actualCount); } }