| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- //
- // Tests for System.Web.UI.WebControls.Style.cs
- //
- // Author:
- // Peter Dennis Bartok ([email protected])
- //
- //
- // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using NUnit.Framework;
- using System;
- using System.Collections;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Globalization;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace MonoTests.System.Web.UI.WebControls
- {
-
-
- [TestFixture]
- public class EditCommandColumnTest {
- private class DataGridTest : DataGrid {
- public ArrayList CreateColumns (PagedDataSource data_source, bool use_data_source) {
- return CreateColumnSet (data_source, use_data_source);
- }
- public void CreateControls (bool use_data_source) {
- CreateControlHierarchy (use_data_source);
- }
- }
-
- [Test]
- public void Defaults ()
- {
- EditCommandColumn e;
- e = new EditCommandColumn();
- Assert.AreEqual(ButtonColumnType.LinkButton, e.ButtonType, "D1");
- Assert.AreEqual(string.Empty, e.CancelText, "D2");
- Assert.AreEqual(string.Empty, e.EditText, "D3");
- Assert.AreEqual(string.Empty, e.UpdateText, "D4");
- }
- [Test]
- public void Properties () {
- EditCommandColumn e;
- e = new EditCommandColumn();
- e.ButtonType = ButtonColumnType.PushButton;
- Assert.AreEqual(ButtonColumnType.PushButton, e.ButtonType, "P1");
- e.CancelText = "Cancel this!";
- Assert.AreEqual("Cancel this!", e.CancelText, "D2");
- e.EditText = "Edit me good";
- Assert.AreEqual("Edit me good", e.EditText, "D3");
- e.UpdateText = "Update? What update?";
- Assert.AreEqual("Update? What update?", e.UpdateText, "D4");
- }
- private string ControlMarkup(Control c) {
- StringWriter sw = new StringWriter ();
- HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
- c.RenderControl (tw);
- return sw.ToString ();
- }
- private void ShowControlsRecursive (Control c, int depth) {
- StringWriter sw = new StringWriter ();
- HtmlTextWriter tw = new CleanHtmlTextWriter (sw);
- c.RenderControl (tw);
- Console.WriteLine (sw.ToString ());
- Console.WriteLine (c);
- foreach (Control child in c.Controls)
- ShowControlsRecursive (child, depth + 5);
- }
- [Test]
- //[Ignore("Need a DataGrid ID rendering and DataGridColumn checked in")]
- public void InitializeCell () {
- DataGridTest p = new DataGridTest ();
- DataTable table = new DataTable ();
- EditCommandColumn e;
- string markup;
- e = new EditCommandColumn();
- e.ButtonType = ButtonColumnType.LinkButton;
- e.CancelText = "Cancel";
- e.EditText = "Edit";
- e.UpdateText = "Update";
- table.Columns.Add (new DataColumn ("one", typeof (string)));
- table.Columns.Add (new DataColumn ("two", typeof (string)));
- table.Columns.Add (new DataColumn ("three", typeof (string)));
- table.Rows.Add (new object [] { "1", "2", "3" });
- p.DataSource = new DataView (table);
- p.Columns.Add(e);
- e = new EditCommandColumn();
- e.ButtonType = ButtonColumnType.PushButton;
- e.CancelText = "Abbrechen";
- e.EditText = "Bearbeiten";
- e.UpdateText = "Refresh";
- p.Columns.Add(e);
- // This will trigger EditCommandColumn.InitializeCell, without any EditItem set, tests the EditText render
- p.CreateControls (true);
- p.ID = "sucker";
- Assert.AreEqual (2, p.Columns.Count, "I1");
- markup = ControlMarkup(p.Controls[0]);
- markup = markup.Replace("\t", "");
- markup = markup.Replace ("\r", "");
- markup = markup.Replace ("\n", "");
- Assert.AreEqual (
- "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
- "</tr><tr><td><a>Edit</a></td><td><input name type=\"submit\" value=\"Bearbeiten\" /></td><td>1</td><td>2</td><td>3</td>" +
- "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
- "</tr></table>", markup, "I2");
- //ShowControlsRecursive (p.Controls [0], 1);
- }
- [Test]
- public void InitializeEditCell () {
- DataGridTest p = new DataGridTest ();
- DataTable table = new DataTable ();
- EditCommandColumn e;
- string markup;
- e = new EditCommandColumn();
- e.ButtonType = ButtonColumnType.LinkButton;
- e.CancelText = "Cancel";
- e.EditText = "Edit";
- e.UpdateText = "Update";
- table.Columns.Add (new DataColumn ("one", typeof (string)));
- table.Columns.Add (new DataColumn ("two", typeof (string)));
- table.Columns.Add (new DataColumn ("three", typeof (string)));
- table.Rows.Add (new object [] { "1", "2", "3" });
- p.DataSource = new DataView (table);
- p.Columns.Add(e);
- e = new EditCommandColumn();
- e.ButtonType = ButtonColumnType.PushButton;
- e.CancelText = "Abbrechen";
- e.EditText = "Bearbeiten";
- e.UpdateText = "Refresh";
- p.Columns.Add(e);
- // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
- p.EditItemIndex = 0;
- // This will trigger EditCommandColumn.InitializeCell
- p.CreateControls (true);
- p.ID = "sucker";
- markup = ControlMarkup (p.Controls[0]);
- markup = markup.Replace ("\t", "");
- markup = markup.Replace ("\r", "");
- markup = markup.Replace ("\n", "");
- //Console.WriteLine("Markup:>{0}<", markup);
- Assert.AreEqual (2, p.Columns.Count, "I1");
- Assert.AreEqual (
- "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
- "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" /> " +
- "<input name type=\"submit\" value=\"Abbrechen\" /></td>" +
- "<td><input name=\"sucker:_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
- "<td><input name=\"sucker:_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
- "<td><input name=\"sucker:_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
- "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
- "</tr></table>", markup, "I2");
- }
- [Test]
- [Ignore("Unfinished")]
- public void InitializeReadOnlyEditCell ()
- {
- DataGridTest p = new DataGridTest ();
- DataTable table = new DataTable ();
- EditCommandColumn e;
- string markup;
- e = new EditCommandColumn ();
- e.ButtonType = ButtonColumnType.LinkButton;
- e.CancelText = "Cancel";
- e.EditText = "Edit";
- e.UpdateText = "Update";
- table.Columns.Add (new DataColumn ("one", typeof (string)));
- table.Columns.Add (new DataColumn ("two", typeof (string)));
- table.Columns.Add (new DataColumn ("three", typeof (string)));
- table.Rows.Add (new object[] { "1", "2", "3" });
- p.DataSource = new DataView (table);
- p.Columns.Add (e);
- e = new EditCommandColumn ();
- e.ButtonType = ButtonColumnType.PushButton;
-
- e.CancelText = "Abbrechen";
- e.EditText = "Bearbeiten";
- e.UpdateText = "Refresh";
- p.Columns.Add (e);
- // Force the ListItemType to be EditItem so we can test rendering the UpdateText/CancelText render
- p.EditItemIndex = 0;
- // This will trigger EditCommandColumn.InitializeCell
- p.CreateControls (true);
- p.ID = "sucker";
- markup = ControlMarkup (p.Controls[0]);
- markup = markup.Replace ("\t", "");
- markup = markup.Replace ("\r", "");
- markup = markup.Replace ("\n", "");
- Console.WriteLine ("Markup:>{0}<", markup);
- Assert.AreEqual (2, p.Columns.Count, "I1");
- Assert.AreEqual (
- "<table border=\"0\" id=\"sucker\"><tr><td> </td><td> </td><td>one</td><td>two</td><td>three</td>" +
- "</tr><tr><td><a>Update</a> <a>Cancel</a></td><td><input name type=\"submit\" value=\"Refresh\" /> " +
- "<input name value=\"Abbrechen\" type=\"submit\" /></td>" +
- "<td><input name=\"_ctl2:_ctl0\" type=\"text\" value=\"1\" /></td>" +
- "<td><input name=\"_ctl2:_ctl1\" type=\"text\" value=\"2\" /></td>" +
- "<td><input name=\"_ctl2:_ctl2\" type=\"text\" value=\"3\" /></td>" +
- "</tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td>" +
- "</tr></table>", markup, "I2");
- }
- }
- }
|