X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FTest%2FSystem.Web.UI.WebControls%2FTextBoxTest.cs;h=1912ef0f896ad82238cce84da7b778eb10c192f5;hb=b58f5b27ba58a6b3ef028100c9cb5c594e12c2c6;hp=715357e750ad8cf818c3cdf8c203cadfe37d391b;hpb=dbf19eb41dbd299c4c33d4de35ffe3cf6c669832;p=mono.git diff --git a/mcs/class/System.Web/Test/System.Web.UI.WebControls/TextBoxTest.cs b/mcs/class/System.Web/Test/System.Web.UI.WebControls/TextBoxTest.cs index 715357e750a..1912ef0f896 100644 --- a/mcs/class/System.Web/Test/System.Web.UI.WebControls/TextBoxTest.cs +++ b/mcs/class/System.Web/Test/System.Web.UI.WebControls/TextBoxTest.cs @@ -35,6 +35,9 @@ using System.Globalization; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using MonoTests.SystemWeb.Framework; +using MonoTests.stand_alone.WebHarness; +using System.Collections; namespace MonoTests.System.Web.UI.WebControls { @@ -74,6 +77,32 @@ namespace MonoTests.System.Web.UI.WebControls { } } + [TestFixtureSetUp] + public void SetUp () + { + WebTest.CopyResource (GetType (), "TextBoxTestlPage.aspx", "TextBoxTestlPage.aspx"); + WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx"); + } + + [Test] + public void Defaults () + { + Poker p = new Poker (); +#if NET_2_0 + Assert.AreEqual (string.Empty, p.ValidationGroup, "ValidationGroup"); + Assert.AreEqual (false, p.CausesValidation, "CausesValidation"); +#endif + } + + [Test] + public void Defaults_NotWorking () + { + Poker p = new Poker (); +#if NET_2_0 + Assert.AreEqual (AutoCompleteType.None, p.AutoCompleteType, "AutoCompleteType"); +#endif + } + [Test] public void MultilineRenderEscape () { @@ -86,7 +115,7 @@ namespace MonoTests.System.Web.UI.WebControls { string exp = ""; #endif - Assert.AreEqual (exp, t.Render ()); + HtmlDiff.AssertAreEqual(exp, t.Render (),"MultilineRenderEscape"); } @@ -142,7 +171,228 @@ namespace MonoTests.System.Web.UI.WebControls { t.TextMode = TextBoxMode.MultiLine; string exp = ""; - Assert.AreEqual (exp, t.Render ()); + HtmlDiff.AssertAreEqual (exp, t.Render (),"ValidationRender"); + } + + [Test] + [Category ("NunitWeb")] + public void CausesValidation_ValidationGroup () + { + WebTest t = new WebTest ("TextBoxTestlPage.aspx"); + string str = t.Run (); + FormRequest fr = new FormRequest (t.Response, "form1"); + fr.Controls.Add ("__EVENTTARGET"); + fr.Controls.Add ("__EVENTARGUMENT"); + fr.Controls.Add ("TextBox1"); + fr.Controls["__EVENTTARGET"].Value = "TextBox1"; + fr.Controls["__EVENTARGUMENT"].Value = ""; + fr.Controls["TextBox1"].Value = "TestValue"; + 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"); + } + + #region Help_class + public class PokerL : TextBox + { + public string Render () + { + StringWriter sw = new StringWriter (); + sw.NewLine = "\n"; + HtmlTextWriter writer = new HtmlTextWriter (sw); + base.Render (writer); + return writer.InnerWriter.ToString (); + } + + public new void RaisePostDataChangedEvent () + { + base.RaisePostDataChangedEvent (); + } + + protected override bool LoadPostData (string postDataKey, global::System.Collections.Specialized.NameValueCollection postCollection) + { + if (WebTest.CurrentTest.UserData == null) { + ArrayList list = new ArrayList (); + list.Add ("LoadPostData"); + WebTest.CurrentTest.UserData = list; + } + else { + ArrayList list = WebTest.CurrentTest.UserData as ArrayList; + if (list == null) + throw new NullReferenceException (); + list.Add ("LoadPostData"); + WebTest.CurrentTest.UserData = list; + } + return base.LoadPostData (postDataKey, postCollection); + } + + protected override void OnLoad (EventArgs e) + { + if (this.Page.IsPostBack) { + if (WebTest.CurrentTest.UserData == null) { + ArrayList list = new ArrayList (); + list.Add ("ControlLoad"); + WebTest.CurrentTest.UserData = list; + } + else { + ArrayList list = WebTest.CurrentTest.UserData as ArrayList; + if (list == null) + throw new NullReferenceException (); + list.Add ("ControlLoad"); + WebTest.CurrentTest.UserData = list; + } + } + base.OnLoad (e); + } + } + #endregion + + [Test] + [Category ("NunitWeb")] + public void LoadPostData_Flow () //Just flow and not implementation detail + { + WebTest t = new WebTest (PageInvoker.CreateOnLoad (LoadPostData_Load)); + string html = t.Run (); + FormRequest fr = new FormRequest (t.Response, "form1"); + fr.Controls.Add ("__EVENTTARGET"); + fr.Controls.Add ("__EVENTARGUMENT"); + fr.Controls.Add ("pb"); + fr.Controls["__EVENTTARGET"].Value = "pb"; + fr.Controls["__EVENTARGUMENT"].Value = ""; + fr.Controls["pb"].Value = "TestValue"; + t.Request = fr; + t.Run (); + + ArrayList eventlist = t.UserData as ArrayList; + if (eventlist == null) + Assert.Fail ("User data does not been created fail"); + Assert.AreEqual ("PageLoad", eventlist[0], "Live Cycle Flow #1"); + Assert.AreEqual ("ControlLoad", eventlist[1], "Live Cycle Flow #2"); + Assert.AreEqual ("LoadPostData", eventlist[2], "Live Cycle Flow #3"); + } + + public static void LoadPostData_Load (Page p) + { + PokerL b = new PokerL (); + b.AutoPostBack = true; + b.ID = "pb"; + p.Form.Controls.Add (b); + if (p.IsPostBack) { + if (WebTest.CurrentTest.UserData == null) { + ArrayList list = new ArrayList (); + list.Add ("PageLoad"); + WebTest.CurrentTest.UserData = list; + } + else { + ArrayList list = WebTest.CurrentTest.UserData as ArrayList; + if (list == null) + throw new NullReferenceException (); + list.Add ("PageLoad"); + WebTest.CurrentTest.UserData = list; + } + } + } + + [Test] + [Category ("NunitWeb")] + public void LoadPostData () + { + WebTest t = new WebTest (PageInvoker.CreateOnLoad (LoadPostData__Load)); + string html = t.Run (); + FormRequest fr = new FormRequest (t.Response, "form1"); + fr.Controls.Add ("__EVENTTARGET"); + fr.Controls.Add ("__EVENTARGUMENT"); + fr.Controls.Add ("pb"); + fr.Controls["__EVENTTARGET"].Value = "pb"; + fr.Controls["__EVENTARGUMENT"].Value = ""; + fr.Controls["pb"].Value = "TestValue"; + t.Request = fr; + html = t.Run (); + + ArrayList eventlist = t.UserData as ArrayList; + if (eventlist == null) + Assert.Fail ("User data does not been created fail"); + Assert.AreEqual ("ControlLoad", eventlist[0], "Live Cycle Flow #1"); + Assert.AreEqual ("LoadPostData", eventlist[1], "Live Cycle Flow #2"); + Assert.AreEqual ("TextChanged", eventlist[2], "Live Cycle Flow #3"); + + if (html.IndexOf ("TestValue") == -1) + Assert.Fail ("Wrong value failed"); + } + + public static void LoadPostData__Load (Page p) + { + PokerL b = new PokerL (); + b.ID = "pb"; + p.Form.Controls.Add (b); + b.TextChanged += new EventHandler (b_TextChanged); + if (p.IsPostBack) + p.Response.Write (b.Text); + } + + public static void b_TextChanged (object sender, EventArgs e) + { + if (WebTest.CurrentTest.UserData == null) { + ArrayList list = new ArrayList (); + list.Add ("TextChanged"); + WebTest.CurrentTest.UserData = list; + } + else { + ArrayList list = WebTest.CurrentTest.UserData as ArrayList; + if (list == null) + throw new NullReferenceException (); + list.Add ("TextChanged"); + WebTest.CurrentTest.UserData = list; + } + } + + [Test] + public void RaisePostDataChangedEvent () + { + PokerL p = new PokerL (); + p.TextChanged += new EventHandler (p_TextChanged); + Assert.AreEqual (false, eventTextChanged, "RaisePostDataChangedEvent#1"); + p.RaisePostDataChangedEvent (); + Assert.AreEqual (true, eventTextChanged, "RaisePostDataChangedEvent#2"); + } + + bool eventTextChanged; + void p_TextChanged(object sender, EventArgs e) + { + eventTextChanged = true; + } + + [Test] + public void AutoCompleteType_Test () + { + WebTest t = new WebTest ("NoEventValidation.aspx"); + t = new WebTest (PageInvoker.CreateOnLoad (AutoCompleteType__Load)); + string html = t.Run (); + string orig =""; + HtmlDiff.AssertAreEqual (orig, HtmlDiff.GetControlFromPageHtml (html), "AutoCompleteType"); + } + + public static void AutoCompleteType__Load (Page page) + { + LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG); + LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG); + + PokerL p = new PokerL (); + p.ID = "Poker"; + p.AutoCompleteType = AutoCompleteType.FirstName; + page.Form.Controls.Add (lcb); + page.Form.Controls.Add (p); + page.Form.Controls.Add (lce); + } + + [TestFixtureTearDown] + public void TearDown () + { + WebTest.Unload (); } #endif }