public void ShouldReturnTrueForCorrectStringAndHasToBeEqualToInputDate() { NumberValidator numberValidator = new NumberValidator(correctTestString, separator1); Assert.IsTrue(numberValidator.Validate()); Assert.AreEqual(testValueDouble, numberValidator.Number); }
public void ShouldReturnTrueForIntAndHasToBeEqualToInputDate() { NumberValidator numberValidator = new NumberValidator(testValueInt, separator1); Assert.IsTrue(numberValidator.Validate()); Assert.AreEqual(testValueInt, numberValidator.Number); }
public void ShouldReturnTrueForIncorrectStringAndHasToBeEqualZero() { NumberValidator numberValidator = new NumberValidator(incorrectTestString, separator1); Assert.IsFalse(numberValidator.Validate()); Assert.AreEqual(0, numberValidator.Number); }
public void ShouldReturnTrueForDecimalAndHasToBeEqualToInputDate() { NumberValidator numberValidator = new NumberValidator(testValueDecimal, separator2); Assert.IsTrue(numberValidator.Validate()); Assert.AreEqual(testValueDecimal, (decimal)numberValidator.Number); }
public void ShouldReturnFalseForEmptyObjectAndHasToBeEqualZero() { object emptyObject = new object(); NumberValidator numberValidator = new NumberValidator(emptyObject, separator1); Assert.IsFalse(numberValidator.Validate()); Assert.AreEqual(0, numberValidator.Number); }
public void Validate_TooManyDigits_ReturnFalse() { // Arrange var validator = new NumberValidator(); var number = "00467562341424"; // Act var validationResult = validator.Validate(number); // Assert validationResult.Should().BeFalse(); }
public void Validate_ValidNumber_ReturnTrue() { // Arrange var validator = new NumberValidator(); var number = "+46712312123"; // Act var validationResult = validator.Validate(number); // Assert validationResult.Should().BeTrue(); }
public void Validate_InvalidCharacters_ReturnFalse() { // Arrange var validator = new NumberValidator(); var number = "T00467562341424"; // Act var validationResult = validator.Validate(number); // Assert validationResult.Should().BeFalse(); }
public void ErrorMessage_RangeFormat_AreEqual() { string column = "測試欄位"; NumberValidator validator = new NumberValidator(column, "0.1", 1.1m, 2.1m); validator.Validate(); Assert.AreEqual( string.Format(validator.RangeErrorMessageFormat, column, 1.1m, 2.1m), validator.ErrorMessage ); }
public void ErrorMessage_MinFormat_AreEqual() { string column = "測試欄位"; NumberValidator validator = NumberValidator.CreateMinValue(column, "0.1", 1.1m); validator.Validate(); Assert.AreEqual( string.Format(validator.MinValueErrorMessageFormat, column, 1.1m), validator.ErrorMessage ); }
public void ErrorMessage_CustomFormat_AreEqual() { string column = "測試欄位"; NumberValidator validator = new NumberValidator(column, "error", "{0}Number"); validator.Validate(); Assert.AreEqual( string.Format(validator.CustomErrorMessageFormat, column), validator.ErrorMessage ); }
public void ErrorMessage_BasicFormat_AreEqual() { string column = "測試欄位"; NumberValidator validator = new NumberValidator(column, "error"); validator.Validate(); Assert.AreEqual( string.Format(validator.DefaultErrorMessageFormat, column), validator.ErrorMessage ); }
public void ErrorMessage_RangeCustomFormat_AreEqual() { string column = "測試欄位"; NumberValidator validator = new NumberValidator(column, "0.1", 1.1m, 2.1m, customRangeMessageFormat: "{0}_{1}_{2}Number"); validator.Validate(); Assert.AreEqual( string.Format(validator.CustomRangeMessageFormat, column, 1.1m, 2.1m), validator.ErrorMessage ); }
public void ErrorMessage_MaxCustomFormat_AreEqual() { string column = "測試欄位"; NumberValidator validator = NumberValidator.CreateMaxValue(column, "1.1", 0.1m, customRangeMessageFormat: "{0}_{1}Number"); validator.Validate(); Assert.AreEqual( string.Format(validator.CustomRangeMessageFormat, column, 0.1m), validator.ErrorMessage ); }
public void Then_correct_errors_are_returned(object input, bool isValid) { var validator = new NumberValidator { ValidationDefinition = new ValidationDefinition() { ErrorMessage = "Not a valid Number", Name = "Number" } }; var question = new Question { QuestionId = "Q1" }; var errors = validator.Validate(question, new Answer { Value = input?.ToString(), QuestionId = question.QuestionId }); (errors.Count is 0).Should().Be(isValid); }
private bool CanRegister() { return(!_isNumberInitiallyEmpty || NumberValidator.Validate()); }
public void Validate_ReturnsEmpty() { Assert.Empty(validator.Validate(null)); }
/// <summary> /// The method validates whether a supplied object is a valid number. /// </summary> /// <param name="objectToValidate">An object to be valdiated whether it is a valid number.</param> /// <param name="separator">A string separator used to separate an integer part from a fractional part in a number.</param> /// <returns>True - if object is valid, false - if object is invalid.</returns> public static bool IsNumber(object objectToValidate, string separator) { Validator validator = new NumberValidator(objectToValidate, separator); return(validator.Validate()); }
public void Validate_Format_AreEqual(string value, bool isValid) { NumberValidator validator = new NumberValidator("", value); Assert.AreEqual(validator.Validate(), isValid); }
public void Validate_Range_AreEqual(string value, decimal min, decimal max, bool isValid) { NumberValidator validator = new NumberValidator("", value, min, max); Assert.AreEqual(validator.Validate(), isValid); }
public void Validate_Min_AreEqual(string value, decimal min, bool isValid) { NumberValidator validator = NumberValidator.CreateMinValue("", value, min); Assert.AreEqual(validator.Validate(), isValid); }
public void Validate_Max_AreEqual(string value, decimal max, bool isValid) { NumberValidator validator = NumberValidator.CreateMaxValue("", value, max); Assert.AreEqual(validator.Validate(), isValid); }
public void Validate_DoesNotValidate() { Assert.Empty(validator.Validate(null)); }
/// <summary> /// Add object in Grid Control /// </summary> /// <param name="sender"></param> private void AddObjectInGridButton_Click(object sender, EventArgs e) { var validator = new NumberValidator(); var validateUpTextBox = validator.Validate(FigureUpTextBox.Text); var validateDownTextBox = validator.Validate(FigureDownTextBox.Text); switch ((Figures)FigureComboBox.SelectedIndex) { case Figures.Circle: if (validateUpTextBox) { var radius = Convert.ToDouble(Tools.ReplaceDotsByCommas(FigureUpTextBox.Text)); var circle = new Circle(radius); _parentDataGrid.Rows.Add(); _parentDataGrid["FigureName", _parentDataGrid.Rows.Count - 1].Value = "Circle"; _parentDataGrid["FigureArea", _parentDataGrid.Rows.Count - 1].Value = circle.CountArea(); } else { var errors = new string[1] { "" }; if (!validateUpTextBox) { errors[0] = "Circle radius"; } ShowErrorMessage(errors); } break; case Figures.Rectangle: if (validateUpTextBox && validateDownTextBox) { var rectangleWidth = Convert.ToDouble(Tools.ReplaceDotsByCommas(FigureUpTextBox.Text)); var rectangleHeight = Convert.ToDouble(Tools.ReplaceDotsByCommas(FigureDownTextBox.Text)); var rectangle = new AreaCounting.Rectangle(rectangleWidth, rectangleHeight); _parentDataGrid.Rows.Add(); _parentDataGrid["FigureName", _parentDataGrid.Rows.Count - 1].Value = "Rectangle"; _parentDataGrid["FigureArea", _parentDataGrid.Rows.Count - 1].Value = rectangle.CountArea(); } else { var errors = new string[2] { "", "" }; if (!validateUpTextBox) { errors[0] = "Rectangle width"; } if (!validateDownTextBox) { errors[1] = "Rectangle height"; } ShowErrorMessage(errors); } break; case Figures.Triangle: if (validateUpTextBox && validateDownTextBox) { var triangleBase = Convert.ToDouble(Tools.ReplaceDotsByCommas(FigureUpTextBox.Text)); var triangleHeight = Convert.ToDouble(Tools.ReplaceDotsByCommas(FigureDownTextBox.Text)); var triangle = new AreaCounting.Rectangle(triangleBase, triangleHeight); _parentDataGrid.Rows.Add(); _parentDataGrid["FigureName", _parentDataGrid.Rows.Count - 1].Value = "Triangle"; _parentDataGrid["FigureArea", _parentDataGrid.Rows.Count - 1].Value = triangle.CountArea(); } else { var errors = new string[2] { "", "" }; if (!validateUpTextBox) { errors[0] = "Triangle base"; } if (!validateDownTextBox) { errors[1] = "Triangle height"; } ShowErrorMessage(errors); } break; } }
public void Validate_DoesNotValidate() { CollectionAssert.IsEmpty(validator.Validate(null)); }