Пример #1
0
    public void ReadAsDecimalFailure()
    {
      ExceptionAssert.Throws<JsonSchemaException>("Float 5.5 is not evenly divisible by 1. Line 1, position 3.",
      () =>
      {
        JsonSchema s = new JsonSchemaGenerator().Generate(typeof(decimal));
        s.DivisibleBy = 1;

        JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5.5")))
        {
          Schema = s
        };
        reader.ReadAsDecimal();
      });
    }
Пример #2
0
    public void ReadAsDecimal()
    {
      JsonSchema s = new JsonSchemaGenerator().Generate(typeof (decimal));

      JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1.5")))
        {
          Schema = s
        };
      decimal? d = reader.ReadAsDecimal();

      Assert.AreEqual(1.5m, d);
    }
Пример #3
0
    public void ReadAsInt32()
    {
      JsonSchema s = new JsonSchemaGenerator().Generate(typeof (int));

      JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"1")))
        {
          Schema = s
        };
      int? i = reader.ReadAsInt32();

      Assert.AreEqual(1, i);
    }
Пример #4
0
    public void ReadAsInt32Failure()
    {
      ExceptionAssert.Throws<JsonSchemaException>("Integer 5 exceeds maximum value of 2. Line 1, position 1.",
      () =>
      {
        JsonSchema s = new JsonSchemaGenerator().Generate(typeof(int));
        s.Maximum = 2;

        JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"5")))
        {
          Schema = s
        };
        reader.ReadAsInt32();
      });
    }
Пример #5
0
    public void ReadAsBytes()
    {
      JsonSchema s = new JsonSchemaGenerator().Generate(typeof (byte[]));

      byte[] data = Encoding.UTF8.GetBytes("Hello world");

      JsonReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(@"""" + Convert.ToBase64String(data) + @"""")))
        {
          Schema = s
        };
      byte[] bytes = reader.ReadAsBytes();

      CollectionAssert.AreEquivalent(data, bytes);
    }