public async Task ReadAsBytes_CommaErrorsAsync()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader("[,'']"));
            await reader.ReadAsync();

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() =>
            {
                await reader.ReadAsBytesAsync();
            }, "Unexpected character encountered while parsing value: ,. Path '[0]', line 1, position 2.");

            CollectionAssert.AreEquivalent(new byte[0], await reader.ReadAsBytesAsync());
            Assert.IsTrue(await reader.ReadAsync());
        }
        public async Task ReadAsBytes_MissingCommaAsync()
        {
            byte[] data = Encoding.UTF8.GetBytes("Hello world");

            string         json   = @"['" + Convert.ToBase64String(data) + "' '" + Convert.ToBase64String(data) + @"']";
            JsonTextReader reader = new JsonTextReader(new StringReader(json));

            Assert.IsTrue(await reader.ReadAsync());
            CollectionAssert.AreEquivalent(data, await reader.ReadAsBytesAsync());

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(
                () => reader.ReadAsBytesAsync(),
                "After parsing a value an unexpected character was encountered: '. Path '[0]', line 1, position 20.");
        }
        public async Task ReadBytesWithErrorAsync()
        {
            string json = @"{
    ChildId: '123'
}";

            JsonTextReader jsonTextReader = new JsonTextReader(new StringReader(json));

            Assert.IsTrue(await jsonTextReader.ReadAsync());
            Assert.AreEqual(JsonToken.StartObject, jsonTextReader.TokenType);

            Assert.IsTrue(await jsonTextReader.ReadAsync());
            Assert.AreEqual(JsonToken.PropertyName, jsonTextReader.TokenType);

            try
            {
                await jsonTextReader.ReadAsBytesAsync();
            }
            catch (FormatException)
            {
            }

            Assert.IsTrue(await jsonTextReader.ReadAsync());
            Assert.AreEqual(JsonToken.EndObject, jsonTextReader.TokenType);

            Assert.IsFalse(await jsonTextReader.ReadAsync());
        }
        public async Task ReadAsBytes_InvalidEndArrayAsync()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader("]"));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() =>
            {
                await reader.ReadAsBytesAsync();
            }, "Unexpected character encountered while parsing value: ]. Path '', line 1, position 1.");
        }
        public async Task ReadBytesWithUnexpectedEndAsync()
        {
            string helloWorld = "Hello world!";

            byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);

            JsonReader reader = new JsonTextReader(new StringReader(@"'" + Convert.ToBase64String(helloWorldData)));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Unterminated string. Expected delimiter: '. Path '', line 1, position 17.");
        }
        public async Task ReadBytesWithBadCharacterAsync()
        {
            JsonReader reader = new JsonTextReader(new StringReader(@"true"));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Unexpected character encountered while parsing value: t. Path '', line 1, position 1.");
        }
        public async Task ReadAsBytesBadContentAsync()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader(@"new Date()"));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Unexpected character encountered while parsing value: e. Path '', line 1, position 2.");
        }
        public async Task ReadAsBytesArrayWithBadContentAsync()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader(@"[1.0]"));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Unexpected token when reading bytes: Float. Path '[0]', line 1, position 4.");
        }
        public async Task ReadAsBytesIntegerArrayWithNoEndAsync()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader(@"[1"));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Unexpected end when reading bytes. Path '[0]', line 1, position 2.");
        }
        public async Task ReadAsBytes_BadDataAsync()
        {
            string json = @"pie";

            JsonTextReader reader = new JsonTextReader(new StringReader(json));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Unexpected character encountered while parsing value: p. Path '', line 1, position 1.");
        }
        public async Task ReadBytesEmptyWrappedObjectAsync()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader(@"{}"));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Error reading bytes. Unexpected token: StartObject. Path '', line 1, position 2.");
        }
        public async Task ReadAsBytesNoContentWrappedObjectAsync()
        {
            JsonTextReader reader = new JsonTextReader(new StringReader(@"{"));

            await ExceptionAssert.ThrowsAsync <JsonReaderException>(async() => { await reader.ReadAsBytesAsync(); }, "Unexpected end when reading JSON. Path '', line 1, position 1.");
        }