public void LargeArrayBinaryJsonTest() { StringBuilder builder = new StringBuilder((1 << 24) + 50); builder.Append('['); for (int x = 1 << 24; x < (1 << 24) + 3355450; ++x) { builder.Append(x); builder.Append(','); } builder.Append("\"string_one\""); builder.Append(','); builder.Append("\"string_two\""); builder.Append(','); builder.Append("\"string_two\""); builder.Append(']'); string json = builder.ToString(); byte[] binaryJson = JsonTestUtils.ConvertTextToBinary(json); IJsonNavigator navigator = JsonNavigator.Create(binaryJson); int count = navigator.GetArrayItemCount(navigator.GetRootNode()); IJsonNavigatorNode node = navigator.GetArrayItemAt(navigator.GetRootNode(), count - 1); string stringValue = navigator.GetStringValue(node); Assert.AreEqual("string_two", stringValue); }
private static JsonToken[] GetTokensFromArrayNode(IJsonNavigatorNode node, IJsonNavigator navigator, bool performCorrectnessCheck) { // Get tokens once through IEnumerable List <JsonToken> tokensFromIEnumerable = new List <JsonToken>(); IEnumerable <IJsonNavigatorNode> arrayItems = navigator.GetArrayItems(node); tokensFromIEnumerable.Add(JsonToken.ArrayStart()); foreach (IJsonNavigatorNode arrayItem in arrayItems) { tokensFromIEnumerable.AddRange(JsonNavigatorTests.GetTokensFromNode(arrayItem, navigator, performCorrectnessCheck)); } tokensFromIEnumerable.Add(JsonToken.ArrayEnd()); if (performCorrectnessCheck) { // Get tokens once again through indexer List <JsonToken> tokensFromIndexer = new List <JsonToken>(); tokensFromIndexer.Add(JsonToken.ArrayStart()); for (int i = 0; i < navigator.GetArrayItemCount(node); ++i) { tokensFromIndexer.AddRange(JsonNavigatorTests.GetTokensFromNode(navigator.GetArrayItemAt(node, i), navigator, performCorrectnessCheck)); } tokensFromIndexer.Add(JsonToken.ArrayEnd()); Assert.AreEqual(arrayItems.Count(), navigator.GetArrayItemCount(node)); Assert.IsTrue(tokensFromIEnumerable.SequenceEqual(tokensFromIndexer)); try { navigator.GetArrayItemAt(node, navigator.GetArrayItemCount(node) + 1); Assert.Fail("Expected to get an index out of range exception from going one past the end of the array."); } catch (IndexOutOfRangeException) { Assert.AreEqual(navigator.SerializationFormat, JsonSerializationFormat.Binary); } catch (ArgumentOutOfRangeException) { Assert.AreEqual(navigator.SerializationFormat, JsonSerializationFormat.Text); } } return(tokensFromIEnumerable.ToArray()); }