예제 #1
0
        public static void Validate_LowerAndUpperPropertyName_Success()
        {
            CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.comparepropertycased));

            Assert.NotNull(attribute.GetValidationResult("b", s_context).ErrorMessage);
            Assert.Equal(ValidationResult.Success, attribute.GetValidationResult(null, s_context));
            Assert.Equal(nameof(CompareObject.comparepropertycased), attribute.OtherPropertyDisplayName);
        }
        public static void Validate_IncludesMemberName_NetFx()
        {
            ValidationContext validationContext = new ValidationContext(new CompareObject("a"));

            validationContext.MemberName = nameof(CompareObject.CompareProperty);
            CompareAttribute attribute = new CompareAttribute(nameof(CompareObject.ComparePropertyCased));

            ValidationResult validationResult = attribute.GetValidationResult("b", validationContext);

            Assert.NotNull(validationResult.ErrorMessage);
            Assert.Empty(validationResult.MemberNames);
        }
예제 #3
0
        public void GetValidationResult()
        {
            var sla = new CompareAttribute("B");
            var obj = new TestModel {
                A = "x", B = "x"
            };
            var ctx = new ValidationContext(obj, null, null);

            Assert.IsNotNull(sla.GetValidationResult(null, ctx), "#A1-1");
            Assert.IsNotNull(sla.GetValidationResult(String.Empty, ctx), "#A1-2");
            Assert.IsNotNull(sla.GetValidationResult(obj, ctx), "#A1-3");
            Assert.IsNull(sla.GetValidationResult(obj.A, ctx), "#A1-4");

            obj = new TestModel {
                A = "x", B = "n"
            };

            Assert.IsNotNull(sla.GetValidationResult(null, ctx), "#B-1");
            Assert.IsNotNull(sla.GetValidationResult(obj, ctx), "#B-2");
            Assert.IsNotNull(sla.GetValidationResult(true, ctx), "#B-3");
            Assert.IsNotNull(sla.GetValidationResult(DateTime.Now, ctx), "#B-4");
        }