Example #1
0
        public void Fill_Test_FillErrorTest()
        {
            string query = "select type_int from numeric_family where id=1 or id=4 ";

            DataSet   ds    = new DataSet();
            DataTable table = ds.Tables.Add("test");

            table.Columns.Add("col", typeof(short));

            adapter = new SqlDataAdapter(query, connectionString);
            DataTableMapping mapping = adapter.TableMappings.Add("numeric_family", "test");

            mapping.ColumnMappings.Add("type_int", "col");

            try {
                adapter.Fill(ds, "numeric_family");
                Assert.Fail("#A1");
            } catch (OverflowException) {
            } catch (ArgumentException ex) {
                // System.OverflowException: Value was either too large or too
                // small for an Int16
                Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#A2");
#if NET_2_0
                Assert.IsNotNull(ex.InnerException, "#A3");
#else
                Assert.IsNull(ex.InnerException, "#A3");
#endif
                Assert.IsNotNull(ex.Message, "#A4");
                Assert.IsNull(ex.ParamName, "#A5");

#if NET_2_0
                OverflowException inner = ex.InnerException as OverflowException;
                Assert.IsNotNull(inner, "#A6");
                Assert.AreEqual(typeof(OverflowException), inner.GetType(), "#A7");
                Assert.IsNull(inner.InnerException, "#A8");
                Assert.IsNotNull(inner.Message, "#A9");
#endif
            }
            Assert.AreEqual(0, ds.Tables [0].Rows.Count, "#A10");

            adapter.FillError += new FillErrorEventHandler(ErrorHandler);
            FillErrorContinue  = false;
            try {
                adapter.Fill(ds, "numeric_family");
                Assert.Fail("#B1");
            } catch (OverflowException) {
            } catch (ArgumentException ex) {
                // System.OverflowException: Value was either too large or too
                // small for an Int16
                Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#B2");
#if NET_2_0
                Assert.IsNotNull(ex.InnerException, "#B3");
#else
                Assert.IsNull(ex.InnerException, "#B3");
#endif
                Assert.IsNotNull(ex.Message, "#B4");
                Assert.IsNull(ex.ParamName, "#B5");

#if NET_2_0
                OverflowException inner = ex.InnerException as OverflowException;
                Assert.IsNotNull(inner, "#B6");
                Assert.AreEqual(typeof(OverflowException), inner.GetType(), "#B7");
                Assert.IsNull(inner.InnerException, "#B8");
                Assert.IsNotNull(inner.Message, "#B9");
#endif
            }
            Assert.AreEqual(0, ds.Tables [0].Rows.Count, "#B10");

            FillErrorContinue = true;
            int count = adapter.Fill(ds, "numeric_family");
            Assert.AreEqual(1, ds.Tables [0].Rows.Count, "#C1");
            Assert.AreEqual(1, count, "#C2");
        }