Exemple #1
0
        public void Validate_WhenAnyPropertyIsNull_ReturnsFalse()
        {
            var toValidate = new TestableObject();

            var result = NullChecker.For(toValidate).Validate();

            Assert.Null(toValidate.FullName);
            Assert.False(result);
        }
Exemple #2
0
        public void Ignore_IfExpressionIsNotOnObject_ThrowsArgumentException()
        {
            var toValidate = new TestableObject();

            var checker = NullChecker.For(toValidate);

            Assert.Throws <ArgumentException>(() =>
                                              checker.Ignore(c => "hello world")
                                              );
        }
Exemple #3
0
        public void Validate_WhenNoPropertiesAreNull_ReturnsTrue()
        {
            var toValidate = new TestableObject()
            {
                FullName = "GreenShell"
            };

            var result = NullChecker.For(toValidate).Validate();

            Assert.True(result);
        }
Exemple #4
0
        public void Ignore_IfExpressionIsInvalidPropertyThrowsArgumentException()
        {
            var toValidate = new TestableObject();

            var resultWithoutIgnore = NullChecker.For(toValidate).Validate();

            var checker = NullChecker.For(toValidate);

            Assert.Throws <ArgumentException>(() =>
                                              checker.Ignore(c => new OtherTestableObject().InvalidProperty)
                                              );
        }
Exemple #5
0
        public void Ignore_IfExpressionIsMethodExecutedWithReturnType_ThrowsArgumentExceptionn()
        {
            var toValidate = new TestableObject();

            var resultWithoutIgnore = NullChecker.For(toValidate).Validate();

            var checker = NullChecker.For(toValidate);

            Assert.Throws <ArgumentException>(() =>
                                              checker.Ignore(c => c.MethodWithReturnType())
                                              );
        }
Exemple #6
0
        public void Ignore_WhenValidated_IfPropertyIsNull_DoesNotValidateIt()
        {
            var toValidate = new TestableObject();

            var resultWithoutIgnore = NullChecker.For(toValidate).Validate();

            var resultWithIgnore = NullChecker.For(toValidate)
                                   .Ignore(c => c.FullName)
                                   .Validate();

            Assert.False(resultWithoutIgnore);
            Assert.True(resultWithIgnore);
        }
Exemple #7
0
        public void AllowValueTypeValidation_WhenValidated_IfValueObjectIsDefault_ReturnsFalse()
        {
            var withDefault = new TestableObject()
            {
                //DateOfBirth = Default,
                Age      = 99,
                FullName = "GreenShell"
            };

            var withoutDefault = new TestableObject()
            {
                DateOfBirth = DateTime.Now,
                Age         = 99,
                FullName    = "GreenShell"
            };

            var resultWithDefaults    = NullChecker.For(withDefault).AllowValueTypeValidation().Validate();
            var resultWithoutDefaults = NullChecker.For(withoutDefault).AllowValueTypeValidation().Validate();

            Assert.False(resultWithDefaults);
            Assert.True(resultWithoutDefaults);
        }