using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
+using MonoTests.stand_alone.WebHarness;
+using MonoTests.SystemWeb.Framework;
namespace MonoTests.System.Web.UI.WebControls {
{
return TagKey;
}
+
+ public new void OnSelectedIndexChanged (EventArgs e)
+ {
+ base.OnSelectedIndexChanged (e);
+ }
+
+ public new void OnTextChanged (EventArgs e)
+ {
+ base.OnTextChanged (e);
+ }
+
+ public new void VerifyMultiSelect ()
+ {
+ base.VerifyMultiSelect ();
+ }
+
#endif
}
[TestFixture]
- public class ListControlTest {
+ public class ListControlTest
+ {
+ #region help_class_for_addattributetorender
+ class Poker : ListControl
+ {
+ public void TrackState ()
+ {
+ TrackViewState ();
+ }
+
+ public object SaveState ()
+ {
+ return SaveViewState ();
+ }
+
+ public void LoadState (object state)
+ {
+ LoadViewState (state);
+ }
+ public object ViewStateValue (string name)
+ {
+ return ViewState[name];
+ }
+
+
+ public string Render ()
+ {
+ StringWriter sw = new StringWriter ();
+ sw.NewLine = "\n";
+ HtmlTextWriter writer = new HtmlTextWriter (sw);
+ base.Render (writer);
+ return writer.InnerWriter.ToString ();
+ }
+#if NET_2_0
+ ArrayList Databound ()
+ {
+ ArrayList list = new ArrayList ();
+ list.Add (1);
+ list.Add (2);
+ list.Add (3);
+ return list;
+ }
+
+ public HtmlTextWriterTag GetTagKey ()
+ {
+ return TagKey;
+ }
+
+ protected override void AddAttributesToRender (HtmlTextWriter writer)
+ {
+ writer.AddAttribute (HtmlTextWriterAttribute.Type, "MyType");
+ writer.AddAttribute (HtmlTextWriterAttribute.Name, "MyName");
+ writer.AddAttribute (HtmlTextWriterAttribute.Value, "MyValue");
+ base.AddAttributesToRender (writer);
+ }
+
+ protected override void PerformDataBinding (IEnumerable dataSource)
+ {
+ base.PerformDataBinding (Databound());
+ }
+
+ protected override void PerformSelect ()
+ {
+ base.PerformSelect ();
+ SelectedIndex = 0;
+ }
+
+ public new void SetPostDataSelection(int selectedItem)
+ {
+ base.SetPostDataSelection(selectedItem);
+ }
+#endif
+ }
+ #endregion
private Hashtable changed = new Hashtable ();
+ [TestFixtureSetUp]
+ public void SetUp ()
+ {
+ WebTest.CopyResource (GetType (), "ListControlPage.aspx", "ListControlPage.aspx");
+ }
+
[Test]
public void DefaultProperties ()
{
Assert.IsFalse (p.AppendDataBoundItems, "A11");
Assert.AreEqual (p.Text, "", "A12");
Assert.AreEqual (p.GetTagKey(), HtmlTextWriterTag.Select, "A13");
+ Assert.AreEqual (false, p.AppendDataBoundItems, "A14");
+ Assert.AreEqual (false, p.CausesValidation, "A15");
#endif
}
+#if NET_2_0
+
+ [Test]
+ public void AddAttributesToRender ()
+ {
+ Poker p = new Poker ();
+ ListItem foo = new ListItem ("foo");
+ ListItem bar = new ListItem ("bar");
+ p.Items.Add (foo);
+ p.Items.Add (bar);
+#region orig
+ string orig = "<select type=\"MyType\" name=\"MyName\" value=\"MyValue\"><option value=\"foo\">foo</option><option value=\"bar\">bar</option></select>";
+#endregion
+ string html = p.Render ();
+ HtmlDiff.AssertAreEqual(orig,html,"AddAttributesToRender failed");
+ }
+
+ [Test]
+ public void AppendDataBoundItems ()
+ {
+ ListControlPoker p = new ListControlPoker ();
+ ListItem foo = new ListItem ("foo");
+ ListItem bar = new ListItem ("bar");
+ p.Items.Add (foo);
+ p.Items.Add (bar);
+ Assert.AreEqual (2, p.Items.Count, "Before databound");
+ p.AppendDataBoundItems = true; // Not to clear list before databind
+ p.DataSource = Databound ();
+ p.DataBind ();
+ Assert.AreEqual (5, p.Items.Count, "After databound");
+ p.AppendDataBoundItems = false; // To clear list before databind
+ p.DataBind ();
+ Assert.AreEqual (3, p.Items.Count, "Clear list and databound");
+ }
+
+ ArrayList Databound ()
+ {
+ ArrayList list = new ArrayList ();
+ list.Add (1);
+ list.Add (2);
+ list.Add (3);
+ return list;
+ }
+
+ [Test]
+ [Category ("NunitWeb")]
+ public void CausesValidation_ValidationGroup ()
+ {
+ WebTest t = new WebTest ("ListControlPage.aspx");
+ string str = t.Run ();
+ FormRequest fr = new FormRequest (t.Response, "form1");
+ fr.Controls.Add ("__EVENTTARGET");
+ fr.Controls.Add ("__EVENTARGUMENT");
+ fr.Controls.Add ("ListBox1");
+ fr.Controls["__EVENTTARGET"].Value = "ListBox1";
+ fr.Controls["__EVENTARGUMENT"].Value = "";
+ fr.Controls["ListBox1"].Value = "2";
+ t.Request = fr;
+ string html = t.Run ();
+
+ if (html.IndexOf ("Validate_validation_group") == -1)
+ Assert.Fail ("Validate not created");
+ if (html.IndexOf ("MyValidationGroup") == -1)
+ Assert.Fail ("Wrong validation group");
+ }
+
+ [Test]
+ public void OnTextChanged ()
+ {
+ ListControlPoker p = new ListControlPoker ();
+ p.TextChanged += new EventHandler (p_TextChanged);
+ Assert.AreEqual (false, eventTextChanged, "Before");
+ p.OnTextChanged (new EventArgs ());
+ Assert.AreEqual (true, eventTextChanged, "After");
+ }
+
+ bool eventTextChanged;
+ void p_TextChanged (object sender, EventArgs e)
+ {
+ eventTextChanged = true;
+ }
+
+ [Test]
+ public void PerformDataBind_PerformSelect ()
+ {
+ Poker p = new Poker ();
+ p.DataBind ();
+ string html = p.Render ();
+#region #1
+ string orig = @"<select type=""MyType"" name=""MyName"" value=""MyValue"">
+ <option selected=""selected"" value=""1"">1</option>
+ <option value=""2"">2</option>
+ <option value=""3"">3</option>
+ </select>";
+#endregion
+ HtmlDiff.AssertAreEqual (orig, html, "PerformDataBind");
+ }
+
+ [Test]
+ [Category("NotWorking")] //Not implemented
+ public void SetPostDataSelection ()
+ {
+ Poker p = new Poker ();
+ ListItem foo = new ListItem ("foo");
+ ListItem bar = new ListItem ("bar");
+ p.Items.Add (foo);
+ p.Items.Add (bar);
+ p.SetPostDataSelection (1);
+ Assert.AreEqual (1, p.SelectedIndex, "SetPostDataSelection");
+ }
+
+ [Test]
+ public void Text ()
+ {
+ Poker p = new Poker ();
+ ListItem foo = new ListItem ("foo");
+ ListItem bar = new ListItem ("bar");
+ p.Items.Add (foo);
+ p.Items.Add (bar);
+ Assert.AreEqual (string.Empty, p.Text, "Text#1");
+ p.SelectedIndex = 1;
+ Assert.AreEqual ("bar", p.Text, "Text#2");
+ }
+
+ #region HelpListForMultiple
+ class PokerL : ListBox
+ {
+ public PokerL ()
+ {
+ InitializeMyListBox ();
+ }
+ private void InitializeMyListBox ()
+ {
+ // Add items to the ListBox.
+ Items.Add ("A");
+ Items.Add ("C");
+ Items.Add ("E");
+ Items.Add ("F");
+ Items.Add ("G");
+ Items.Add ("D");
+ Items.Add ("B");
+
+ // Set the SelectionMode to select multiple items.
+ SelectionMode = ListSelectionMode.Multiple;
+
+ Items[0].Selected = true;
+ Items[2].Selected = true;
+ }
+
+ public void TrackState ()
+ {
+ TrackViewState ();
+ }
+
+ public object SaveState ()
+ {
+ return SaveViewState ();
+ }
+
+ public void LoadState (object state)
+ {
+ LoadViewState (state);
+ }
+
+ public object ViewStateValue (string name)
+ {
+ return ViewState[name];
+ }
+
+ public string Render ()
+ {
+ StringWriter sw = new StringWriter ();
+ sw.NewLine = "\n";
+ HtmlTextWriter writer = new HtmlTextWriter (sw);
+ base.Render (writer);
+ return writer.InnerWriter.ToString ();
+ }
+ }
+ #endregion
+ [Test]
+ public void Multiple ()
+ {
+ PokerL p = new PokerL ();
+ Assert.AreEqual (true, p.Items[0].Selected, "MultipleSelect#1");
+ Assert.AreEqual (true, p.Items[2].Selected, "MultipleSelect#2");
+ string html = p.Render ();
+ #region origin
+ string orig = @"<select size=""4"" multiple=""multiple"">
+ <option selected=""selected"" value=""A"">A</option>
+ <option value=""C"">C</option>
+ <option selected=""selected"" value=""E"">E</option>
+ <option value=""F"">F</option>
+ <option value=""G"">G</option>
+ <option value=""D"">D</option>
+ <option value=""B"">B</option>
+ </select>";
+ #endregion
+ HtmlDiff.AssertAreEqual (orig, html, "MultipleSelect#3");
+ }
+#endif
+
+
[Test]
public void CleanProperties ()
Assert.AreEqual(null, p.SelectedItem, "SelectedItem");
Assert.AreEqual(-1, p.SelectedIndex, "SelectedIndex");
}
+#if NET_2_0
+ [Test]
+ [Category ("NotWorking")]
+ [ExpectedException (typeof (HttpException))]
+ public void VerifyMultiSelect_Exception ()
+ {
+ ListControlPoker p = new ListControlPoker ();
+ p.VerifyMultiSelect ();
+ }
+
+ [TestFixtureTearDown]
+ public void TearDown ()
+ {
+ WebTest.Unload ();
+ }
+#endif
+
}
}