Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }