2006-11-22 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / BaseCompareValidatorTest.cs
index 8e688749c2bc6a13d208cf5f0be7cec8a2c780bb..6a95d3b9a26a8d8152c8fb22e09cecdd8d57b8f7 100644 (file)
@@ -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]
@@ -435,11 +472,7 @@ namespace MonoTests.System.Web.UI.WebControls
                {
                        BaseCompareValidatorPoker p = new BaseCompareValidatorPoker ();
 
-#if NET_2_0
-                       Assert.AreEqual (p.GetCutoffYear(), 29, "E1");
-#else
                        Assert.AreEqual (p.GetCutoffYear(), 2029, "E1");
-#endif
                        Assert.AreEqual (p.GetFullYear (29), 2029, "E2");
 #if NET_2_0
                        Assert.AreEqual (p.GetFullYear (30), 1930, "E3");
@@ -456,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
+       }
 }