public void ValidationPathResult_NonConstantDictionaryIndexer()
        {
            int i      = 30;
            var result = ValidationPathResult.Create(new NestedDictionaryValidationObject <int>(), "Test, test, testaroo", x => x.NestedDictionary[i].DoubleProperty);

            Assert.AreEqual(String.Format("NestedDictionary[{0}].DoubleProperty", i), result.MemberNames.First());
        }
        public void ValidationPathResult_NonConstantListIndexer()
        {
            int i      = 50;
            var result = ValidationPathResult.Create(new NestedListValidationObject(), "Test, test, testaroo", x => x.NestedObject[i]);

            Assert.AreEqual(String.Format("NestedObject[{0}]", i), result.MemberNames.First());
        }
Exemple #3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            if (Options == null || Options.Count < 2)
            {
                errors.Add(ValidationPathResult.Create(this, "A Vote must have at least 2 options", (m) => m.Options));
            }
            if (Options.Count > 10)
            {
                errors.Add(ValidationPathResult.Create(this, "A Vote is limited to 10 options", (m) => m.Options));
            }

            //Ensure no duplicate titles
            if (Options != null || Options.Count >= 2)
            {
                var grouped        = Options.GroupBy(x => x.Title.TrimSafe().ToNormalized(Normalization.Lower)).Select(x => new { Key = x.Key, Count = x.Count() });
                var duplicateTitle = grouped.FirstOrDefault(x => x.Count > 1);
                if (duplicateTitle != null)
                {
                    errors.Add(ValidationPathResult.Create(this, "Option titles must be unique.", (m) => m.Options));
                }
            }

            return(errors);
        }
Exemple #4
0
 public override IEnumerable <ValidationPathResult> Validate(MetalGizmo value, ValidationContext context)
 {
     if (String.IsNullOrEmpty(value.Alloy))
     {
         return(ValidationPathResult.Create(value, "{0} is empty", "Required", x => x.Alloy).ToEnumerable());
     }
     return(null);
 }
        public void ValidationPathResult_NonConstantNestedIndexer()
        {
            int i      = 0;
            int i3     = 17;
            var result = ValidationPathResult.Create(new NestedEndlessListValidationObject(), "Test, test, testaroo", x => x.NestedObject[i].NestedObject[i3]);

            Assert.AreEqual(String.Format("NestedObject[{0}].NestedObject[{1}]", i, i3), result.MemberNames.First());
        }
Exemple #6
0
 public override IEnumerable <ValidationPathResult> Validate(PipelineStageTestModel value, ValidationContext context)
 {
     if (!value.Pass)
     {
         return(ValidationPathResult.Create(value, "{0} didn't pass yo!", x => x.Pass).ToEnumerable());
     }
     return(null);
 }
Exemple #7
0
 public override IEnumerable <ValidationPathResult> Validate(DomainObject17 value, ValidationContext context)
 {
     if (value.ID <= 0)
     {
         return(ValidationPathResult.Create(value, "ID can't be less than zero", x => x.ID).ToEnumerable());
     }
     return(null);
 }
Exemple #8
0
 public override IEnumerable <ValidationPathResult> Validate(UnitTestModel value, ValidationContext context)
 {
     if (String.Equals("<forbidden phrase>", value.Name, StringComparison.OrdinalIgnoreCase))
     {
         return(ValidationPathResult.Create(value, "Property '{0}' with value '" + value.Name + "' is forbidden in this environment", x => x.Name).ToEnumerable());
     }
     return(null);
 }
        public void ValidationPathResult_PathRootIsModel()
        {
            string message = "Test, test, testaroo";
            var    result  = new ValidationPathResult(message, "Name", "Required");

            Assert.AreEqual(result.ErrorMessage, message);

            result = ValidationPathResult.Create("", message, x => x);
            Assert.AreEqual("", result.MemberNames.First());
        }
Exemple #10
0
        public void ValidationPathResult_ErrorMessagePropagation()
        {
            string message = "Test, test, testaroo";
            var    result  = new ValidationPathResult(message, "Name", "Required");

            Assert.AreEqual(result.ErrorMessage, message);

            result = ValidationPathResult.Create("", message, x => x);
            Assert.AreEqual(result.ErrorMessage, message);
        }
Exemple #11
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            if (ReturnValidationError)
            {
                if (UseValidationPathResult)
                {
                    errors.Add(ValidationPathResult.Create(this, "Invalid: {0}", m => m.UserName));
                }
                else
                {
                    errors.Add(new ValidationResult("Invalid: {0}", new[] { "UserName" }));
                }
            }
            return(errors);
        }
Exemple #12
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var    errors           = new List <ValidationResult>();
            string originalUserName = UserHelper.OriginalUsername(UserName);

            if (String.IsNullOrEmpty(originalUserName))
            {
                errors.Add(ValidationPathResult.Create(this, $"User '{UserName}' can not be found", x => x.UserName));
            }
            else
            {
                UserName = originalUserName;
            }



            return(errors);
        }