public void IsValidThrowsExceptionWhenPropertyNotSet() { var r = new DecimalPrecisionRule("ARuleName"); // Act var result = r.IsValid(this.Values); }
public void CannotSetPrecisionAbove38() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName"); // Act r.Precision(39); }
public void CannotSetPrecisionToNegativeValue() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName"); // Act r.Precision(-10); }
public void CannotSetPecisionToZero() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName"); // Act r.Precision(0); }
public void CannotSetPrecisionWhenPropertyNotSet() { // Arrange var r = new DecimalPrecisionRule("ARuleName"); // Act r.Precision(10); }
public void IsValidThrowsExceptionWhenScaleNotSet() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10); // Act var result = r.IsValid(this.Values); }
private void PropertyThrowsExceptionOnNullEquivalent(string Property) { // Arrange var r = new DecimalPrecisionRule("ARuleName"); // Act r.Property(Property); }
public void ScaleCannotBeGreaterThanPrecision() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10); // Act r.Scale(11); }
public void ScaleCannotBeSetWhenPrecisionIsNotSet() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName"); // Act r.Scale(10); }
public void ScaleCannotBeSetToNegativeNumber() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName"); // Act r.Scale(-10); }
public void ScaleCannotBeSetToZero() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName"); // Act r.Scale(0); }
public void IsValidThrowsExceptionIfValuesIsNull() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName").Precision(10).Scale(5); // Act var result = r.IsValid(null); }
public void PropertyThrowsExceptionIfPropertyAlreadySet() { // Arrange var r = new DecimalPrecisionRule("ARuleName").Property("APropertyName"); // Act r.Property("BPropertyName"); }
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); }
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); }
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); }
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); }
public void PropertySetsProperty() { // Arrange var r = new DecimalPrecisionRule("ARuleName"); var name = "APropertyName"; // Act r.Property(name); // Assert Assert.AreEqual(name, r.PropertyName); }
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]); }
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); }
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); }
private void ConstructorThrowsExceptionOnNullEquivalent(string RuleName) { // Act var r = new DecimalPrecisionRule(RuleName); }