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

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

            // Act
            r.Precision(39);
        }
Exemple #3
0
        public void CannotSetPrecisionToNegativeValue()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName");

            // Act
            r.Precision(-10);
        }
Exemple #4
0
        public void CannotSetPecisionToZero()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName");

            // Act
            r.Precision(0);
        }
Exemple #5
0
        public void CannotSetPrecisionWhenPropertyNotSet()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName");

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

            // Act
            var result = r.IsValid(this.Values);
        }
Exemple #7
0
        private void PropertyThrowsExceptionOnNullEquivalent(string Property)
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName");

            // Act
            r.Property(Property);
        }
Exemple #8
0
        public void ScaleCannotBeGreaterThanPrecision()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10);

            // Act
            r.Scale(11);
        }
Exemple #9
0
        public void ScaleCannotBeSetWhenPrecisionIsNotSet()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName");

            // Act
            r.Scale(10);
        }
Exemple #10
0
        public void ScaleCannotBeSetToNegativeNumber()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName");

            // Act
            r.Scale(-10);
        }
Exemple #11
0
        public void ScaleCannotBeSetToZero()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName");

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

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

            // Act
            r.Property("BPropertyName");
        }
Exemple #14
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 #15
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 #16
0
        public void ScaleCanBeEqualToPrecision()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10);

            // Act
            r.Scale(10);

            // Assert
            Assert.IsTrue(r.ScaleValue.HasValue);
            Assert.AreEqual(10, r.ScaleValue.Value);
        }
Exemple #17
0
        public void PrecisionCanBeSetTo38Precisely()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName");

            // Act
            r.Precision(38);

            // Assert
            Assert.IsTrue(r.PrecisionValue.HasValue);
            Assert.AreEqual(38, r.PrecisionValue.Value);
        }
Exemple #18
0
        public void PrecisionSetsPrecision()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName");

            // Act
            r.Precision(6);

            // Assert
            Assert.IsTrue(r.PrecisionValue.HasValue);
            Assert.AreEqual(6, r.PrecisionValue.Value);
        }
Exemple #19
0
        public void PropertySetsProperty()
        {
            // Arrange
            var r    = new DecimalPrecisionRule("ARuleName");
            var name = "APropertyName";

            // Act
            r.Property(name);

            // Assert
            Assert.AreEqual(name, r.PropertyName);
        }
Exemple #20
0
        public void GetPropertyNamesReferencedReturnsPropertyName()
        {
            // Arrange
            var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5);

            // Act
            var propertyNames = r.GetPropertyNamesReferenced();

            // Assert
            Assert.IsNotNull(propertyNames);
            Assert.AreEqual(1, propertyNames.Count);
            Assert.AreEqual("APropertyName", propertyNames[0]);
        }
Exemple #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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);
        }
Exemple #29
0
        public void ConstructorCreatesRule()
        {
            // Arrange
            var ruleName = "ARuleName";

            // Act
            var r = new DecimalPrecisionRule(ruleName);

            // Assert
            Assert.IsNotNull(r);
            Assert.AreEqual(ruleName, r.RuleName);
            Assert.IsTrue(string.IsNullOrWhiteSpace(r.PropertyName));
            Assert.IsFalse(r.PrecisionValue.HasValue);
            Assert.IsFalse(r.ScaleValue.HasValue);
            Assert.IsNull(r.ErrorMessage);
        }
Exemple #30
0
 private void ConstructorThrowsExceptionOnNullEquivalent(string RuleName)
 {
     // Act
     var r = new DecimalPrecisionRule(RuleName);
 }