| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- //
- // Tests for System.Web.UI.WebControls.RangeValidator
- //
- // 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.Drawing;
- using System.IO;
- using System.Globalization;
- using WebSpace = System.Web;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace MonoTests.System.Web.UI.WebControls
- {
- [TestFixture]
- public class RangeValidatorTest : ValidatorTest {
- public class RangeValidatorTestClass : RangeValidator {
- public RangeValidatorTestClass () {
- TrackViewState();
- }
- public object SaveState () {
- return SaveViewState ();
- }
- public void LoadState (object o) {
- LoadViewState (o);
- }
- public void SetTrackingVS () {
- TrackViewState ();
- }
- public void CheckProperties () {
- ControlPropertiesValid ();
- }
- public bool DoEvaluateIsValid () {
- return EvaluateIsValid ();
- }
- public void CallInit() {
- base.OnInit(EventArgs.Empty);
- }
- public string Render () {
- HtmlTextWriter writer;
- writer = RangeValidatorTest.GetWriter();
- base.Render (writer);
- return writer.InnerWriter.ToString ();
- }
- public bool UpRender () {
- return base.RenderUplevel;
- }
- }
- private static HtmlTextWriter GetWriter () {
- StringWriter sw = new StringWriter ();
- sw.NewLine = "\n";
- return new HtmlTextWriter (sw);
- }
- [Test]
- public void State () {
- RangeValidatorTestClass p;
- RangeValidatorTestClass p_copy;
- object state;
- p = new RangeValidatorTestClass();
- Assert.AreEqual (p.ControlToValidate, String.Empty, "S1");
- Assert.AreEqual (p.MinimumValue, String.Empty, "S2");
- Assert.AreEqual (p.MaximumValue, String.Empty, "S3");
- p.ControlToValidate = "TextBox";
- Assert.AreEqual ("TextBox", p.ControlToValidate, "S4");
- p.MinimumValue = "123";
- Assert.AreEqual ("123", p.MinimumValue, "S5");
- p.MaximumValue = "456";
- Assert.AreEqual ("456", p.MaximumValue, "S6");
- state = p.SaveState ();
- p_copy = new RangeValidatorTestClass ();
- p_copy.LoadState (state);
- Assert.AreEqual ("TextBox", p.ControlToValidate, "S7");
- Assert.AreEqual ("123", p.MinimumValue, "S8");
- Assert.AreEqual ("456", p.MaximumValue, "S9");
- }
-
- [Test]
- public void Defaults ()
- {
- RangeValidatorTestClass p;
- p = new RangeValidatorTestClass();
- Assert.AreEqual (String.Empty, p.ControlToValidate, "D1");
- Assert.AreEqual (String.Empty, p.MinimumValue, "D2");
- Assert.AreEqual (String.Empty, p.MaximumValue, "D3");
- Assert.AreEqual (true, p.EnableClientScript, "D4");
- Assert.AreEqual (false, p.UpRender(), "D5");
- }
- [Test]
- public void Render () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- p.Type = ValidationDataType.Integer;
- Assert.AreEqual (false, p.UpRender(), "R0");
- t = SetValidationTextBox("textbox", "3");
- p.MinimumValue = "1";
- p.MaximumValue = "2";
- p.Validate();
- p.ErrorMessage = "aw shucks";
- p.Display = ValidatorDisplay.Static;
- p.Enabled = true;
- p.EnableViewState = true;
- Assert.AreEqual("<span style=\"color:Red;\">aw shucks</span>", p.Render(), "R1");
- }
- [Test]
- public void ValidateRangeTest () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- p.Type = ValidationDataType.Integer;
- p.MinimumValue = "2";
- p.MaximumValue = "4";
- t = SetValidationTextBox("textbox", "1");
- Assert.AreEqual(false, p.DoEvaluateIsValid(), "V1");
- t.Text = "2";
- Assert.AreEqual(true, p.DoEvaluateIsValid(), "V2");
- t.Text = "3";
- Assert.AreEqual(true, p.DoEvaluateIsValid(), "V3");
- t.Text = "4";
- Assert.AreEqual(true, p.DoEvaluateIsValid(), "V4");
- t.Text = "5";
- Assert.AreEqual(false, p.DoEvaluateIsValid(), "V5");
- StopValidationTest();
- }
- [Test]
- [ExpectedException(typeof(WebSpace.HttpException))]
- public void Exception1Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- p.CheckProperties();
- }
- [Test]
- [ExpectedException(typeof(WebSpace.HttpException))]
- public void Exception2Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- t = SetValidationTextBox("textbox", "1");
- p.Type = ValidationDataType.Integer;
- p.MaximumValue = "1";
- p.CheckProperties();
- }
- [Test]
- [ExpectedException(typeof(WebSpace.HttpException))]
- public void Exception3Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- t = SetValidationTextBox("textbox", "1");
- p.Type = ValidationDataType.Integer;
- p.MinimumValue = "1";
- p.CheckProperties();
- }
- [Test]
- [ExpectedException(typeof(WebSpace.HttpException))]
- public void Exception4Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- t = SetValidationTextBox("textbox", "1");
- p.Type = ValidationDataType.Date;
- p.MaximumValue = "1";
- p.CheckProperties();
- }
- [Test]
- [ExpectedException(typeof(WebSpace.HttpException))]
- public void Exception5Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- t = SetValidationTextBox("textbox", "1");
- p.Type = ValidationDataType.Integer;
- p.MinimumValue = "3";
- p.MaximumValue = "1";
- p.CheckProperties();
- }
- [Test]
- [ExpectedException(typeof(WebSpace.HttpException))]
- public void Exception6Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- t = SetValidationTextBox("textbox", "1");
- p.Type = ValidationDataType.Date;
- p.MinimumValue = "01/01/02";
- p.MaximumValue = "01/01/01";
- p.CheckProperties();
- }
- [Test]
- //[ExpectedException(typeof(WebSpace.HttpException))]
- public void NoException7Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- t = SetValidationTextBox("textbox", "1");
- p.Type = ValidationDataType.String;
- p.MinimumValue = "lasdjflk jasldfj ";
- p.MaximumValue = "s.dfjalsd fl;asdf";
- p.CheckProperties();
- }
- [Test]
- [ExpectedException(typeof(WebSpace.HttpException))]
- public void Exception8Test () {
- RangeValidatorTestClass p;
- TextBox t;
- p = new RangeValidatorTestClass();
- StartValidationTest(p);
- p.Type = ValidationDataType.Integer;
- p.MinimumValue = "2";
- p.MaximumValue = "4";
- t = SetValidationTextBox("textbox", "1");
- t = SetValidationTextBox("textbox", "2");
- p.DoEvaluateIsValid();
- }
- }
- }
|