Ejemplo n.º 1
0
        public void NullOrWhiteSpace_ShouldPass_IfObjectIsNullOrWhitespace(string arg)
        {
            // Act
            var validate = new V.Validate();

            validate.That(arg, Is => Is.NullOrWhiteSpace, "Should be null or whitespace");

            // Assert
            Assert.That(validate.HasErrors, Is.False);
        }
Ejemplo n.º 2
0
        public void LengthLessThanOrEqualTo_ShouldPass_IfActualLenthIsLessThanOrEqualToTargetLength(string arg)
        {
            // Act
            var validate = new V.Validate();

            validate.That(arg, Is => Is.LengthLessThanOrEqualTo(10), "Should be length less than or equal to 10");

            // Assert
            Assert.That(validate.HasErrors, Is.False);
        }
Ejemplo n.º 3
0
        public void NotNullOrWhiteSpace_ShouldPass_IfObjectIsNotWhitespace()
        {
            // Act
            var validate = new V.Validate();

            validate.That("   notwhitespace", Is => Is.NotNullOrWhiteSpace, "Should not be null or whitespace");

            // Assert
            Assert.That(validate.HasErrors, Is.False);
        }
Ejemplo n.º 4
0
        public void IsNotNullConstraint_ShouldPass_IfObjectIsNotNull()
        {
            // Act
            var validate = new V.Validate();

            validate.That("notnull", Is => Is.NotNull, "Should be not null");

            // Assert
            Assert.That(validate.HasErrors, Is.False);
        }
Ejemplo n.º 5
0
        public void LengthLessThanOrEqualTo_ShouldFail_IfActualLenthIsLongerThanTargetLength()
        {
            // Act
            var validate = new V.Validate();

            validate.That("01234567890", Is => Is.LengthLessThanOrEqualTo(10), "Should be length less than or equal to 10");

            // Assert
            Assert.That(validate.HasErrors, Is.True);
            Assert.That(validate.Errors[0].Message, Is.EqualTo("Should be length less than or equal to 10"));
        }
Ejemplo n.º 6
0
        public void LengthLessThanOrEqualTo_ShouldThrowException_IfActualIsNotAString()
        {
            // Arrange
            var testObj = new { Flag = false };

            // Act/Assert
            var validate = new V.Validate();

            Assert.That(() => validate.That(testObj.Flag, Is => Is.LengthLessThanOrEqualTo(10), "Should be length less than or equal to 10"),
                        Throws.ArgumentException.With.Message.EqualTo("LengthLessThanOrEqualTo can only be used with string type."));
        }
Ejemplo n.º 7
0
        public void NotNullOrWhiteSpace_ShouldFail_IfObjectIsNullOrWhitespace(string arg)
        {
            // Act
            var validate = new V.Validate();

            validate.That(arg, Is => Is.NotNullOrWhiteSpace, "Should not be null or whitespace");

            // Assert
            Assert.That(validate.HasErrors, Is.True);
            Assert.That(validate.Errors[0].Message, Is.EqualTo("Should not be null or whitespace"));
        }
Ejemplo n.º 8
0
        public void IsNotNullOrWhiteSpace_ShouldThrowException_IfActualIsNotAString()
        {
            // Arrange
            var testObj = new { Flag = false };

            // Act/Assert
            var validate = new V.Validate();

            Assert.That(() => validate.That(testObj.Flag, Is => Is.NotNullOrWhiteSpace, "Should not be null or whitespace"),
                        Throws.ArgumentException.With.Message.EqualTo("IsNotNullOrWhiteSpace can only be used with string type."));
        }
Ejemplo n.º 9
0
        public void IsNotNullConstraint_ShouldFail_IfObjectIsNull()
        {
            // Act
            var validate = new V.Validate();

            validate.That((object)null, Is => Is.NotNull, "Should be not null");

            // Assert
            Assert.That(validate.HasErrors, Is.True);
            Assert.That(validate.Errors[0].Message, Is.EqualTo("Should be not null"));
        }
Ejemplo n.º 10
0
        public void IsTrueConstraint_ShouldPass_IfObjectIsTrue()
        {
            // Arrange
            var testObject = new { Flag = true };

            // Act
            var validate = new V.Validate();

            validate.That(testObject.Flag, Is => Is.True, "Flag should be true");

            // Assert
            Assert.That(validate.HasErrors, Is.False);
        }
Ejemplo n.º 11
0
        public void ABoolLambda_ShouldPass_IfLambdaIsTrue()
        {
            // Arrange
            var testObject = new { Name = "woot" };

            // Act
            var validate = new V.Validate();

            validate.That(() => testObject.Name == "woot", "Name should be woot");

            // Assert
            Assert.That(validate.HasErrors, Is.False);
        }
Ejemplo n.º 12
0
        public void ABoolArgument_ShouldPass_IfArgIsTrue()
        {
            // Arrange
            var testObject = new { Flag = true };

            // Act
            var validate = new V.Validate();

            validate.That(testObject.Flag, "Flag should be true");

            // Assert
            Assert.That(validate.HasErrors, Is.False);
        }
Ejemplo n.º 13
0
        public void IsTrueConstraint_ShouldFail_IfObjectIsFalse()
        {
            // Arrange
            var testObject = new { Flag = false };

            // Act
            var validate = new V.Validate();

            validate.That(testObject.Flag, Is => Is.True, "Flag should be true");

            // Assert
            Assert.That(validate.HasErrors, Is.True);
            Assert.That(validate.Errors[0].Message, Is.EqualTo("Flag should be true"));
        }
Ejemplo n.º 14
0
        public void ABoolLambda_ShouldFaile_IfLambdaIsFalse()
        {
            // Arrange
            var testObject = new { Name = "wrong" };

            // Act
            var validate = new V.Validate();

            validate.That(() => testObject.Name == "woot", "Name should be woot");

            // Assert
            Assert.That(validate.HasErrors, Is.True);
            Assert.That(validate.Errors[0].Message, Is.EqualTo("Name should be woot"));
        }