public void ValiationFailsWithEmptyRowName() { var schema = new ResultSetSchema(); var row = new ResultSetRow(); row[" "] = "smith"; // defines use of string.isnulloremptywhitespace var ex = row.Validate(schema); Assert.IsNotNull(ex); Assert.AreSame(typeof(InvalidOperationException), ex.GetType()); Assert.AreEqual("Row contains a value without column name (null/empty)", ex.Message); }
public void CanValidate() { var schema = new ResultSetSchema(); schema.Columns.Add(new Column { Name = "Name", ClrType = typeof(string), DbType = "varchar" }); schema.Columns.Add(new Column { Name = "Age", ClrType = typeof(int), DbType = "int" }); var row = new ResultSetRow(); row["Name"] = "smith"; row["Age"] = 81; Assert.IsNull(row.Validate(schema)); }
public void ValidationFailsWithRowNameThatIsNotInSchema() { var schema = new ResultSetSchema(); schema.Columns.Add(new Column { Name = "Age", ClrType = typeof(int), DbType = "varchar" }); var row = new ResultSetRow(); row["Name"] = "smith"; row["Age"] = 12; var ex = row.Validate(schema); Assert.IsNotNull(ex); Assert.AreSame(typeof(InvalidOperationException), ex.GetType()); Assert.AreEqual("Column 'Name' is not defined in schema", ex.Message); }
public void ValidationFailsWithInvalidSchema() { var schema = new ResultSetSchema(); schema.Columns.Add(new Column { Name = null, ClrType = typeof(string), DbType = "varchar" }); var row = new ResultSetRow(); row["Name"] = "smith"; var ex = row.Validate(schema); Assert.IsNotNull(ex); Assert.AreSame(typeof(InvalidOperationException), ex.GetType()); Assert.AreEqual("Invalid schema", ex.Message); Assert.IsNotNull(ex.InnerException); }
public void ValidationFailsIfRowValueDiffersFromClrTypeDefinedInSchema() { var schema = new ResultSetSchema(); schema.Columns.Add(new Column { Name = "Name", ClrType = typeof(string), DbType = "varchar" }); schema.Columns.Add(new Column { Name = "Age", ClrType = typeof(int), DbType = "int" }); var row = new ResultSetRow(); row["Name"] = "smith"; row["Age"] = "test"; var ex = row.Validate(schema); Assert.IsNotNull(ex); Assert.AreSame(typeof(InvalidOperationException), ex.GetType()); Assert.AreEqual("Value for 'Age' is of type 'System.String' while schema defines type 'System.Int32'", ex.Message); }