1 // 2 // Tests for System.Web.UI.WebControls.RegularExpressionValidator 3 // 4 // Author: 5 // Chris Toshok (toshok@novell.com) 6 // 7 8 // 9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com) 10 // 11 // Permission is hereby granted, free of charge, to any person obtaining 12 // a copy of this software and associated documentation files (the 13 // "Software"), to deal in the Software without restriction, including 14 // without limitation the rights to use, copy, modify, merge, publish, 15 // distribute, sublicense, and/or sell copies of the Software, and to 16 // permit persons to whom the Software is furnished to do so, subject to 17 // the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be 20 // included in all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 // 30 31 using NUnit.Framework; 32 using System; 33 using System.IO; 34 using System.Globalization; 35 using System.Web; 36 using System.Web.UI; 37 using System.Web.UI.WebControls; 38 39 namespace MonoTests.System.Web.UI.WebControls 40 { 41 class REValidatorPoker : RegularExpressionValidator { REValidatorPoker()42 public REValidatorPoker () 43 { 44 TrackViewState (); 45 } 46 SaveState()47 public object SaveState () 48 { 49 return SaveViewState (); 50 } 51 LoadState(object o)52 public void LoadState (object o) 53 { 54 LoadViewState (o); 55 } 56 DoEvaluateIsValid()57 public bool DoEvaluateIsValid () 58 { 59 return EvaluateIsValid (); 60 } 61 62 } 63 64 65 [TestFixture] 66 public class RegularExpressionValidatorTest : ValidatorTest { 67 68 [Test] REValidator_ViewState()69 public void REValidator_ViewState () 70 { 71 REValidatorPoker p = new REValidatorPoker (); 72 73 Assert.AreEqual (p.ValidationExpression, String.Empty, "A1"); 74 75 p.ValidationExpression = "\\d{5}"; 76 Assert.AreEqual ("\\d{5}", p.ValidationExpression, "A2"); 77 78 object state = p.SaveState (); 79 80 REValidatorPoker copy = new REValidatorPoker (); 81 copy.LoadState (state); 82 Assert.AreEqual ("\\d{5}", copy.ValidationExpression, "A3"); 83 } 84 85 [Test] REValidator_ValidationTests()86 public void REValidator_ValidationTests () 87 { 88 REValidatorPoker p = new REValidatorPoker (); 89 TextBox box; 90 91 StartValidationTest (p); 92 93 p.ValidationExpression = "\\d{5}"; 94 box = SetValidationTextBox ("textbox", "94117"); 95 Assert.IsTrue (p.DoEvaluateIsValid (), "B1"); 96 97 box.Text = "9410"; 98 Assert.IsFalse (p.DoEvaluateIsValid (), "B2"); 99 100 box.Text = "12345 "; 101 Assert.IsFalse (p.DoEvaluateIsValid (), "B3"); 102 103 box.Text = " 12345"; 104 Assert.IsFalse (p.DoEvaluateIsValid (), "B4"); 105 106 box.Text = " 12345 "; 107 Assert.IsFalse (p.DoEvaluateIsValid (), "B5"); 108 109 p.ValidationExpression = "^\\d{5}$"; 110 box.Text = "12345"; 111 Assert.IsTrue (p.DoEvaluateIsValid (), "B6"); 112 113 StopValidationTest(); 114 } 115 } 116 } 117 118 119