| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- //
- // HtmlInputRadioButtonTest.cs
- // - Unit tests for System.Web.UI.HtmlControls.HtmlInputRadioButton
- //
- // Author:
- // Sebastien Pouliot <[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 System;
- using System.Collections.Specialized;
- using System.IO;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using NUnit.Framework;
- namespace MonoTests.System.Web.UI.HtmlControls {
- public class TestHtmlInputRadioButton : HtmlInputRadioButton {
- public string RenderAttributes ()
- {
- HtmlTextWriter writer = new HtmlTextWriter (new StringWriter ());
- base.RenderAttributes (writer);
- return writer.InnerWriter.ToString ();
- }
- #if NET_2_0
- public bool LoadPost (string key, NameValueCollection nvc)
- {
- return base.LoadPostData (key, nvc);
- }
- public void Raise ()
- {
- base.RaisePostDataChangedEvent ();
- }
- #endif
- }
- [TestFixture]
- public class HtmlInputRadioButtonTest {
- private const int defaultAttributesCount = 1;
- [Test]
- public void DefaultProperties ()
- {
- HtmlInputRadioButton rb = new HtmlInputRadioButton ();
- Assert.AreEqual (defaultAttributesCount, rb.Attributes.Count, "Attributes.Count");
- Assert.IsFalse (rb.Checked, "Checked");
- Assert.AreEqual (String.Empty, rb.Name, "Name");
- Assert.IsNull (rb.Value, "Value");
- Assert.AreEqual ("input", rb.TagName, "TagName");
- Assert.AreEqual (defaultAttributesCount, rb.Attributes.Count, "Attributes.Count-2");
- }
- [Test]
- public void NullProperties ()
- {
- HtmlInputRadioButton rb = new HtmlInputRadioButton ();
- rb.Name = null;
- Assert.AreEqual (String.Empty, rb.Name, "Name");
- rb.Value = null;
- Assert.IsNull (rb.Value, "Value");
- Assert.AreEqual (defaultAttributesCount, rb.Attributes.Count, "Attributes.Count");
- }
- [Test]
- public void CleanProperties ()
- {
- HtmlInputRadioButton rb = new HtmlInputRadioButton ();
- rb.Checked = true;
- Assert.IsTrue (rb.Checked, "Checked");
- rb.Name = "name";
- Assert.AreEqual ("name", rb.Name, "Name");
- rb.Value = "value";
- Assert.AreEqual ("value", rb.Value, "Value");
- Assert.AreEqual (defaultAttributesCount + 3, rb.Attributes.Count, "1");
- rb.Checked = false;
- Assert.IsFalse (rb.Checked, "-Checked");
- rb.Name = null;
- Assert.AreEqual (String.Empty, rb.Name, "-Name");
- rb.Value = null;
- Assert.IsNull (rb.Value, "-Value");
- Assert.AreEqual (defaultAttributesCount, rb.Attributes.Count, "0");
- }
- [Test]
- public void Value_Existing ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.Value = "a";
- Assert.AreEqual ("a", rb.Value, "Value before");
- rb.ID = "id1";
- Assert.AreEqual ("id1", rb.ID, "ID");
- Assert.AreEqual ("a", rb.Value, "Value after");
- }
- [Test]
- public void Value_Resetting ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ID = "id1";
- Assert.AreEqual ("id1", rb.Value, "Value before");
- rb.Value = "a";
- Assert.AreEqual ("id1", rb.ID, "ID");
- Assert.AreEqual ("a", rb.Value, "Value after");
- }
- [Test]
- public void Value_ResetNull ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.Value = "a";
- rb.ID = "id1";
- rb.Value = null;
- Assert.AreEqual ("id1", rb.ID, "ID");
- Assert.AreEqual ("id1", rb.Value, "Value");
- }
- [Test]
- // note: this behaviour isn't present in HtmlInputControl
- public void IDversusValue ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- Assert.IsNull (rb.Value, "Value before");
- rb.ID = "id1";
- Assert.AreEqual ("id1", rb.ID, "ID");
- Assert.AreEqual ("id1", rb.Value, "Value after");
- }
- [Test]
- [Ignore ("throws NullReferenceException")]
- public void RenderAttributes ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.Checked = true;
- rb.Name = "mono";
- rb.Value = "value";
- rb.RenderAttributes ();
- }
- private bool serverChange;
- private void ServerChange (object sender, EventArgs e)
- {
- serverChange = true;
- }
- [Test]
- public void IPostBackDataHandler_RaisePostBackEvent ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ServerChange += new EventHandler (ServerChange);
- IPostBackDataHandler pbdh = (rb as IPostBackDataHandler);
- serverChange = false;
- pbdh.RaisePostDataChangedEvent ();
- Assert.IsTrue (serverChange, "ServerChange");
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void IPostBackDataHandler_LoadPostData_NullCollection ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- IPostBackDataHandler pbdh = (rb as IPostBackDataHandler);
- pbdh.LoadPostData ("id1", null);
- }
- [Test]
- [Category ("NotDotNet")] // MS throws a NullReferenceException here
- public void IPostBackDataHandler_LoadPostData_IdNull ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ID = "id1";
- IPostBackDataHandler pbdh = (rb as IPostBackDataHandler);
- NameValueCollection nvc = new NameValueCollection ();
- nvc.Add ("id1", "mono");
- Assert.IsFalse (pbdh.LoadPostData (null, nvc), "LoadPostData");
- Assert.AreEqual ("id1", rb.Value, "Value");
- }
- [Test]
- public void IPostBackDataHandler_LoadPostData_WrongId ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ID = "id1";
- IPostBackDataHandler pbdh = (rb as IPostBackDataHandler);
- NameValueCollection nvc = new NameValueCollection ();
- nvc.Add ("id1", "mono");
- Assert.IsFalse (pbdh.LoadPostData ("id2", nvc), "LoadPostData");
- Assert.AreEqual ("id1", rb.Value, "Value");
- }
- [Test]
- public void IPostBackDataHandler_LoadPostData ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ID = "id1";
- IPostBackDataHandler pbdh = (rb as IPostBackDataHandler);
- NameValueCollection nvc = new NameValueCollection ();
- nvc.Add ("id1", "id1");
- // we didn't change the state of the control
- Assert.IsFalse (pbdh.LoadPostData ("id1", nvc), "LoadPostData");
- Assert.AreEqual ("id1", rb.Value, "Value");
- }
- #if NET_2_0
- [Test]
- public void RaisePostBackEvent ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ServerChange += new EventHandler (ServerChange);
- serverChange = false;
- rb.Raise ();
- Assert.IsTrue (serverChange, "ServerClick");
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void LoadPostData_NullCollection ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.LoadPost ("id1", null);
- }
- [Test]
- [Category ("NotDotNet")] // MS throws a NullReferenceException here
- public void LoadPostData_IdNull ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ID = "id1";
- NameValueCollection nvc = new NameValueCollection ();
- nvc.Add ("id1", "mono");
- Assert.IsFalse (rb.LoadPost (null, nvc), "LoadPostData");
- Assert.AreEqual ("id1", rb.Value, "Value");
- }
- [Test]
- public void LoadPostData_WrongId ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ID = "id1";
- NameValueCollection nvc = new NameValueCollection ();
- nvc.Add ("id1", "mono");
- Assert.IsFalse (rb.LoadPost ("id2", nvc), "LoadPostData");
- Assert.AreEqual ("id1", rb.Value, "Value");
- }
- [Test]
- public void LoadPostData ()
- {
- TestHtmlInputRadioButton rb = new TestHtmlInputRadioButton ();
- rb.ID = "id1";
- NameValueCollection nvc = new NameValueCollection ();
- nvc.Add ("id1", "mono");
- Assert.IsFalse (rb.LoadPost ("id1", nvc), "LoadPostData");
- Assert.AreEqual ("id1", rb.Value, "Value");
- }
- #endif
- }
- }
|