public void RepeatedValue_NullRejectedOnConversion() { var row = new BigQueryInsertRow { { "names", new[] { "a", null, "b" } } }; Assert.Throws <InvalidOperationException>(() => row.ToRowsData()); }
public void RepeatedValue() { var row = new BigQueryInsertRow { { "numbers", new[] { 1, 2 } } }; var rowData = row.ToRowsData(); Assert.Equal(new object[] { 1, 2 }, rowData.Json["numbers"]); }
public void DateTimeFormatting() { var row = new BigQueryInsertRow { { "field", new DateTime(2000, 1, 1, 5, 0, 0, DateTimeKind.Utc) }, }; var rowData = row.ToRowsData(); Assert.Equal("2000-01-01 05:00:00Z", rowData.Json["field"]); }
public void SupportedValueTypes_Passthrough(Type type) { object value = Activator.CreateInstance(type); var row = new BigQueryInsertRow { { "field", value } }; var rowData = row.ToRowsData(); Assert.Equal(value, rowData.Json["field"]); }
public void TimespanFormatting() { var row = new BigQueryInsertRow { { "field", new TimeSpan(1, 2, 3) }, }; var rowData = row.ToRowsData(); Assert.Equal("01:02:03", rowData.Json["field"]); }
public void Numeric_Json() { object value = BigQueryNumeric.Parse("123.456"); var row = new BigQueryInsertRow { { "field", value } }; var rowData = row.ToRowsData(); Assert.Equal("123.456", rowData.Json["field"]); }
public void UnspecifiedDateTimeFormatting() { var row = new BigQueryInsertRow { { "field", new DateTime(2000, 1, 1, 5, 0, 0, DateTimeKind.Unspecified) }, }; var rowData = row.ToRowsData(false); Assert.Equal("2000-01-01T05:00:00", rowData.Json["field"]); }
public void DateTimeOffsetFormatting() { var row = new BigQueryInsertRow { // 3am UTC { "field", new DateTimeOffset(2000, 1, 1, 5, 0, 0, TimeSpan.FromHours(2)) }, }; var rowData = row.ToRowsData(); Assert.Equal("2000-01-01 03:00:00Z", rowData.Json["field"]); }
public void ToRowsData_WithInsertId() { var row = new BigQueryInsertRow("my-id") { { "field1", "value1" }, }; var rowData = row.ToRowsData(); Assert.Equal("value1", rowData.Json["field1"]); Assert.Equal("my-id", rowData.InsertId); }
// Invalid values should be invalid for general insert, but also invalid // in a list at conversion time private void AssertInvalidValueWithListCheck <T>(string name, T value) { AssertInvalid(name, value); var list = new List <T>(); var row = new BigQueryInsertRow { { name, list } }; list.Add(value); Assert.Throws <InvalidOperationException>(() => row.ToRowsData()); }
public void NestedRecordFormatting() { var nested = new BigQueryInsertRow { { "inner", "value" } }; var outer = new BigQueryInsertRow { { "outer", nested } }; var rowData = outer.ToRowsData(); var obj = (IDictionary <string, object>)rowData.Json["outer"]; Assert.Equal("value", obj["inner"]); }
public void SimpleSuccess() { var row = new BigQueryInsertRow { { "field1", "value1" }, { "field2", null } }; Assert.Equal("value1", row["field1"]); row["field3"] = 2; var rowData = row.ToRowsData(); Assert.Equal("value1", rowData.Json["field1"]); Assert.Null(rowData.Json["field2"]); Assert.Equal(2, rowData.Json["field3"]); }
public void ToRowsData_NoSpecifiedInsertId() { var row = new BigQueryInsertRow { { "field1", "value1" }, { "field2", null } }; Assert.Equal("value1", row["field1"]); row["field3"] = 2; var rowData = row.ToRowsData(); Assert.Equal("value1", rowData.Json["field1"]); Assert.Null(rowData.Json["field2"]); Assert.Equal(2, rowData.Json["field3"]); // The insert ID should be populated automatically if not supplied by the user. Assert.NotNull(rowData.InsertId); }
public void ToRowsData_NoSpecifiedInsertId_EmptyInsertIdAllowed() { var row = new BigQueryInsertRow { { "field1", "value1" }, { "field2", null } }; Assert.Equal("value1", row["field1"]); row["field3"] = 2; var rowData = row.ToRowsData(true); Assert.Equal("value1", rowData.Json["field1"]); Assert.Null(rowData.Json["field2"]); Assert.Equal(2, rowData.Json["field3"]); // The insert ID won't be populated automatically. Assert.Null(rowData.InsertId); }