Ejemplo n.º 1
0
        public void GetDataSourceDataTable()
        {
            //Setting up a standard OleDBDataAdapter datasource.
            OleDbConnection myConn = new OleDbConnection(ConnectionAccessOleDb);

            OleDbDataAdapter myCmd = new OleDbDataAdapter("SELECT * FROM [Employees]", myConn);
            DataTable        dt    = new DataTable();

            myCmd.Fill(dt);
            Grid grid = new Grid {
                ID = "test", EditIndex = "3", DisplayView = DisplayView.Detail
            };

            WebGrid.Number column = new WebGrid.Number("EmployeeID", grid.MasterTable)
            {
                Required   = true,
                Primarykey = true
            };
            grid.Columns.Add(column);
            grid.SkinType   = SkinType.Disabled;
            grid.DataSource = dt;
            grid.Culture    = new System.Globalization.CultureInfo("en-US");
            StringBuilder  sb         = new StringBuilder();
            StringWriter   sw         = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);

            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.DataSourceType, DataSourceControlType.EnumerableDataSource);
            Assert.AreEqual(grid.Primarykeys.Count, 1);

            Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(grid.EditIndex, grid.MasterTable.Rows[0].PrimaryKeyValues);

            Assert.Greater(grid.MasterTable.Columns.Count, 1);
            string content = sb.ToString();

            string[] triggerStrings = new[]
            {
                //    "test_3_HireDate_trigger",
                //  "calendar.gif",
                //   "class=\"wgeditfield\"  value=\"Ms.\"",
                "value=\"8/30/1963\"",                               //Us Format
                "ob=true&wgfilenameoption=2&wgfilename=&",
                "class=\"wgupdaterecord\""
            };
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1, part + Environment.NewLine + content);
            }
        }
Ejemplo n.º 2
0
        public void NumberColumn()
        {
            Grid grid = new Grid();

            Number column = new Number("column", grid.MasterTable);

            column.Required   = true;
            column.Primarykey = true;

            Number column2 = new Number("column2", grid.MasterTable);
            Number column3 = new Number("column3", grid.MasterTable);
            Number column4 = new Number("column4", grid.MasterTable);
            Number column5 = new Number("column5", grid.MasterTable);
            Number column6 = new Number("column6", grid.MasterTable);
            Number column7 = new Number("column7", grid.MasterTable);
            Number column8 = new Number("column8", grid.MasterTable);

            grid.MasterTable.Columns.Add(column);
            grid.MasterTable.Columns.Add(column2);
            grid.MasterTable.Columns.Add(column3);
            grid.MasterTable.Columns.Add(column4);
            grid.MasterTable.Columns.Add(column5);
            grid.MasterTable.Columns.Add(column6);
            grid.MasterTable.Columns.Add(column7);
            grid.MasterTable.Columns.Add(column8);

            SetupGrid(grid);

            // Not allowed content
            grid.MasterTable.Rows[0]["column"].Value  = "";
            grid.MasterTable.Rows[0]["column2"].Value = "test";
            grid.MasterTable.Rows[0]["column3"].Value = "<'.3%&#'34,'5>";

            // Allowed Content
            grid.MasterTable.Rows[0]["column4"].Value = "05";
            grid.MasterTable.Rows[0]["column5"].Value = "34";
            grid.MasterTable.Rows[0]["column6"].Value = "1 035 000";
            grid.MasterTable.Rows[0]["column7"].Value = "1 000";
            grid.MasterTable.Rows[0]["column8"].Value = "123 000 000";

            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
            grid.RaisePostBackEvent("RecordUpdateClick!!False");

            Assert.AreSame("", grid.MasterTable.Rows[0]["column"].Value.ToString());
            Assert.AreSame("test", grid.MasterTable.Rows[0]["column2"].Value.ToString());
            Assert.AreSame("<'.3%&#'34,'5>", grid.MasterTable.Rows[0]["column3"].Value.ToString());

            Assert.AreEqual(grid.SystemMessage.Count, 3);
        }
Ejemplo n.º 3
0
        public void NumberColumn()
        {
            Grid grid = new Grid();

            Number column = new Number("column", grid.MasterTable);
            column.Required = true;
            column.Primarykey = true;

            Number column2 = new Number("column2", grid.MasterTable);
            Number column3 = new Number("column3", grid.MasterTable);
            Number column4 = new Number("column4", grid.MasterTable);
            Number column5 = new Number("column5", grid.MasterTable);
            Number column6 = new Number("column6", grid.MasterTable);
            Number column7 = new Number("column7", grid.MasterTable);
            Number column8 = new Number("column8", grid.MasterTable);

            grid.MasterTable.Columns.Add(column);
            grid.MasterTable.Columns.Add(column2);
            grid.MasterTable.Columns.Add(column3);
            grid.MasterTable.Columns.Add(column4);
            grid.MasterTable.Columns.Add(column5);
            grid.MasterTable.Columns.Add(column6);
            grid.MasterTable.Columns.Add(column7);
            grid.MasterTable.Columns.Add(column8);

            SetupGrid(grid);

            // Not allowed content
            grid.MasterTable.Rows[0]["column"].Value = "";
            grid.MasterTable.Rows[0]["column2"].Value = "test";
            grid.MasterTable.Rows[0]["column3"].Value = "<'.3%&#'34,'5>";

            // Allowed Content
            grid.MasterTable.Rows[0]["column4"].Value = "05";
            grid.MasterTable.Rows[0]["column5"].Value = "34";
            grid.MasterTable.Rows[0]["column6"].Value = "1 035 000";
            grid.MasterTable.Rows[0]["column7"].Value = "1 000";
            grid.MasterTable.Rows[0]["column8"].Value = "123 000 000";

            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
            grid.RaisePostBackEvent("RecordUpdateClick!!False");

            Assert.AreSame("", grid.MasterTable.Rows[0]["column"].Value.ToString());
            Assert.AreSame("test", grid.MasterTable.Rows[0]["column2"].Value.ToString());
            Assert.AreSame("<'.3%&#'34,'5>", grid.MasterTable.Rows[0]["column3"].Value.ToString());

            Assert.AreEqual(grid.SystemMessage.Count, 3);
        }
Ejemplo n.º 4
0
        public void GetDataSourceDataTable()
        {
            //Setting up a standard OleDBDataAdapter datasource.
            OleDbConnection myConn = new OleDbConnection(ConnectionAccessOleDb);

            OleDbDataAdapter myCmd = new OleDbDataAdapter("SELECT * FROM [Employees]", myConn);
            DataTable dt = new DataTable();

            myCmd.Fill(dt);
            Grid grid = new Grid {ID = "test", EditIndex = "3", DisplayView = DisplayView.Detail};

            WebGrid.Number column = new WebGrid.Number("EmployeeID", grid.MasterTable)
                                                {
                                                    Required = true,
                                                    Primarykey = true
                                                };
            grid.Columns.Add(column);
            grid.SkinType = SkinType.Disabled;
            grid.DataSource = dt;
            grid.Culture = new System.Globalization.CultureInfo("en-US");
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.DataSourceType, DataSourceControlType.EnumerableDataSource);
            Assert.AreEqual(grid.Primarykeys.Count, 1);

            Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(grid.EditIndex,grid.MasterTable.Rows[0].PrimaryKeyValues);

            Assert.Greater(grid.MasterTable.Columns.Count, 1);
            string content = sb.ToString();
            string[] triggerStrings = new[]
                                          {
                                          //    "test_3_HireDate_trigger",
                                            //  "calendar.gif",
                                           //   "class=\"wgeditfield\"  value=\"Ms.\"",
                                              "value=\"8/30/1963\"", //Us Format
                                              "ob=true&amp;wgfilenameoption=2&amp;wgfilename=&amp;",
                                              "class=\"wgupdaterecord\""
                                          };
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1,part+Environment.NewLine+content);
            }
        }