Exemple #1
0
        public void StringLengthValidator_WhenStringIsLongerThanMaxLength_IsValid()
        {
            const string INPUT    = "a test string";
            const bool   EXPECTED = false;

            StringLengthValidator validator = new StringLengthValidator(10);

            bool result = validator.IsValid(INPUT);

            Assert.AreEqual(EXPECTED, result);
        }
Exemple #2
0
        public void StringLengthValidator_WhenStringIsSmaller_IsValid()
        {
            const string INPUT      = "a test";
            const bool   EXPECTED   = true;
            const int    MAX_LENGTH = 13;

            StringLengthValidator validator = new StringLengthValidator(MAX_LENGTH);

            bool result = validator.IsValid(INPUT);

            Assert.AreEqual(EXPECTED, result);
        }
        public void Should_Return_Valid_When_String_Is_Forty_Character_Long() {
            // Arrange
            var validator = new StringLengthValidator(40);

            // Act
            var result = validator.IsValid(new string('A', 40));

            // Assert
            result.ShouldNotBeNull();
            result.Valid.ShouldBeTrue();
            result.ErrorMessages.ShouldNotBeNull();
            result.ErrorMessages.ShouldBeEmpty();
        }
        public void Should_Return_Invalid_When_String_Lenghts_Dont_Match() {
            // Arrange
            var validator = new StringLengthValidator(40);

            // Act
            var result = validator.IsValid(new string('A', 39));

            // Assert
            result.ShouldNotBeNull();
            result.Valid.ShouldBeFalse();
            result.ErrorMessages.ShouldNotBeNull();
            result.ErrorMessages.Count.ShouldEqual(1);
            result.ErrorMessages.Single().ParamName.ShouldEqual("input");
            result.ErrorMessages.Single().Message.ShouldEqual("Length of input string does not match expected. Expected: 40. Actual: 39.");
        }