public void Test_ValidatorBuilder_Build()
 {
     var builder = new ValidatorBuilder<ValidateContext>(_Validation);
     var rule = builder.RuleFor(i => i.RuleSelector);
     var v = builder.Build();
     Assert.NotNull(v);
 }
        public void Test_ValidatorBuilder_Build()
        {
            var builder = new ValidatorBuilder <ValidateContext>(_Validation);
            var rule    = builder.RuleFor(i => i.RuleSelector);
            var v       = builder.Build();

            Assert.NotNull(v);
        }
Beispiel #3
0
        public static Func <Request, Response, Task <HandlerType> > BuildRedQueryMiddleware(this ValidatorBuilder builder)
        {
            var validator = builder.Build();

            return(async(req, res) =>
            {
                if (!validator.Validate(req.Queries))
                {
                    return await res.SendStatus(HttpStatusCode.BadRequest);
                }

                return HandlerType.Continue;
            });
        }
Beispiel #4
0
    static void Main()
    {
        Validator <Student> validator = ValidatorBuilder
                                        .Build <Student>()
                                        // .AddValidation("Age", new Above18())
                                        .AddValidation("Name", new NotNull())
                                        .AddValidation <String>("Name", val => val.Length < 10);

        Student s1 = new Student(76135, "Anacleto", 20);

        validator.Validate(s1);
        s1.Print();
        Student s2 = new Student(654354, "Maria Jose Catita", 25);

        validator.Validate(s2);
        s2.Print();
    }
        public async Task <IActionResult> Add(Faculty faculty)
        {
            var a = new ValidatorBuilder <Faculty>();

            a.AddRulesFor(f => f.Name)
            .AsRequired()
            .WithMaxLength(20);

            var b = a.Build();

            var c = b.Validate(faculty);

            if (c.Success == false)
            {
                return(BadRequest(c));
            }


            await _facultyService.AddFaculty(faculty);



            return(Ok("Faculty added"));
        }
Beispiel #6
0
 public void Setup()
 {
     _validatorBuilder = CreateValidatorBuilder();
     _validator        = _validatorBuilder.Build();
 }
        public void Validate(Stream stream)
        {
            var doc              = new XPathDocument(stream);
            var navigator        = doc.CreateNavigator();
            var namespaceUri     = @"http://schemas.microsoft.com/vstudio/debugger/natvis/2010";
            var namespaceManager = new XmlNamespaceManager(navigator.NameTable);

            namespaceManager.AddNamespace("vs", namespaceUri);
            var validatorBuilder = new ValidatorBuilder(namespaceManager);

            List <Validator> validators = new List <Validator>();

            validators.Add(validatorBuilder.Build(@"count(//vs:Synthetic[@Expression])",
                                                  "The 'Expression' attribute is not supported on the <Synthetic> tag."));
            validators.Add(validatorBuilder.Build(@"count(//@*[name()='ModuleName'])",
                                                  "The 'ModuleName' attribute is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//@*[name()='ModuleVersionMin'])",
                                                  "The 'ModuleVersionMin' attribute is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//@*[name()='ModuleVersionMax'])",
                                                  "The 'ModuleVersionMax' attribute is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:DisplayString[@Export])",
                                                  "The 'Export' attribute is not supported on the <DisplayString> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:DisplayString[@Encoding])",
                                                  "The 'Encoding' attribute is not supported on the <DisplayString> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:DisplayString[@LegacyAddin])",
                                                  "The 'LegacyAddin' attribute is not supported on the <DisplayString> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:UIVisualizer)",
                                                  "The <UIVisualizer> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:CustomVisualizer)",
                                                  "The <CustomVisualizer> tag is not supported."));
            validators.Add(
                validatorBuilder.Build(@"count(//vs:LinkedListItems/vs:ValueNode[@Name])",
                                       "The 'Name' attribute is not supported on the <LinkedListItems>/<ValueNode> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:ArrayItems/vs:Direction)",
                                                  "The <ArrayItems>/<Direction> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:ArrayItems/vs:Rank)",
                                                  "The <ArrayItems>/<Rank> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:ArrayItems/vs:LowerBound)",
                                                  "The <ArrayItems>/<LowerBound> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:Type/vs:MostDerivedType)",
                                                  "The <Type>/<MostDerivedType> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:Type/vs:Version)",
                                                  "The <Type>/<Version> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:Type[@Priority])",
                                                  "The 'Priority' attribute is not supported on the <Type> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:Type[@Inheritable])",
                                                  "The 'Inheritable' attribute is not supported on the <Type> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:AlternativeType[@Priority])",
                                                  "The 'Priority' attribute is not supported on the <AlternativeType> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:AlternativeType[@Inheritable])",
                                                  "The 'Inheritable' attribute is not supported on the <AlternativeType> tag."));
            validators.Add(validatorBuilder.Build(@"count(//vs:Intrinsic)",
                                                  "The <Intrinsic> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:HResult)",
                                                  "The <HResult> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:LocalizedStrings)",
                                                  "The <LocalizedStrings> tag is not supported."));
            validators.Add(validatorBuilder.Build(@"count(//vs:Version)",
                                                  "The <Version> tag is not supported."));

            foreach (var validator in validators)
            {
                var xPathResult = navigator.Evaluate(validator.XPathExpression);
                if (xPathResult is double)
                {
                    if ((double)xPathResult > 0)
                    {
                        logger.Warning(() => $"{validator.WarningMessage} It was found " +
                                       $"{xPathResult} time(s).");
                    }
                }
                else
                {
                    Trace.WriteLine($"ERROR: Unexpected XPath result type=" +
                                    $"{xPathResult?.GetType()} for expression={validator.XPathExpression}.");
                }
            }
        }