Beispiel #1
0
        public void CopyTo()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            DataRowView[] drvExpected = null;
            DataRowView[] drvResult   = null;

            // ------- Copy from Index=0
            drvExpected = new DataRowView[dv.Count];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i] = dv[i];
            }

            drvResult = new DataRowView[dv.Count];
            // CopyTo from index 0
            dv.CopyTo(drvResult, 0);
            Assert.Equal(drvResult, drvExpected);

            // ------- Copy from Index=3
            drvExpected = new DataRowView[dv.Count + 3];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 3];
            // CopyTo from index 3
            dv.CopyTo(drvResult, 3);
            Assert.Equal(drvResult, drvExpected);

            // ------- Copy from Index=3,larger array
            drvExpected = new DataRowView[dv.Count + 9];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 9];
            // CopyTo from index 3,larger array
            dv.CopyTo(drvResult, 3);
            Assert.Equal(drvResult, drvExpected);

            // ------- CopyTo smaller array, check exception
            drvResult = new DataRowView[dv.Count - 1];

            // CopyTo smaller array, check exception
            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                dv.CopyTo(drvResult, 0);
            });
        }
Beispiel #2
0
        [Test] public void RowFilter()
        {
            //note: this test does not check all the possible row filter expression. this is done in DataTable.Select method.
            // this test also check DataView.Count property

            DataRowView[] drvResult         = null;
            System.Collections.ArrayList al = new System.Collections.ArrayList();

            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            //-------------------------------------------------------------
            //Get excpected result
            al.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                if ((int)dr["ChildId"] == 1)
                {
                    al.Add(dr);
                }
            }

            // RowFilter = 'ChildId=1', check count
            dv.RowFilter = "ChildId=1";
            Assert.AreEqual(al.Count, dv.Count, "DV70");

            // RowFilter = 'ChildId=1', check rows
            drvResult = new DataRowView[dv.Count];
            dv.CopyTo(drvResult, 0);
            //check that the filterd rows exists
            bool Succeed = true;

            for (int i = 0; i < drvResult.Length; i++)
            {
                Succeed = al.Contains(drvResult[i].Row);
                if (!Succeed)
                {
                    break;
                }
            }
            Assert.AreEqual(true, Succeed, "DV71");
            //-------------------------------------------------------------

            //-------------------------------------------------------------
            //Get excpected result
            al.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1")
                {
                    al.Add(dr);
                }
            }

            // RowFilter - ChildId=1 and String1='1-String1'
            dv.RowFilter = "ChildId=1 and String1='1-String1'";
            Assert.AreEqual(al.Count, dv.Count, "DV72");

            // RowFilter = ChildId=1 and String1='1-String1', check rows
            drvResult = new DataRowView[dv.Count];
            dv.CopyTo(drvResult, 0);
            //check that the filterd rows exists
            Succeed = true;
            for (int i = 0; i < drvResult.Length; i++)
            {
                Succeed = al.Contains(drvResult[i].Row);
                if (!Succeed)
                {
                    break;
                }
            }
            Assert.AreEqual(true, Succeed, "DV73");
            //-------------------------------------------------------------

            //EvaluateException
            // RowFilter - check EvaluateException
            try
            {
                dv.RowFilter = "Col=1";
                Assert.Fail("DV74: RowFilter Failed to throw EvaluateException");
            }
            catch (EvaluateException) {}
            catch (AssertionException exc) { throw  exc; }
            catch (Exception exc)
            {
                Assert.Fail("DV75: RowFilter. Wrong exception type. Got:" + exc);
            }

            //SyntaxErrorException 1
            // RowFilter - check SyntaxErrorException 1
            try
            {
                dv.RowFilter = "sum('something')";
                Assert.Fail("DV76: RowFilter Failed to throw SyntaxErrorException");
            }
            catch (SyntaxErrorException) {}
            catch (AssertionException exc) { throw  exc; }
            catch (Exception exc)
            {
                Assert.Fail("DV77: RowFilter. Wrong exception type. Got:" + exc);
            }

            //SyntaxErrorException 2
            // RowFilter - check SyntaxErrorException 2
            try
            {
                dv.RowFilter = "HH**!";
                Assert.Fail("DV78: RowFilter Failed to throw SyntaxErrorException");
            }
            catch (SyntaxErrorException) {}
            catch (AssertionException exc) { throw  exc; }
            catch (Exception exc)
            {
                Assert.Fail("DV79: RowFilter. Wrong exception type. Got:" + exc);
            }
        }
Beispiel #3
0
        [Test] public void CopyTo()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            DataRowView[] drvExpected = null;
            DataRowView[] drvResult   = null;

            // ------- Copy from Index=0
            drvExpected = new DataRowView[dv.Count];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i] = dv[i];
            }

            drvResult = new DataRowView[dv.Count];
            // CopyTo from index 0
            dv.CopyTo(drvResult, 0);
            Assert.AreEqual(drvResult, drvExpected, "DV27");

            // ------- Copy from Index=3
            drvExpected = new DataRowView[dv.Count + 3];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 3];
            // CopyTo from index 3
            dv.CopyTo(drvResult, 3);
            Assert.AreEqual(drvResult, drvExpected, "DV28");

            // ------- Copy from Index=3,larger array
            drvExpected = new DataRowView[dv.Count + 9];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 9];
            // CopyTo from index 3,larger array
            dv.CopyTo(drvResult, 3);
            Assert.AreEqual(drvResult, drvExpected, "DV29");

            // ------- CopyTo smaller array, check exception
            drvResult = new DataRowView[dv.Count - 1];

            // CopyTo smaller array, check exception
            try
            {
                dv.CopyTo(drvResult, 0);
                Assert.Fail("DV30: CopyTo Failed to throw IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException) {}
            catch (AssertionException exc) { throw  exc; }
            catch (Exception exc)
            {
                Assert.Fail("DV31: CopyTo. Wrong exception type. Got:" + exc);
            }
        }
Beispiel #4
0
        public void RowFilter()
        {
            //note: this test does not check all the possible row filter expression. this is done in DataTable.Select method.
            // this test also check DataView.Count property

            DataRowView[] drvResult = null;
            ArrayList     al        = new ArrayList();

            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            //-------------------------------------------------------------
            //Get excpected result
            al.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                if ((int)dr["ChildId"] == 1)
                {
                    al.Add(dr);
                }
            }

            // RowFilter = 'ChildId=1', check count
            dv.RowFilter = "ChildId=1";
            Assert.Equal(al.Count, dv.Count);

            // RowFilter = 'ChildId=1', check rows
            drvResult = new DataRowView[dv.Count];
            dv.CopyTo(drvResult, 0);
            //check that the filterd rows exists
            bool Succeed = true;

            for (int i = 0; i < drvResult.Length; i++)
            {
                Succeed = al.Contains(drvResult[i].Row);
                if (!Succeed)
                {
                    break;
                }
            }
            Assert.Equal(true, Succeed);
            //-------------------------------------------------------------

            //-------------------------------------------------------------
            //Get excpected result
            al.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1")
                {
                    al.Add(dr);
                }
            }

            // RowFilter - ChildId=1 and String1='1-String1'
            dv.RowFilter = "ChildId=1 and String1='1-String1'";
            Assert.Equal(al.Count, dv.Count);

            // RowFilter = ChildId=1 and String1='1-String1', check rows
            drvResult = new DataRowView[dv.Count];
            dv.CopyTo(drvResult, 0);
            //check that the filterd rows exists
            Succeed = true;
            for (int i = 0; i < drvResult.Length; i++)
            {
                Succeed = al.Contains(drvResult[i].Row);
                if (!Succeed)
                {
                    break;
                }
            }
            Assert.Equal(true, Succeed);
            //-------------------------------------------------------------

            //EvaluateException
            // RowFilter - check EvaluateException
            Assert.Throws <EvaluateException>(() =>
            {
                dv.RowFilter = "Col=1";
            });

            //SyntaxErrorException 1
            // RowFilter - check SyntaxErrorException 1
            Assert.Throws <SyntaxErrorException>(() =>
            {
                dv.RowFilter = "sum('something')";
            });

            //SyntaxErrorException 2
            // RowFilter - check SyntaxErrorException 2
            Assert.Throws <SyntaxErrorException>(() =>
            {
                dv.RowFilter = "HH**!";
            });
        }
Beispiel #5
0
        public void RowFilter()
        {
            //note: this test does not check all the possible row filter expression. this is done in DataTable.Select method.
            // this test also check DataView.Count property

            DataRowView[] drvResult = null;
            ArrayList al = new ArrayList();

            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            //-------------------------------------------------------------
            //Get excpected result 
            al.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                if ((int)dr["ChildId"] == 1)
                {
                    al.Add(dr);
                }
            }

            // RowFilter = 'ChildId=1', check count
            dv.RowFilter = "ChildId=1";
            Assert.Equal(al.Count, dv.Count);

            // RowFilter = 'ChildId=1', check rows
            drvResult = new DataRowView[dv.Count];
            dv.CopyTo(drvResult, 0);
            //check that the filterd rows exists
            bool Succeed = true;
            for (int i = 0; i < drvResult.Length; i++)
            {
                Succeed = al.Contains(drvResult[i].Row);
                if (!Succeed) break;
            }
            Assert.Equal(true, Succeed);
            //-------------------------------------------------------------

            //-------------------------------------------------------------
            //Get excpected result 
            al.Clear();
            foreach (DataRow dr in dt.Rows)
                if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1")
                    al.Add(dr);

            // RowFilter - ChildId=1 and String1='1-String1'
            dv.RowFilter = "ChildId=1 and String1='1-String1'";
            Assert.Equal(al.Count, dv.Count);

            // RowFilter = ChildId=1 and String1='1-String1', check rows
            drvResult = new DataRowView[dv.Count];
            dv.CopyTo(drvResult, 0);
            //check that the filterd rows exists
            Succeed = true;
            for (int i = 0; i < drvResult.Length; i++)
            {
                Succeed = al.Contains(drvResult[i].Row);
                if (!Succeed) break;
            }
            Assert.Equal(true, Succeed);
            //-------------------------------------------------------------

            //EvaluateException
            // RowFilter - check EvaluateException
            Assert.Throws<EvaluateException>(() =>
            {
                dv.RowFilter = "Col=1";
            });

            //SyntaxErrorException 1
            // RowFilter - check SyntaxErrorException 1
            Assert.Throws<SyntaxErrorException>(() =>
            {
                dv.RowFilter = "sum('something')";
            });

            //SyntaxErrorException 2
            // RowFilter - check SyntaxErrorException 2
            Assert.Throws<SyntaxErrorException>(() =>
            {
                dv.RowFilter = "HH**!";
            });
        }
Beispiel #6
0
        public void CopyTo()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            DataRowView[] drvExpected = null;
            DataRowView[] drvResult = null;

            // ------- Copy from Index=0
            drvExpected = new DataRowView[dv.Count];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i] = dv[i];
            }

            drvResult = new DataRowView[dv.Count];
            // CopyTo from index 0
            dv.CopyTo(drvResult, 0);
            Assert.Equal(drvResult, drvExpected);

            // ------- Copy from Index=3
            drvExpected = new DataRowView[dv.Count + 3];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 3];
            // CopyTo from index 3
            dv.CopyTo(drvResult, 3);
            Assert.Equal(drvResult, drvExpected);

            // ------- Copy from Index=3,larger array
            drvExpected = new DataRowView[dv.Count + 9];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 9];
            // CopyTo from index 3,larger array
            dv.CopyTo(drvResult, 3);
            Assert.Equal(drvResult, drvExpected);

            // ------- CopyTo smaller array, check exception
            drvResult = new DataRowView[dv.Count - 1];

            // CopyTo smaller array, check exception
            Assert.Throws<IndexOutOfRangeException>(() =>
            {
                dv.CopyTo(drvResult, 0);
            });
        }
        //Activate This Construntor to log All To Standard output
        //public TestClass():base(true){}

        //Activate this constructor to log Failures to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, false){}


        //Activate this constructor to log All to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, true){}

        //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

        public void run()
        {
            //note: this test does not check all the possible row filter expression. this is done in DataTable.Select method.
            // this test also check DataView.Count property

            Exception exp = null;

            DataRowView[] drvResult         = null;
            System.Collections.ArrayList al = new System.Collections.ArrayList();

            //create the source datatable
            DataTable dt = GHTUtils.DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);


            //-------------------------------------------------------------
            //Get excpected result
            al.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                if ((int)dr["ChildId"] == 1)
                {
                    al.Add(dr);
                }
            }

            try
            {
                BeginCase("RowFilter = 'ChildId=1', check count");
                dv.RowFilter = "ChildId=1";
                Compare(dv.Count, al.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("RowFilter = 'ChildId=1', check rows");
                drvResult = new DataRowView[dv.Count];
                dv.CopyTo(drvResult, 0);
                //check that the filterd rows exists
                bool Succeed = true;
                for (int i = 0; i < drvResult.Length; i++)
                {
                    Succeed = al.Contains(drvResult[i].Row);
                    if (!Succeed)
                    {
                        break;
                    }
                }
                Compare(Succeed, true);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }
            //-------------------------------------------------------------


            //-------------------------------------------------------------
            //Get excpected result
            al.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1")
                {
                    al.Add(dr);
                }
            }

            try
            {
                BeginCase("RowFilter - ChildId=1 and String1='1-String1'");
                dv.RowFilter = "ChildId=1 and String1='1-String1'";
                Compare(dv.Count, al.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("RowFilter = ChildId=1 and String1='1-String1', check rows");
                drvResult = new DataRowView[dv.Count];
                dv.CopyTo(drvResult, 0);
                //check that the filterd rows exists
                bool Succeed = true;
                for (int i = 0; i < drvResult.Length; i++)
                {
                    Succeed = al.Contains(drvResult[i].Row);
                    if (!Succeed)
                    {
                        break;
                    }
                }
                Compare(Succeed, true);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }
            //-------------------------------------------------------------

            //EvaluateException
            try
            {
                BeginCase("RowFilter - check EvaluateException");
                try
                {
                    dv.RowFilter = "Col=1";
                }
                catch (EvaluateException ex)
                {
                    exp = ex;
                }
                Compare(exp.GetType().FullName, typeof(EvaluateException).FullName);
                exp = null;
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            //SyntaxErrorException 1
            try
            {
                BeginCase("RowFilter - check SyntaxErrorException 1");
                try
                {
                    dv.RowFilter = "sum('something')";
                }
                catch (SyntaxErrorException ex)
                {
                    exp = ex;
                }
                Compare(exp.GetType().FullName, typeof(SyntaxErrorException).FullName);
                exp = null;
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            //SyntaxErrorException 2
            try
            {
                BeginCase("RowFilter - check SyntaxErrorException 2");
                try
                {
                    dv.RowFilter = "HH**!";
                }
                catch (SyntaxErrorException ex)
                {
                    exp = ex;
                }
                Compare(exp.GetType().FullName, typeof(SyntaxErrorException).FullName);
                exp = null;
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }
        }
Beispiel #8
0
        //Activate This Construntor to log All To Standard output
        //public TestClass():base(true){}

        //Activate this constructor to log Failures to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, false){}


        //Activate this constructor to log All to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, true){}

        //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

        public void run()
        {
            Exception exp = null;

            //create the source datatable
            DataTable dt = GHTUtils.DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            DataRowView[] drvExpected = null;
            DataRowView[] drvResult   = null;

            // ------- Copy from Index=0
            drvExpected = new DataRowView[dv.Count];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i] = dv[i];
            }

            drvResult = new DataRowView[dv.Count];
            try
            {
                BeginCase("CopyTo from index 0");
                dv.CopyTo(drvResult, 0);
                Compare(drvExpected, drvResult);
            }
            catch (Exception ex)
            {
                exp = ex;
            }
            finally
            {
                EndCase(exp);
                exp = null;
            }

            // ------- Copy from Index=3
            drvExpected = new DataRowView[dv.Count + 3];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 3];
            try
            {
                BeginCase("CopyTo from index 3");
                dv.CopyTo(drvResult, 3);
                Compare(drvExpected, drvResult);
            }
            catch (Exception ex)
            {
                exp = ex;
            }
            finally
            {
                EndCase(exp);
                exp = null;
            }

            // ------- Copy from Index=3,larger array
            drvExpected = new DataRowView[dv.Count + 9];
            for (int i = 0; i < dv.Count; i++)
            {
                drvExpected[i + 3] = dv[i];
            }

            drvResult = new DataRowView[dv.Count + 9];
            try
            {
                BeginCase("CopyTo from index 3,larger array");
                dv.CopyTo(drvResult, 3);
                Compare(drvExpected, drvResult);
            }
            catch (Exception ex)
            {
                exp = ex;
            }
            finally
            {
                EndCase(exp);
                exp = null;
            }

            // ------- CopyTo smaller array, check exception
            drvResult = new DataRowView[dv.Count - 1];

            try
            {
                BeginCase("CopyTo smaller array, check exception");
                try
                {
                    dv.CopyTo(drvResult, 0);
                }
                catch (IndexOutOfRangeException ex)
                {
                    exp = ex;
                }
                Compare(exp.GetType().FullName, typeof(IndexOutOfRangeException).FullName);
                exp = null;
            }
            catch (Exception ex)
            {
                exp = ex;
            }
            finally
            {
                EndCase(exp);
                exp = null;
            }
        }