private void TestIsValid(int lengthRequired, int lengthToTest, bool valid)
        {
            // Arrange
            var testString = "X".PadRight(lengthToTest);
            var r          = new StringMaximumLengthRule("ARuleName").Property("APropertyName").MaximumLength(lengthRequired);

            // Act
            var result = r.IsValid(new Dictionary <string, string>(1)
            {
                { "APropertyName", testString }
            });

            // Assert
            if (valid)
            {
                Assert.IsTrue(result);
                Assert.IsNull(r.ErrorMessage);
            }
            else
            {
                Assert.IsFalse(result);
                Assert.AreEqual(r.PropertyName + " value is " + lengthToTest.ToString() +
                                " characters, which is longer than the maximum required length of " +
                                lengthRequired.ToString() + " characters.",
                                r.ErrorMessage);
            }
        }
        public void PropertyThrowsExceptionIfAlreadySet()
        {
            // Arrange
            var r = new StringMaximumLengthRule("RuleName").Property("AProperty");

            // Act
            r.Property("AnotherName");
        }
        private void TestPropertyWithNullEquivalent(string Value)
        {
            // Arrange
            var r = new StringMaximumLengthRule("RuleName");

            // Act
            r.Property(Value);
        }
        public void IsValidThrowsExceptionIfMinimumLengthNotSet()
        {
            // Arrange
            var r = new StringMaximumLengthRule("ARuleName").Property("APropertyName");

            // Act
            r.IsValid(new Dictionary <string, string>(1)
            {
                { "APropertyName", "This is also a big string." }
            });
        }
        public void IsValidThrowsExceptionIfPropertyNameNotSet()
        {
            // Arrange
            var r = new StringMaximumLengthRule("ARuleName");

            // Act
            r.IsValid(new Dictionary <string, string>(1)
            {
                { "APropertyName", "A big string" }
            });
        }
        public void MinimumLengthSetsLength()
        {
            // Arrange
            var r = new StringMaximumLengthRule("ARuleName").Property("APropertyName");

            // Act
            var returnedRule = r.MaximumLength(28);

            // Assert
            Assert.AreSame(returnedRule, r);
            Assert.AreEqual(28, r.Length);
        }
        public void PropertySetsPropertyName()
        {
            // Arrange
            var r     = new StringMaximumLengthRule("ARuleName");
            var pName = "APropertyName";

            // Act
            var returnedRule = r.Property(pName);

            // Assert
            Assert.AreEqual(returnedRule, r);
            Assert.AreEqual(pName, r.PropertyName);
        }
        public void ConstructorReturnsRule()
        {
            // Arrange
            var ruleName = "ARuleName";

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

            // Assert
            Assert.IsNotNull(r);
            Assert.AreEqual(ruleName, r.RuleName);
            Assert.IsNull(r.PropertyName);
            Assert.IsNull(r.ErrorMessage);
            Assert.IsFalse(r.Length.HasValue);
        }
        private void IsValidReturnsTrueIfNullEquivalent(string Value)
        {
            // Arrange
            var r = new StringMaximumLengthRule("ARuleName").Property("APropertyName").MaximumLength(10);

            // Act
            var result = r.IsValid(new Dictionary <string, string>(1)
            {
                { "APropertyName", Value }
            });

            // Assert
            Assert.IsTrue(result);
            Assert.IsNull(r.ErrorMessage);
        }
Exemplo n.º 10
0
 public static StringMaximumLengthRule Length(this StringMaximumLengthRule rule, int length)
 {
     rule.MaximumLength = length;
     return(rule);
 }
 private void TestConstructorWithNullEquivalent(string Value)
 {
     // Act
     var r = new StringMaximumLengthRule(Value);
 }