Пример #1
0
        public void GivenOtherProperty_WhenConstruct_ThenPropertyMatches()
        {
            string expected = "blah";

            var target = new NumericLessThanAttribute(expected);

            Assert.AreEqual(expected, target.OtherProperty);
        }
        public void GivenOtherProperty_WhenConstruct_ThenPropertyMatches()
        {
            string expected = "blah";

            var target = new NumericLessThanAttribute(expected);

            Assert.AreEqual(expected, target.OtherProperty);
        }
        public void GivenNumbersEqual_AndAllowEquality_AndValidationContext_WhenValidate_ThenSucceed()
        {
            TestEntity toValidate = new TestEntity { Value = "20" };
            ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" };
            var target = new NumericLessThanAttribute("Value") { AllowEquality = true };

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

            ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("20", 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 NumericLessThanAttribute("Value");

            ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("20", validationContext));
            Assert.AreEqual("Value is not a numeric value.", actual.Message);
        }
Пример #6
0
        public void GivenValidProperty_AndValidationContext_WhenValidate_ThenSucceed()
        {
            TestEntity toValidate = new TestEntity {
                Value = "20"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericLessThanAttribute("Value");

            target.Validate("10", validationContext);
        }
Пример #7
0
        public void GivenInvalidProperty_AndValidationContext_WhenValidate_ThenThrowException()
        {
            TestEntity toValidate = new TestEntity {
                Value = "10"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericLessThanAttribute("blah");

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

            Assert.AreEqual("Could not find a property named blah.", actual.Message);
        }
Пример #8
0
        public void GivenPropertyIsGreaterThan_AndValidationContext_WhenValidate_ThenThrowException()
        {
            TestEntity toValidate = new TestEntity {
                Value = "10"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericLessThanAttribute("Value");

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

            Assert.AreEqual("Test Entity Value must be less than Value.", actual.Message);
        }
Пример #9
0
        public void GivenNumbersEqual_AndDontAllowEquality_AndValidationContext_WhenValidate_ThenThrowException()
        {
            TestEntity toValidate = new TestEntity {
                Value = "20"
            };
            ValidationContext validationContext = new ValidationContext(toValidate)
            {
                DisplayName = "Test Entity Value", MemberName = "Value"
            };
            var target = new NumericLessThanAttribute("Value")
            {
                AllowEquality = false
            };

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

            Assert.AreEqual("AllowEquality has been set to false so values cannot be equal.", actual.Message);
        }
        public void GivenPropertyIsGreaterThan_AndAllowEquality_AndValidationContext_WhenValidate_ThenThrowExceptionWithEqualityMessage()
        {
            TestEntity toValidate = new TestEntity { Value = "10" };
            ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" };
            var target = new NumericLessThanAttribute("Value") { AllowEquality = true };

            ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("20", validationContext));
            Assert.AreEqual("Test Entity Value must be less than or equal to Value.", actual.Message);
        }