示例#1
0
        private void Validate()
        {
            var errors = new List <ValidationFailure>();

            foreach (var result in Variables.Select(variable => new VariableValidator <T>().Validate(variable)).Where(result => !result.IsValid))
            {
                errors.AddRange(result.Errors.ToList());
            }

            foreach (var result in Domains.Select(domain => new DomainValidator <T>().Validate(domain)).Where(result => !result.IsValid))
            {
                errors.AddRange(result.Errors.ToList());
            }

            foreach (var result in Relations.Select(relation => new RelationsValidator <T>().Validate(relation)).Where(result => !result.IsValid))
            {
                errors.AddRange(result.Errors.ToList());
            }

            foreach (var result in Constraints.Select(constraint => new ConstraintValidator <T>().Validate(constraint)).Where(result => !result.IsValid))
            {
                errors.AddRange(result.Errors.ToList());
            }

            if (errors.Any())
            {
                throw new ArgumentException(errors.Select(e => e.ErrorMessage).Aggregate((a, b) => $"{a},{b}"));
            }

            if (Relations.Any(r => Variables.All(v => v.Key != r.Key)))
            {
                throw new ArgumentException("Relationships/Variables mismatch");
            }

            if (Relations.Any(r => r.Values.Any(rv => Variables.All(v => v.Key != rv.Key))))
            {
                throw new ArgumentException("Relationships/Variables mismatch");
            }

            if (Domains.Any(d => !d.Values.Any()))
            {
                throw new ArgumentException("Domain start size cannot be zero");
            }
        }
示例#2
0
 internal Relations <T> VariableRelations(string key) =>
 Relations.FirstOrDefault(r =>
                          r.Key == key) ?? new Relations <T>(key, new List <Variable <T> >());