public void ReadBytesNoStartWithUnexpectedEnd()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"[  "));
   Assert.IsTrue(reader.Read());
   reader.ReadAsBytes();
 }
    public void ReadBytesFollowingNumberInObject()
    {
      string helloWorld = "Hello world!";
      byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);

      JsonReader reader = new JsonTextReader(new StringReader(@"{num:1,data:'" + Convert.ToBase64String(helloWorldData) + @"'}"));
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
      Assert.IsTrue(reader.Read());
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);
      Assert.IsTrue(reader.Read());
      byte[] data = reader.ReadAsBytes();
      Assert.AreEqual(helloWorldData, data);
      Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsFalse(reader.Read());
    }
 public void ReadBytesWithBadCharacter()
 {
   JsonReader reader = new JsonTextReader(new StringReader(@"true"));
   reader.ReadAsBytes();
 }
    public void ReadBytesWithUnexpectedEnd()
    {
      string helloWorld = "Hello world!";
      byte[] helloWorldData = Encoding.UTF8.GetBytes(helloWorld);

      JsonReader reader = new JsonTextReader(new StringReader(@"'" + Convert.ToBase64String(helloWorldData)));
      reader.ReadAsBytes();
    }
    public void ReadAsBytesIntegerArrayWithNoEnd()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"[1"));

      reader.ReadAsBytes();
    }
    public void ReadAsBytesArrayWithBadContent()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"[1.0]"));

      reader.ReadAsBytes();
    }
    public void ReadAsBytesIntegerArrayWithComments()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"[/*hi*/1/*hi*/,2/*hi*/]"));

      byte[] data = reader.ReadAsBytes();
      Assert.AreEqual(2, data.Length);
      Assert.AreEqual(1, data[0]);
      Assert.AreEqual(2, data[1]);
    }
    public void ReadAsBytesBadContent()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"new Date()"));

      reader.ReadAsBytes();
    }
    public void ReadAsBytesNoContentWrappedObject()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@"{"));

      reader.ReadAsBytes();
    }
    public void ReadAsBytesNoContent()
    {
      JsonTextReader reader = new JsonTextReader(new StringReader(@""));

      reader.ReadAsBytes();
    }
    public void ReadSingleBytes()
    {
      StringReader s = new StringReader(@"""SGVsbG8gd29ybGQu""");
      JsonTextReader reader = new JsonTextReader(s);

      byte[] data = reader.ReadAsBytes();
      Assert.IsNotNull(data);

      string text = Encoding.UTF8.GetString(data, 0, data.Length);
      Assert.AreEqual("Hello world.", text);
    }