Exemple #1
0
        public void IsValidThrowsExceptionWhenPropertyNotSet()
        {
            var r = new DecimalPrecisionRule("ARuleName");

            // Act
            var result = r.IsValid(this.Values);
        }
Exemple #2
0
        public void IsValidThrowsExceptionIfValuesIsNull()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5);

            // Act
            var result = r.IsValid(null);
        }
Exemple #3
0
        public void IsValidThrowsExceptionWhenScaleNotSet()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10);

            // Act
            var result = r.IsValid(this.Values);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        // 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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }