예제 #1
0
    public void ShouldSerializeAsJsonObject() {
      var table = new JsonTable(new[] {"x", "y"});
      Assert.That(table.AsJson(), Is.EqualTo("{\"columns\":[\"x\",\"y\"],\"rows\":[[]]}"));

      table.Add(new JsonArray(new [] {
        new JsonInteger(0), new JsonInteger(1)
      }));
      Assert.That(table.AsJson(),
        Is.EqualTo("{\"columns\":[\"x\",\"y\"],\"rows\":[[0,1]]}"));
    }
예제 #2
0
        public void ShouldSerializeAsJsonObject()
        {
            var table = new JsonTable(new[] { "x", "y" });

            Assert.That(table.AsJson(), Is.EqualTo("{\"columns\":[\"x\",\"y\"],\"rows\":[[]]}"));

            table.Add(new JsonArray(new [] {
                new JsonInteger(0), new JsonInteger(1)
            }));
            Assert.That(table.AsJson(),
                        Is.EqualTo("{\"columns\":[\"x\",\"y\"],\"rows\":[[0,1]]}"));
        }
예제 #3
0
    public void ShouldCountTheNumberOfRows() {
      var table = new JsonTable();
      Assert.That(table.Count, Is.EqualTo(0));

      table = new JsonTable(new[] {"column1", "column2"});
      Assert.That(table.Count, Is.EqualTo(0));

      table = new JsonTable(new[] {"column1", "column2"});
      table.Add(new JsonArray(new [] {
        new JsonString("value"), new JsonString("value"),
      }));

      Assert.That(table.Count, Is.EqualTo(1));
    }
예제 #4
0
        public void ShouldCountTheNumberOfRows()
        {
            var table = new JsonTable();

            Assert.That(table.Count, Is.EqualTo(0));

            table = new JsonTable(new[] { "column1", "column2" });
            Assert.That(table.Count, Is.EqualTo(0));

            table = new JsonTable(new[] { "column1", "column2" });
            table.Add(new JsonArray(new [] {
                new JsonString("value"), new JsonString("value"),
            }));

            Assert.That(table.Count, Is.EqualTo(1));
        }
예제 #5
0
    /// <summary>
    /// Creates a <see cref="JsonTable"/> containing the data readed from
    /// <paramref name="reader"/>.
    /// </summary>
    /// <param name="reader">
    /// A <see cref="IDataReader"/> object that contains the data that will be
    /// used to populate a <see cref="JsonTable"/>.
    /// </param>
    /// <returns>
    /// A <see cref="JsonTable"/> object that contains the data readed from
    /// the <paramref name="reader"/>.
    /// </returns>
    public JsonTable CreateJsonTable(IDataReader reader) {
      if (reader.Read()) {
        IJsonDataField[] json_data_fields = GetJsonDataFields(reader);
        int length = json_data_fields.Length;

        // Get the column names for the json table.
        string[] columns = new string[length];
        for (int i = 0, j = length; i < j; i++) {
          columns[i] = json_data_fields[i].Name;
        }

        JsonTable json_table = new JsonTable(columns);

        // Read the values into a sequence of json arrays and append it to
        // the json table.
        do {
          JsonArray json_array = new JsonArray();
          for (int i = 0, j = length; i < j; i++) {
            IJsonDataField json_data_field = json_data_fields[i];
            json_array.Add(json_data_field.GetValue(reader));
          }
          json_table.Add(json_array);
        } while (reader.Read());
        return json_table;
      }
      return new JsonTable();
    }
예제 #6
0
        public void ShouldAccpetOnlyRowsWithTheSameNumberOfTableColumns()
        {
            var table = new JsonTable(new[] { "x", "y" });

            Assert.That(() => table.Add(new JsonArray()), Throws.ArgumentException);
        }
예제 #7
0
 public void ShouldAccpetOnlyRowsWithTheSameNumberOfTableColumns() {
   var table = new JsonTable(new[] {"x", "y"});
   Assert.That(() => table.Add(new JsonArray()), Throws.ArgumentException);
 }