X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FTest%2FSystem.Web.UI.WebControls%2FBaseCompareValidatorTest.cs;h=6a95d3b9a26a8d8152c8fb22e09cecdd8d57b8f7;hb=a26fb314f560eda099d5a09370d3eb3d37232b29;hp=eeea5699989dab142dab32389c5bedd909d96a39;hpb=b5cfba1835f2ba823796f825410e0062b7e4c9a3;p=mono.git diff --git a/mcs/class/System.Web/Test/System.Web.UI.WebControls/BaseCompareValidatorTest.cs b/mcs/class/System.Web/Test/System.Web.UI.WebControls/BaseCompareValidatorTest.cs index eeea5699989..6a95d3b9a26 100644 --- a/mcs/class/System.Web/Test/System.Web.UI.WebControls/BaseCompareValidatorTest.cs +++ b/mcs/class/System.Web/Test/System.Web.UI.WebControls/BaseCompareValidatorTest.cs @@ -3,6 +3,7 @@ // // Author: // Chris Toshok (toshok@novell.com) +// Yoni Klain (Yonik@mainsoft.com) // // @@ -36,6 +37,7 @@ using System.Threading; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using MonoTests.SystemWeb.Framework; namespace MonoTests.System.Web.UI.WebControls { @@ -104,16 +106,51 @@ namespace MonoTests.System.Web.UI.WebControls } } - [TestFixture] - public class BaseCompareValidatorTest : ValidatorTest { + [TestFixture] + public class BaseCompareValidatorTest : ValidatorTest + { + + [Test] + public void DefaultProperties () + { + BaseCompareValidatorPoker p = new BaseCompareValidatorPoker (); + + Assert.AreEqual (ValidationDataType.String, p.Type, "CultureInvariantValues"); +#if NET_2_0 + Assert.AreEqual (false, p.CultureInvariantValues, "CultureInvariantValues"); +#endif + } + + [Test] + public void AssignProperties () + { + BaseCompareValidatorPoker p = new BaseCompareValidatorPoker (); + + p.Type = ValidationDataType.Double; + Assert.AreEqual (ValidationDataType.Double, p.Type, "CultureInvariantValues"); +#if NET_2_0 + p.CultureInvariantValues = true; + Assert.AreEqual (true, p.CultureInvariantValues, "CultureInvariantValues"); +#endif + } [Test] public void ViewState () { BaseCompareValidatorPoker p = new BaseCompareValidatorPoker (); - p.Type = ValidationDataType.String; - Assert.AreEqual (p.Type, ValidationDataType.String, "A1"); + p.Type = ValidationDataType.Double; +#if NET_2_0 + p.CultureInvariantValues = true; +#endif + + BaseCompareValidatorPoker copy = new BaseCompareValidatorPoker (); + copy.LoadState (p.SaveState ()); + + Assert.AreEqual (ValidationDataType.Double, copy.Type, "A1"); +#if NET_2_0 + Assert.AreEqual (true, copy.CultureInvariantValues, "A1"); +#endif } [Test] @@ -452,6 +489,110 @@ namespace MonoTests.System.Web.UI.WebControls Thread.CurrentThread.CurrentCulture = new CultureInfo ("af-ZA", false); Assert.AreEqual (p.GetDateElementOrder (), "ymd", "E6"); } - } +#if NET_2_0 + [Test] + public void CultureInvariantValues_1 () + { + Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false); + // Current date format --> "dmy" + Page p = new Page (); + + CompareValidator v = new CompareValidator (); + v.ControlToValidate = "tb1"; + v.Type = ValidationDataType.Date; + v.ValueToCompare = "2005/12/24"; + v.CultureInvariantValues = true; + + TextBox tb1 = new TextBox (); + tb1.ID = "tb1"; + tb1.Text = "12.24.2005"; + + p.Controls.Add (tb1); + p.Controls.Add (v); + + v.Validate (); + Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#1"); + + tb1.Text = "12/24/2005"; + v.Validate (); + Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#2"); + + tb1.Text = "2005.12.24"; + v.Validate (); + Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#3"); + + tb1.Text = "2005.24.12"; + v.Validate (); + Assert.AreEqual (false, v.IsValid, "CultureInvariantValues#4"); + } + + [Test] + public void CultureInvariantValues_2 () + { + + Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-GB", false); + // Current date format --> "dmy" + Page p = new Page (); + + CompareValidator v = new CompareValidator (); + v.ControlToValidate = "tb1"; + v.Type = ValidationDataType.Date; + v.ValueToCompare = "24/12/2005"; + v.CultureInvariantValues = false; + + TextBox tb1 = new TextBox (); + tb1.ID = "tb1"; + tb1.Text = "24.12.2005"; + + p.Controls.Add (tb1); + p.Controls.Add (v); + + v.Validate (); + Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#1"); + + tb1.Text = "24-12-2005"; + v.Validate (); + Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#2"); + + tb1.Text = "2005/12/24"; + v.Validate (); + Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#3"); + + tb1.Text = "2005.24.12"; + v.Validate (); + Assert.AreEqual (false, v.IsValid, "CultureInvariantValues#4"); + } + + [Test] + [Category ("NotWorking")] + [ExpectedException(typeof(HttpException))] + public void CultureInvariantValues_Exception () + { + + Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-GB", false); + // Current date format --> "dmy" + Page p = new Page (); + + CompareValidator v = new CompareValidator (); + v.ControlToValidate = "tb1"; + v.Type = ValidationDataType.Date; + v.ValueToCompare = "12/24/2005"; + v.CultureInvariantValues = false; + + TextBox tb1 = new TextBox (); + tb1.ID = "tb1"; + tb1.Text = "24.12.2005"; + + p.Controls.Add (tb1); + p.Controls.Add (v); + + v.Validate (); + Assert.AreEqual (true, v.IsValid, "CultureInvariantValues#1"); + + tb1.Text = "24-12-2005"; + v.Validate (); + } +#endif + } }