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

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

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

            var checker = NullChecker.For(toValidate);

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

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

            Assert.True(result);
        }
예제 #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)
                                              );
        }
예제 #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())
                                              );
        }
예제 #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);
        }
예제 #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);
        }
예제 #8
0
        public void For_CreatesGenericObject()
        {
            var subject = NullChecker.For(new TestableObject());

            Assert.IsType <NullChecker <TestableObject> >(subject);
        }