public void IsValidThrowsExceptionWhenPropertyNotSet() { var r = new DecimalPrecisionRule("ARuleName"); // Act var result = r.IsValid(this.Values); }
public void IsValidThrowsExceptionIfValuesIsNull() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); // Act var result = r.IsValid(null); }
public void IsValidThrowsExceptionWhenScaleNotSet() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10); // Act var result = r.IsValid(this.Values); }
public void IsValidThrowsExceptionIfDictionaryIsEmpty() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Clear(); // Act var result = r.IsValid(this.Values); }
// This may seem wrong, but the lact of a value is not an error // for this rule. That must be checked with a RequiredRule or a WhenRequiredRule. public void IsValidReturnsTrueIfPropertyIsNotInValuesDictionary() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); // Act var result = r.IsValid(this.Values); // Assert Assert.IsTrue(result); }
private void TestIsValidWithNullEquivalent(string Value) { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Add("APropertyName", Value); // Act var result = r.IsValid(this.Values); // Assert Assert.IsTrue(result); }
public void IsValidReturnsTrueWhenDecimalDoesNotExist() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Add("APropertyName", "12312345"); // Act var result = r.IsValid(this.Values); // Assert Assert.IsTrue(result); }
public void IsValidReturnsTrueWhenDecimalPortionIsLessThanScale() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Add("APropertyName", "123.456"); // Act var result = r.IsValid(this.Values); // Assert Assert.IsTrue(result); }
public void IsValidReturnsTrueWhenNumberIsExactlyAsLongAsPrecisionWithoutDecimalPoint() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Add("APropertyName", "1234567890"); // Act var result = r.IsValid(this.Values); // Assert Assert.IsTrue(result); }
public void IsValidReturnsTrueWhenNumberIsExactlyAsLongAsPrecisionWithDecimalPointAndNegativeSign() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(9).Scale(6); this.Values.Add("APropertyName", "-123.123456"); // Act var result = r.IsValid(this.Values); // Assert Assert.IsTrue(result); }
public void IsValidReturnsFalseWhenValueCannotBeCastAsDecimal() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Add("APropertyName", "I am not a number"); // Act var result = r.IsValid(this.Values); // Assert Assert.IsFalse(result); Assert.AreEqual("APropertyName value of \"I am not a number\" cannot be interpreted as a Decimal value. Rule not applied.", r.ErrorMessage); }
public void IsValidReturnsFalseWhenDecimalIsGreaterThanScale() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Add("APropertyName", "123.123456"); // Act var result = r.IsValid(this.Values); // Assert Assert.IsFalse(result); Assert.AreEqual("APropertyName value of \"123.123456\" has more digits in the decimal part of the number than the specified Scale of 5", r.ErrorMessage); }
public void IsValidReturnsFalseWhenNumberIsLongerThanPrecision() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); this.Values.Add("APropertyName", "1234567890123"); // Act var result = r.IsValid(this.Values); // Assert Assert.IsFalse(result); Assert.AreEqual("APropertyName value of \"1234567890123\" is greater than the specified Precision of 10", r.ErrorMessage); }