private void TestIsValid(int lengthRequired, int lengthToTest, bool valid)
        {
            // Arrange
            var testString = "X".PadRight(lengthToTest);
            var r          = new StringMinimumLengthRule("ARuleName").Property("APropertyName").MinimumLength(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 does not meet the minimum required length of " +
                                lengthRequired.ToString() + " characters.",
                                r.ErrorMessage);
            }
        }
        public void PropertyThrowsExceptionIfAlreadySet()
        {
            // Arrange
            var r = new StringMinimumLengthRule("RuleName").Property("AProperty");

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

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

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

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

            // Assert
            Assert.AreSame(returnedRule, r);
            Assert.AreEqual(28, r.Length);
        }
        public void PropertySetsPropertyName()
        {
            // Arrange
            var r     = new StringMinimumLengthRule("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 StringMinimumLengthRule(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 StringMinimumLengthRule("ARuleName").Property("APropertyName").MinimumLength(10);

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

            // Assert
            Assert.IsTrue(result);
            Assert.IsNull(r.ErrorMessage);
        }
 private void TestConstructorWithNullEquivalent(string Value)
 {
     // Act
     var r = new StringMinimumLengthRule(Value);
 }