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(); }
public void ErrorMessage_CustomFormat_AreEqual() { string column = "測試欄位"; const string comparisonColumn = "比較欄位"; CompareValidator validator = new CompareValidator(column, "123", comparisonColumn, "456", "{0}Compare{1}"); validator.Validate(); Assert.AreEqual( string.Format(validator.CustomErrorMessageFormat, column, comparisonColumn), validator.ErrorMessage ); }
public void ErrorMessage_BasicFormat_AreEqual() { const string column = "測試欄位"; const string comparisonColumn = "比較欄位"; CompareValidator validator = new CompareValidator(column, "123", comparisonColumn, "456"); validator.Validate(); Assert.AreEqual( string.Format(validator.DefaultErrorMessageFormat, column, comparisonColumn), validator.ErrorMessage ); }
/// <summary> /// When overridden in a derived class, this method contains the code to determine whether the value in the input control is valid. /// </summary> /// <returns> /// true if the value in the input control is valid; otherwise, false. /// </returns> protected override bool EvaluateIsValid() { if (this.rangeValidator != null) { rangeValidator.Validate(); if (!this.rangeValidator.IsValid) { return(false); } } if (this.requiredFieldValidator != null) { requiredFieldValidator.Validate(); if (!this.requiredFieldValidator.IsValid) { return(false); } } if (this.compareValidator != null) { compareValidator.Validate(); if (!this.compareValidator.IsValid) { return(false); } } if (this.regularExpressionValidator != null) { regularExpressionValidator.Validate(); if (!this.regularExpressionValidator.IsValid) { return(false); } } if (this.customStringLengthValidator != null) { customStringLengthValidator.Validate(); if (!this.customStringLengthValidator.IsValid) { return(false); } } return(true); }
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"); }
//******************************************************* // // TimeEntryGrid_OnUpdate server event handler on this page is used to // update the changes made from in-line-editing. // //******************************************************* protected void TimeEntryGrid_OnUpdate(Object sender, DataGridCommandEventArgs e) { DataGridItem item = TimeEntryGrid.Items[TimeEntryGrid.EditItemIndex]; RequiredFieldValidator required = (RequiredFieldValidator)item.FindControl("RequiredFieldValidatorGridHours"); CompareValidator comparer = (CompareValidator)item.FindControl("CompareValidatorGridHours"); required.Validate(); comparer.Validate(); // Check for validation, if all valid, update the object to data entered and save it. if (required.IsValid && comparer.IsValid) { int entryLogID; int userID; int projectID; int categoryID; DateTime taskDate; string description; decimal duration; BusinessLogicLayer.TimeEntry te = null; // Fill in properties for TimeEntry object. entryLogID = Convert.ToInt32(TimeEntryGrid.DataKeys[(int)e.Item.ItemIndex]); userID = Convert.ToInt32(UserList.SelectedItem.Value); projectID = Convert.ToInt32(((DropDownList)e.Item.FindControl("EntryProjects")).SelectedItem.Value); categoryID = Convert.ToInt32(((DropDownList)e.Item.FindControl("EntryCategories")).SelectedItem.Value); taskDate = Convert.ToDateTime(((DropDownList)e.Item.FindControl("EntryDays")).SelectedItem.Value); description = ITSecurity.CleanStringRegex(((TextBox)e.Item.FindControl("EntryDescription")).Text); duration = Convert.ToDecimal(((TextBox)e.Item.FindControl("EntryHours")).Text); // Save the TimeEntry object. te = new BusinessLogicLayer.TimeEntry(entryLogID, userID, projectID, categoryID, taskDate, description, duration); te.Save(); // Quit in-line-editing mode. TimeEntryGrid.EditItemIndex = -1; BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate); } }
public void Validate_ReturnValue_AreEqual(string value, string comparisonValue, bool isValid) { CompareValidator validator = new CompareValidator("", value, "", comparisonValue); Assert.AreEqual(validator.Validate(), isValid); }