Ejemplo n.º 1
0
        public void GridRowBoundAllowEditInRow()
        {
            //Update The record set, we are updating record set 11
            SqlConnectionUpdate();

            Grid grid = new Grid();
            SetupTestGrid(grid);
            grid.PageSize = 100;
            grid.Culture = new System.Globalization.CultureInfo("en-US");
            grid.RowHighLight = System.Drawing.Color.Azure;
            ((WebGrid.DateTime)grid["dtmDate"]).Format = dateformat;
            grid.RaisePostBackEvent("RecordCancelClick!");
            grid.GridRowBound += grid_GridRowBound;
            grid["intTest"].AllowEditInGrid = true;
            grid["decTest"].AllowEditInGrid = true;
            grid["dtmDate"].AllowEditInGrid = true;
            grid["vchtest"].AllowEditInGrid = true;
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.Greater(grid.MasterTable.Rows.Count, 1);

            // These are triggers from html being rendered.

            string[] triggerStrings = new[]
                                          {
                                               "wggrid_40_vchTest",
                                              "wggrid_40_decTest",
                                              "wggrid_40_intTest",
                                              "wggrid_40_dtmDate",
                                      //        "wggrid_40_dtmDate_trigger",
                                              "cb_wggrid_40_bitFlag",
                                              "wggrid_40_bitFlag",
                                              "onmouseover=\"wgrowhighlight",
                                        //      "calendar.gif",
                                              "wggrid_11_vchTest",
                                              "wggrid_11_decTest",
                                              "wggrid_11_intTest",
                                              "wggrid_11_dtmDate",
                                      //        "wggrid_11_dtmDate_trigger",
                                              "cb_wggrid_11_bitFlag",
                                              "wggrid_11_bitFlag",
                                              //DateTime column with today's DateTime
                                              "value=\""+DateTime.Now.ToString(dateformat)+"\" id=\"wggrid_11_dtmDate\"",
                                              //Test column with 'blah'+ DateTime
                                         //    "maxlength=\"50\"  value=\"blah" +DateTime.Now.ToString(dateformat)+"\" id=\"wggrid_11_vchTest\"",
                                           //Decimal column with value 5634 formatted default "N2"
                                            "style=\"text-align: Right;\" value=\"5,634.00\" id=\"wggrid_11_decTest\"",
                                            //Number column with 33345 formatted default with "N0"
                                            "style=\"text-align: Right;\" value=\"33,345\" id=\"wggrid_11_intTest\""
                                          };

            string content = sb.ToString();
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1,part+Environment.NewLine+content);
            }
        }
Ejemplo n.º 2
0
 public void GridRowBound()
 {
     Grid grid = new Grid();
     SetupTestGrid(grid);
     grid.RaisePostBackEvent("RecordCancelClick!");
     grid.GridRowBound += grid_GridRowBound;
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
     grid.RenderControl(gridwriter);
     Assert.Greater(grid.MasterTable.Rows.Count, 1);
 }
Ejemplo n.º 3
0
        public void CreateAndDeleteRecord()
        {
            CreateRecordSelect();

            int CategoryId = GetCategoryId();

            Grid grid = new Grid();
            Testpage.Controls.Add(grid);
            SetDataSource(grid);
            grid.ID = "test";
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.Standard;
            grid.Width = Unit.Pixel(1000);

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.DataSourceType, DataSourceControlType.AccessDataSource);
            int records = grid.MasterTable.Rows.Count;

            grid = new Grid();
            Testpage.Controls.Add(grid);
            SetDataSource(grid);
            grid.ID = "test";
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.Standard;
            grid.Width = Unit.Pixel(1000);
            grid.RaisePostBackEvent(string.Format("RecordDeleteClick!{0}", CategoryId));

            sb = new StringBuilder();
            sw = new StringWriter(sb);
            gridwriter = new HtmlTextWriter(sw);
            ////grid.ReLoadData = true;
            grid.RenderControl(gridwriter);

             //   Assert.AreEqual(grid.MasterTable.Rows.Count,  GetCategoryCount());
            //   Assert.AreEqual(records-1, grid.MasterTable.Rows.Count);
            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
            Assert.LessOrEqual(grid.SystemMessage.Count, 1);
        }
Ejemplo n.º 4
0
        public void CreateAndDeleteRecord()
        {
            CreateRecord();

            string CategoryId =
                Query.ExecuteScalar("SELECT TOP 1 CategoryID FROM Categories ORDER BY CategoryID DESC",
                                    ConnectionAccessOleDb).ToString();

            Grid grid = new Grid();
            grid.DataSourceId = "Categories";
            grid.ID = "test";
            grid.ConnectionString = ConnectionAccessOleDb;
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            int records = grid.MasterTable.Rows.Count;

            grid = new Grid();
            grid.DataSourceId = "Categories";
            grid.ID = "test";
            grid.ConnectionString = ConnectionAccessOleDb;
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);
            grid.RaisePostBackEvent("RecordDeleteClick!" + CategoryId);

            sb = new StringBuilder();
            sw = new StringWriter(sb);
            gridwriter = new HtmlTextWriter(sw);
            grid.MasterTable.GetData(true);
            grid.RenderControl(gridwriter);

               //     Assert.Less(grid.MasterTable.Rows.Count, records);
            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
        }
Ejemplo n.º 5
0
        public void AllowEditInGrid()
        {
            Grid grid = new Grid();

            SetupGrid(grid);

            grid["CategoryName"].AllowEditInGrid = true;
            grid["Description"].AllowEditInGrid = true;
            grid["CategoryId"].AllowEditInGrid = true;
            grid["CategoryId"].Visibility = Visibility.Both;

            Assert.AreEqual(grid.Mode, Mode.Edit);
            grid.RaisePostBackEvent("RecordCancelClick!");

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.Mode, Mode.Grid);
            Assert.LessOrEqual(grid.SystemMessage.Count, 1);
            Assert.Greater(grid.Rows.Count, 1);
        }
Ejemplo n.º 6
0
        private Grid CreateNewCategory(Grid grid)
        {
            grid.DataSourceId = "Categories";
            grid.ID = "test";
            grid.ConnectionString = ConnectionAccessOleDb;
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);

            grid.RaisePostBackEvent("NewRecordClick!");
            grid.MasterTable.Rows[0]["CategoryName"].Value = "Category name";
            grid.MasterTable.Rows[0]["Description"].Value = string.Format("Unique ID:{0}", DateTime.Now.Ticks);
            return grid;
        }
Ejemplo n.º 7
0
        public void UpdateRecord()
        {
            Grid grid = new Grid();
            grid = CreateNewCategory(grid);
            grid.EditIndex = "6";
            int records = grid.MasterTable.Rows.Count;

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

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            ////grid.ReLoadData = true;
            grid.RenderControl(gridwriter);

            Assert.Greater(grid.MasterTable.Rows.Count, records);
            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
        }
Ejemplo n.º 8
0
 public void OrderBy()
 {
     Grid grid = new Grid();
     grid.DataSourceId = "Categories";
     grid.ID = "test";
     grid.ConnectionString = ConnectionAccessOleDb;
     grid.DefaultVisibility = Visibility.Both;
     grid.RecordsPerRow = 2;
     grid.PagerSettings.PagerType = PagerType.None;
     grid.Width = Unit.Pixel(1000);
     grid.RaisePostBackEvent("ColumnHeaderClick![Categories].[CategoryName]");
     grid.RaisePostBackEvent("ColumnHeaderClick![Categories].[Description]");
     grid.RaisePostBackEvent("ColumnHeaderClick![Categories].[CategoryName]");
     grid.RaisePostBackEvent("ColumnHeaderClick![Categories].[CategoryName]");
     Assert.Greater(grid.MasterTable.Rows.Count, 1);
     Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
     Assert.IsNotEmpty(grid.SortExpression);
 }
Ejemplo n.º 9
0
 public void NewRecordAndCancelRecord()
 {
     Grid grid = new Grid();
     grid.DataSourceId = "Employees";
     grid.ID = "test";
     grid.ConnectionString = ConnectionAccessOleDb;
     grid.DefaultVisibility = Visibility.Both;
     grid.RecordsPerRow = 2;
     grid.PagerSettings.PagerType = PagerType.None;
     grid.Width = Unit.Pixel(1000);
     Assert.Greater(grid.MasterTable.Rows.Count, 1);
     Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
     grid.RaisePostBackEvent("NewRecordClick!");
     Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
     Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
     grid.RaisePostBackEvent("RecordCancelClick!");
     Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
     grid.MasterTable.GetData(false);
     Assert.Greater(grid.MasterTable.Rows.Count, 1);
 }
Ejemplo n.º 10
0
        public void GridUpdateGridRowsClickEvent()
        {
            Grid grid = new Grid();

            grid.DataSourceId = "Categories";
            grid.ID = "test";
            grid.ConnectionString = ConnectionAccessOleDb;
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.Standard;
            grid.Width = Unit.Pixel(1000);

            Assert.IsNull(grid.EditIndex);
            grid.UpdateRowsClick += tmp_UpdateRowsClickEvents;
            grid.BeforeUpdateInsert += tmp_BeforeUpdateInsertUpdateRow;
            grid.RaisePostBackEvent("UpdateRowsClick!");
            grid["CategoryName"].AllowEditInGrid = true;
            grid["Description"].AllowEditInGrid = true;
            grid["CategoryId"].AllowEditInGrid = true;
            grid["CategoryId"].Visibility = Visibility.Both;

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
            Assert.LessOrEqual(grid.SystemMessage.Count, 1);
            Assert.Greater(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(grid.MasterTable.Rows.Count, updaterowseventscount);
            //  foreach (WebGrid.Row row in tmp.MasterTable.Rows)
            //      Console.WriteLine(row["Description"].Value);
            Assert.IsTrue(updaterowsclickevents);
        }
Ejemplo n.º 11
0
        public void GridSearchEvents()
        {
            Grid grid = new Grid();
            grid.SearchChanged += grid_SearchChangedEvents;
            CreateNewCategory(grid);
            grid.Page = Testpage;
            grid.Search = "DoesNotExist";
            grid.RaisePostBackEvent("RecordCancelClick!");

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            ////grid.ReLoadData = true;
            grid.RenderControl(gridwriter);
            grid.Dispose();
            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
            Assert.AreEqual(grid.MasterTable.Rows.Count, 0);
            //Assert.IsTrue(searcheventrunnned);
            // Is not triggered because HttpContext is missing during the test phase.
        }
Ejemplo n.º 12
0
        //[Test]
        public void NewRecordWithDataSourceControl()
        {
            Grid grid = new Grid();
            Testpage.Controls.Add(grid);
            SetDataSource(grid);
            grid.ID = "test";
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);

            Assert.Greater(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
            grid.RaisePostBackEvent("NewRecordClick!");
            Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
        }
Ejemplo n.º 13
0
        public void SelectFromXmlDataSourceEditUpdate()
        {
            Grid grid = new Grid();

            SetupGrid(grid);

            XmlDataSource ds = new XmlDataSource();
            ds.XPath = "//Language//*";
            ds.ID = "test1";
            ds.DataFile = Path + "\\WebGridMessages.xml";
            Testpage.Controls.Add(ds);
            grid.DataSourceId = ds.ID;
            grid["LanguageID"].Primarykey = true;
            grid.EditIndex = "Norwegian";
            grid.DisplayView = DisplayView.Detail;
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            string text = "T:" + DateTime.Now.Ticks;
            grid.Rows[0]["PagerPrefix"].Value = text;
            grid.BeforeUpdateInsert += grid_BeforeUpdateInsert;
            grid.RaisePostBackEvent("RecordUpdateClick!Norwegian!False");
            grid.RenderControl(gridwriter);
            Assert.Greater(grid.Rows.Count, 1, sb.ToString());
            Assert.LessOrEqual(grid.SystemMessage.Count, 1);

            string filecontent = System.IO.File.ReadAllText(Path + "\\WebGridMessages.xml");
            Assert.Greater(filecontent.IndexOf(text), 0);

               /* string[] triggerStrings = new[]
                                          {
                                              "Forrige side",
                                              "RecordCancelClick!Norwegian!",
                                              "RecordUpdateClick!Norwegian!False"
                                          };
            string content = sb.ToString();
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1, part + Environment.NewLine + content);
            }
            */
        }
Ejemplo n.º 14
0
        public void TextColumn()
        {
            Grid grid = new Grid();

            Text column = new Text("column", grid.MasterTable);
            column.Required = true;
            column.Primarykey = true;
            Text column2 = new Text("column2", grid.MasterTable);
            column2.IsEmail = true;

            Text column3 = new Text("column3", grid.MasterTable);
            column3.IsEmail = true;

            Text column4 = new Text("column4", grid.MasterTable);
            column4.IsUrl = true;
            column4.Required = true;

            Text column5 = new Text("column5", grid.MasterTable);
            column.IsPassword = true;

            Text column6 = new Text("column6", grid.MasterTable);
            Text column7 = new Text("column7", grid.MasterTable);
            Text column8 = new Text("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]["column4"].Value = "";
            grid.MasterTable.Rows[0]["column3"].Value = "invalid@email";

            // Allowed Content
            grid.MasterTable.Rows[0]["column2"].Value = "*****@*****.**";
            grid.MasterTable.Rows[0]["column5"].Value = "somepassword";
            grid.MasterTable.Rows[0]["column6"].Value = "<validtext>";
            grid.MasterTable.Rows[0]["column7"].Value = "<%valid text%>";
            grid.MasterTable.Rows[0]["column8"].Value = "valid text";

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

            Assert.AreSame("", grid.MasterTable.Rows[0]["column"].Value.ToString());
            Assert.AreSame("", grid.MasterTable.Rows[0]["column4"].Value.ToString());
            Assert.AreSame("invalid@email", grid.MasterTable.Rows[0]["column3"].Value.ToString());

            Assert.AreEqual(grid.SystemMessage.Count, 3);
        }
Ejemplo n.º 15
0
        private void SetupGrid(Grid grid)
        {
            grid.ID = "wggrid";
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);

            grid.RaisePostBackEvent("NewRecordClick!");
            Testpage.Controls.Add(grid);
        }
Ejemplo n.º 16
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.º 17
0
        public void ManyToMany()
        {
            Testpage.Controls.Clear();
               Grid grid = new Grid();

            ManyToMany column = new ManyToMany("column", grid.MasterTable);
            column.MatrixIdentityColumn = "EmployeeID";
            column.MatrixDataSource = "EmployeeTerritories";
            column.FilterExpression = "RegionID = 3";
            column.ValueColumn = "TerritoryDescription";
            column.ForeignDataSource = "Territories";
            column.ForeignIdentityColumn = "TerritoryID";
            column.RecordsPerRow = 4;
            column.ManyToManyType = ManyToManyType.Checkboxes;

            ManyToMany column2 = new ManyToMany("column2", grid.MasterTable);
            column2.MatrixIdentityColumn = "EmployeeID";
            column2.MatrixDataSource = "EmployeeTerritories";
            column2.FilterExpression = "RegionID = 2";
            column2.ValueColumn = "TerritoryDescription";
            column2.ForeignDataSource = "Territories";
            column2.ForeignIdentityColumn = "TerritoryID";
            column2.ManyToManyType = ManyToManyType.Multiselect;

            grid.MasterTable.Columns.Add(column);
            grid.MasterTable.Columns.Add(column2);

            SetupGrid(grid);
            grid.DisplayView = DisplayView.Detail;
            grid.StayInDetail = true;
            grid.EditIndex = "4";
            grid.DataSourceId = "Employees";
            grid.ConnectionString = ConnectionAccessOleDb;

            grid.RaisePostBackEvent("RecordUpdateClick!!False");
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
            Assert.Greater(column.Items.Count, 1);
            Assert.Greater(column2.Items.Count, 1);
            if (grid.SystemMessage.Count > 2)
                foreach (SystemMessage message in grid.SystemMessage)
                    Console.WriteLine(message.Message);

            //When running bulk tests we get an extra systemmessage because Grid.ID stored in TestPage object.
            Assert.LessOrEqual(grid.SystemMessage.Count, 2); // 15-day license key message
            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);

            string[] triggerStrings = new[]
                                          {
                                              "type=\"checkbox\"",
                                              "id=\"cb_wggrid_4_column_01581\"",
                                          "for=\"cb_wggrid_4_column_01581\"",
                                              "type=\"checkbox\" id=\"cb_wggrid_4_column_55439\""
                                          };
            string content = sb.ToString();
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1, part + Environment.NewLine + content);
            }
        }
Ejemplo n.º 18
0
        public void UpdateRecord()
        {
            Grid grid = new Grid();
            Testpage.Controls.Add(grid);
            grid = SelectAccessCategories(grid);
            grid.CurrentId = "6";
            int records = grid.MasterTable.Rows.Count;

            Assert.AreEqual(grid.Mode, Mode.Edit);
            grid.RaisePostBackEvent("RecordUpdateClick!!False");
            Assert.AreEqual(grid.SystemMessage.Count, 0);

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.ReLoadData = true;
            grid.RenderControl(gridwriter);

            Assert.AreEqual(grid.Mode, Mode.Grid);
            Assert.Greater(grid.MasterTable.Rows.Count, records);
        }
Ejemplo n.º 19
0
        private Grid CreateNewCategorySelect(Grid grid)
        {
            grid.Sql = "SELECT * FROM Categories";
            grid.ID = "test";
            grid.ConnectionString = ConnectionAccessOleDb;
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);

            grid.RaisePostBackEvent("NewRecordClick!");
            grid.MasterTable.Rows[0]["CategoryName"].Value = "Category name";
            grid.MasterTable.Rows[0]["Description"].Value = "test test";
            return grid;
        }
Ejemplo n.º 20
0
        /*
        private Grid SelectObjectDataSourceNorthWind(Grid grid)
        {
            SetObjectDataSource(grid);

            grid.ID = "test";

            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);
            return grid;
        }
        */
        private Grid CreateNewCategorySelect(Grid grid)
        {
            SetDataSource(grid);
            grid.ID = "test";
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);

            grid.RaisePostBackEvent("NewRecordClick!");
            grid.MasterTable.Rows[0]["CategoryName"].Value = "Category name";
            grid.MasterTable.Rows[0]["Description"].Value = "test test";
            return grid;
        }
Ejemplo n.º 21
0
        public void CheckboxColumn()
        {
            Grid grid = new Grid();

            Checkbox column = new Checkbox("column", grid.MasterTable);
            column.Required = true;
            column.Primarykey = true;
            Checkbox column2 = new Checkbox("column2", grid.MasterTable);
            Checkbox column3 = new Checkbox("column3", grid.MasterTable);
            Checkbox column4 = new Checkbox("column4", grid.MasterTable);

            grid.MasterTable.Columns.Add(column);
            grid.MasterTable.Columns.Add(column2);
            grid.MasterTable.Columns.Add(column3);
            grid.MasterTable.Columns.Add(column4);

            SetupGrid(grid);

            // Not allowed content
            grid.MasterTable.Rows[0]["column"].Value = "1";
            grid.MasterTable.Rows[0]["column2"].Value = "sdf30";
            grid.MasterTable.Rows[0]["column3"].Value = "TRUE";
            grid.MasterTable.Rows[0]["column4"].Value = "";

            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
            grid.RaisePostBackEvent("RecordUpdateClick!!False");
            Assert.AreEqual(grid.SystemMessage.Count, 0);
        }
Ejemplo n.º 22
0
        public void GridUpdateGridRowsClick()
        {
            Grid grid = new Grid();

            grid.DataSourceId = "Categories";
            grid.ID = "test";
            grid.ConnectionString = ConnectionAccessOleDb;
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PageSize = 34;
            grid.PagerSettings.PagerType = PagerType.Standard;
            grid.Width = Unit.Pixel(1000);

            Assert.IsNull(grid.EditIndex);
            grid["CategoryName"].AllowEditInGrid = true;
            grid["Description"].AllowEditInGrid = true;
            grid["CategoryId"].AllowEditInGrid = true;
            grid["CategoryId"].Primarykey = true;
            grid["CategoryId"].Visibility = Visibility.Both;
            grid["Description"].MaxSize = 10;

               grid.Rows[0]["Description"].Value = "bla bla bla blah";
            int loadData = grid.Rows.Count;
            grid.RaisePostBackEvent("UpdateRowsClick!");

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
            Assert.LessOrEqual(grid.SystemMessage.Count, 2);
               // Assert.AreEqual("Value must be at least 10 characters.", grid.SystemMessage[0].Message);
            Assert.Greater(grid.MasterTable.Rows.Count, 1);
            Assert.AreEqual(grid.MasterTable.Rows.Count, loadData);
            Assert.AreEqual(34, loadData);
        }
Ejemplo n.º 23
0
        public void SelectFromXmlDataSourceEdit()
        {
            Grid grid = new Grid();

            SetupGrid(grid);

            XmlDataSource ds = new XmlDataSource();
            ds.XPath = "//Language//*";
            ds.ID = "test1";
            ds.DataFile = Path + "\\WebGridMessages.xml";
            Testpage.Controls.Add(ds);
            grid.DataSourceId = ds.ID;
            grid["LanguageID"].Primarykey = true;
            grid.RaisePostBackEvent("RecordClick!!Norwegian");

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.Rows.Count, 1);
            Assert.LessOrEqual(grid.SystemMessage.Count, 1);

            string[] triggerStrings = new[]
                                          {
                                              "Forrige side",
                                              "RecordCancelClick!Norwegian!",
                                              "RecordUpdateClick!Norwegian!False"
                                          };
            string content = sb.ToString();
            foreach (string part in triggerStrings)
            {
                int res = content.IndexOf(part);
                Assert.Greater(res, -1, part + Environment.NewLine + content);
            }
        }
Ejemplo n.º 24
0
        public void DateColumn()
        {
            Grid grid = new Grid();

            DateTime column = new DateTime("column", grid.MasterTable);
            column.Required = true;
            column.Primarykey = true;
            DateTime column2 = new DateTime("column2", grid.MasterTable);
            DateTime column3 = new DateTime("column3", grid.MasterTable);
            DateTime column4 = new DateTime("column4", grid.MasterTable);

            DateTime column5 = new DateTime("column5", grid.MasterTable);
            column5.Format = "dd.MM.yyyy";
            DateTime column6 = new DateTime("column6", grid.MasterTable);
            column6.Format = "dd/MM/yyyy";
            DateTime column7 = new DateTime("column7", grid.MasterTable);
            column7.Format = "dd/MM/yy";
            DateTime column8 = new DateTime("column8", grid.MasterTable);
            column8.Format = "MM/dd/yy";
            grid.Culture = new System.Globalization.CultureInfo("nb-NO");
            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 = "mm.YYYY.333";
            grid.MasterTable.Rows[0]["column3"].Value = "35.34.23";
            grid.MasterTable.Rows[0]["column4"].Value = "test test";

            // Allowed Content
            grid.MasterTable.Rows[0]["column5"].Value = "21.12.2007";
            grid.MasterTable.Rows[0]["column6"].Value = "21/12/2007";
            grid.MasterTable.Rows[0]["column7"].Value = "21/12/07";
            grid.MasterTable.Rows[0]["column8"].Value = "12/21/07";

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

            Assert.AreSame("", grid.MasterTable.Rows[0]["column"].Value.ToString());
            Assert.AreSame("mm.YYYY.333", grid.MasterTable.Rows[0]["column2"].Value.ToString());
            Assert.AreSame("35.34.23", grid.MasterTable.Rows[0]["column3"].Value.ToString());
            Assert.AreSame("test test", grid.MasterTable.Rows[0]["column4"].Value.ToString());

            Assert.AreEqual(grid.SystemMessage.Count, 4);
        }
Ejemplo n.º 25
0
        public void UpdateRecordStayInDetail()
        {
            Grid grid = new Grid();
            Testpage.Controls.Clear();
            Testpage.Controls.Add(grid);
            grid = SelectAccessCategories(grid);
            grid.EditIndex = "6";
            grid.StayInDetail = true;
            int records = grid.MasterTable.Rows.Count;

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

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            ////grid.ReLoadData = true;
            grid.RenderControl(gridwriter);

            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
            Assert.AreEqual(grid.MasterTable.Rows.Count, records);
            Assert.AreEqual(grid.SystemMessage.Count, 0);
        }
Ejemplo n.º 26
0
        public void LoadGridWithNamesDictionaryUpdate()
        {
            Dictionary<string, string> names = new Dictionary<string, string>();
            names.Add("Tom", "Tom");
            names.Add("Dick", "Dick");
            names.Add("Harry", "Harry");
            names.Add("Thomas", "Thomas");
            names.Add("Anders", "Anders");
            names.Add("Carl", "Carl");
            names.Add("Trond", "Trond");
            names.Add("Eli", "Eli");
            names.Add("Eva", "Eva");

            Grid grid = new Grid();
            grid.DataSource = names;
            grid.ID = "test";
            grid.DisplayView = WebGrid.Enums.DisplayView.Detail;
            grid.Columns["Key"].Primarykey = true;
            grid.EditIndex = "Trond";
            grid.BeforeUpdateInsert += grid_BeforeUpdateInsert;
            grid.AfterUpdateInsert += grid_AfterUpdateInsert;
            grid.Rows[0]["Value"].Value = "mytest";
            grid.RaisePostBackEvent("RecordUpdateClick!!False");
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.Rows["Trond"]["Value"].Value, "mytest");
            Assert.AreEqual(grid.MasterTable.Rows.Count, names.Count);
        }
Ejemplo n.º 27
0
        private Grid SelectAccessCategories(Grid grid)
        {
            SetDataSource(grid);

            grid.ID = "test";
            Testpage.Controls.Add(grid);
            grid.ConnectionString = ConnectionAccessOleDb;
            grid.DefaultVisibility = Visibility.Both;
            grid.RecordsPerRow = 2;
            grid.PagerSettings.PagerType = PagerType.None;
            grid.Width = Unit.Pixel(1000);
            grid["CategoryID"].Primarykey = true;
            grid["CategoryID"].Identity = true;
            grid["CategoryID"].IsInDataSource = true;
            grid.RaisePostBackEvent("NewRecordClick!");

            grid.MasterTable.Rows[0]["CategoryName"].Value = "Category name";
            grid.MasterTable.Rows[0]["Description"].Value = "Unique ID:" + DateTime.Now.Ticks;
            return grid;
        }
Ejemplo n.º 28
0
        public void CreateRecordFieldRequired()
        {
            Grid grid = new Grid();
            grid["CategoryName"].Required = true;
            grid = CreateNewCategory(grid);
            grid["CategoryName"].Required = true;
            grid.MasterTable.Rows[0]["CategoryName"].Value = "";
            int records = grid.MasterTable.Rows.Count;

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

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.MasterTable.GotData = false;
            grid.RenderControl(gridwriter);
            Assert.AreEqual(grid.MasterTable.Rows.Count, records);
            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
        }
Ejemplo n.º 29
0
        public void CreateRecordSelect()
        {
            Grid grid = new Grid();
            Testpage.Controls.Add(grid);
            grid = CreateNewCategorySelect(grid);
            grid["CategoryID"].Visibility = Visibility.None;
            int records = grid.MasterTable.Rows.Count;

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

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            ////grid.ReLoadData = true;
            grid.RenderControl(gridwriter);
            Assert.Greater(grid.MasterTable.Rows.Count, records);

            Assert.AreEqual(grid.DisplayView, DisplayView.Grid);
        }
Ejemplo n.º 30
0
        public void CreateRecordSelectFieldRequired()
        {
            Grid grid = new Grid();
            grid["CategoryName"].Required = true;
            grid = CreateNewCategorySelect(grid);
            grid["CategoryName"].Required = true;
            grid.MasterTable.Rows[0]["CategoryName"].Value = "";
            int records = grid.MasterTable.Rows.Count;

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

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter gridwriter = new HtmlTextWriter(sw);
            grid.MasterTable.GotData = false;
            bool res = grid.MasterTable.GotCache;
            grid.RenderControl(gridwriter);
            //Cache is not loaded because we don't have a httpcontext.
            Assert.AreEqual(res, false);
            Assert.AreEqual(grid.MasterTable.Rows.Count, records);
            Assert.AreEqual(grid.DisplayView, DisplayView.Detail);
        }