public void GivenNumbersEqual_AndAllowEquality_AndValidationContext_WhenValidate_ThenSucceed()
        {
            TestEntity toValidate = new TestEntity { Value = "10" };
            ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" };
            var target = new NumericGreaterThanAttribute("Value") { AllowEquality = true };

            target.Validate("10", validationContext);
        }
        public void GivenPropertyIsEqual_AndDontAllowEquality_AndValidationContext_WhenValidate_ThenThrowException()
        {
            TestEntity toValidate = new TestEntity { Value = "10" };
            ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" };
            var target = new NumericGreaterThanAttribute("Value") { AllowEquality = false };

            ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("10", validationContext));
            Assert.AreEqual("AllowEquality has been set to false so values cannot be equal.", actual.Message);
        }
        public void GivenInvalidValue_AndValidationContext_WhenValidate_ThenThrowException()
        {
            TestEntity toValidate = new TestEntity { Value = "blah" };
            ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" };
            var target = new NumericGreaterThanAttribute("Value");

            ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("10", validationContext));
            Assert.AreEqual("Value is not a numeric value.", actual.Message);
        }
        public void GivenValidProperty_AndValidationContext_WhenValidate_ThenSucceed()
        {
            TestEntity toValidate = new TestEntity {
                Value = "10"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericGreaterThanAttribute("Value");

            target.Validate("20", validationContext);
        }
        public void GivenPropertyIsLessThan_AndAllowEquality_AndValidationContext_WhenValidate_ThenThrowExceptionWithEqualityMessage()
        {
            TestEntity toValidate = new TestEntity { Value = "20" };
            ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" };
            var target = new NumericGreaterThanAttribute("Value") { AllowEquality = true };

            ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("10", validationContext));
            Assert.AreEqual("Test Entity Value must be greater than or equal to Value.", actual.Message);
        }
        public void GivenInvalidValue_AndValidationContext_WhenValidate_ThenThrowException()
        {
            TestEntity toValidate = new TestEntity {
                Value = "blah"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericGreaterThanAttribute("Value");

            ValidationException actual = target.ExpectException <ValidationException>(() => target.Validate("10", validationContext));

            Assert.AreEqual("Value is not a numeric value.", actual.Message);
        }
        public void GivenPropertyIsLessThan_AndAllowEquality_AndValidationContext_WhenValidate_ThenThrowExceptionWithEqualityMessage()
        {
            TestEntity toValidate = new TestEntity {
                Value = "20"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericGreaterThanAttribute("Value")
            {
                AllowEquality = true
            };

            ValidationException actual = target.ExpectException <ValidationException>(() => target.Validate("10", validationContext));

            Assert.AreEqual("Test Entity Value must be greater than or equal to Value.", actual.Message);
        }
        public void GivenPropertyIsEqual_AndDontAllowEquality_AndValidationContext_WhenValidate_ThenThrowException()
        {
            TestEntity toValidate = new TestEntity {
                Value = "10"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericGreaterThanAttribute("Value")
            {
                AllowEquality = false
            };

            ValidationException actual = target.ExpectException <ValidationException>(() => target.Validate("10", validationContext));

            Assert.AreEqual("AllowEquality has been set to false so values cannot be equal.", actual.Message);
        }