Beispiel #1
0
        public RuleResults Validate(string successMessage, params object[] objectInstance)
        {
            var result = new RuleResults();

            foreach (var itemObject in objectInstance)
            {
                var method = _view.Validations.GetType().GetMethod("Validate");

                var genericMethod = method.MakeGenericMethod(itemObject.GetType());
                var parameters    = new[] { itemObject };
                var r             = (RuleResults)genericMethod.Invoke(_view.ViewLogics.Validations, parameters);
                result.Add(r);
            }
            if (!string.IsNullOrEmpty(successMessage))
            {
                if (result.Count == 0)
                {
                    _view.ShowMessage(PresenterResources.VALIDATION_SUCCESS, successMessage, Severity.Success);
                }
                else
                {
                    var sb = new StringBuilder();
                    foreach (var item in result)
                    {
                        sb.Append(item.RuleInformation.Description);
                    }


                    _view.ShowContextValidation(PresenterResources.ERR_VALIDATION, sb.ToString(), Utilities.ConvertRuleResultsToReturnMessageList(result));
                }
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Initialises a new instance of <see cref="ValidationResult"/>.
        /// </summary>
        /// <param name="ruleResults">The rule results.</param>
        /// <param name="manifest">The validation manifest</param>
        /// <exception cref="ArgumentNullException">If either parameter is <see langword="null" />.</exception>
        protected ValidationResult(IEnumerable <ValidationRuleResult> ruleResults, ValidationManifest manifest)
        {
            if (ruleResults is null)
            {
                throw new ArgumentNullException(nameof(ruleResults));
            }

            RuleResults = ruleResults.ToList();
            Passed      = RuleResults.All(r => r.Outcome == RuleOutcome.Passed);
            Manifest    = manifest ?? throw new ArgumentNullException(nameof(manifest));
        }
Beispiel #3
0
        /// <summary>
        /// Returns a semi-indented JSON version of this object
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var jBlocks = new string[5];

            jBlocks[0] = Rules.ToJson("rules");
            jBlocks[1] = RuleResults.ToJson("ruleResults");
            jBlocks[2] = Operations.ToJson("operations");
            jBlocks[3] = Requests.ToJson("requests");
            jBlocks[4] = Values.ToJson("values");

            var jObj = new StringBuilder();

            jObj.AppendLine("{");
            jObj.Append(string.Join(",", jBlocks));
            jObj.AppendLine("}");

            return(jObj.ToString());
        }
Beispiel #4
0
        /// <summary>
        ///     Permet de valider les objet
        /// </summary>
        /// <typeparam name="TObject"></typeparam>
        /// <param name="instance"></param>
        /// <returns></returns>
        public RuleResults Validate <TObject>(TObject instance)
        {
            var rls = new RuleResults();

            foreach (var item in UI)
            {
                var rl = new RuleResults();

                var val = item as UIValidation <TObject>;
                if (val != null)
                {
                    rl = val.Validate(instance);
                }
                if (rl != null)
                {
                    rls.Add(rl);
                }
            }
            return(rls);
        }
        public RuleResults ExecuteBusinessRules <T>(T objectToValidate)
        {
            var results = new RuleResults {
                IsSuccessful = true
            };

            if (_container.IsRegistered <IRule <T> >())
            {
                dynamic applicableRules = _container.Resolve <IEnumerable <IRule <T> > >();

                foreach (var rule in applicableRules)
                {
                    results.Add(rule.GetType().GetMethod("Validate", new[] { objectToValidate.GetType() }).Invoke(rule, new[] { objectToValidate }));
                }

                results.IsSuccessful = results.Count(p => p.ErrorLevel == RuleMessageType.Error) == 0;
            }

            return(results);
        }
Beispiel #6
0
        public RuleResults Validate(TObject objectInstance)
        {
            //TObject obj = Activator.CreateInstance<TObject>();
            //Extraire la valeur de la view par invocation et l'assiner a obj.

            var val = Validations as IValidationExtend <TObject>;
            var rs  = new RuleResults();

            var r = ValidationCore.DoValidation(objectInstance, Validations);

            foreach (var item in r)
            {
                if (ObjectPropertyName == item.Property)
                {
                    //indique le lien avec la vue en erreur
                    item.BindObjectName    = ViewName;
                    item.BindPropertytName = ObjectPropertyName;

                    rs.Add(item);
                }
            }
            return(rs);
        }
Beispiel #7
0
 IEnumerator IEnumerable.GetEnumerator() => RuleResults.GetEnumerator();
Beispiel #8
0
 IEnumerator <ValidationRuleResult> IEnumerable <ValidationRuleResult> .GetEnumerator() => RuleResults.GetEnumerator();
Beispiel #9
0
 public virtual void PublishIntegrityValidations(View view, string formatedMessage,
                                                 RuleResults rules,
                                                 IPresenterBase presenterbase)
 {
     view.ShowValidationMessage(PresenterResources.ERR_VALIDATION, formatedMessage, rules);
 }
Beispiel #10
0
 public override bool Validate(Rule rule, ValidationRule ruleProperty, Personne item, RuleResults rulesResults)
 {
     if (item.Nom.ToUpper() == "LOLO")
     {
         return(false);
     }
     return(true);
 }
Beispiel #11
0
 public override bool Validate(Rule rule, ValidationRule ruleProperty, TView item, RuleResults rulesResults)
 {
     rulesResults.Add(item.Validations.Validate <TView>(base.ObjectInstance));
     return(true);
 }
        public void GetResultWithMessagesAsyncShouldNotAddMessagesToPassOrFailedDependencyResults([Frozen] IGetsFailureMessageProvider messageProviderFactory,
                                                                                                  FailureMessageValidationResultPopulator sut,
                                                                                                  [RuleResult(Outcome = RuleOutcome.Passed)] ValidationRuleResult ruleResult1,
                                                                                                  [RuleResult] ValidationRuleResult ruleResult2,
                                                                                                  [RuleResult(Outcome = RuleOutcome.DependencyFailed)] ValidationRuleResult ruleResult3,
                                                                                                  IGetsFailureMessage messageProvider1,
                                                                                                  IGetsFailureMessage messageProvider3,
                                                                                                  string message1,
                                                                                                  string message3)
        {
            var validationResult = new ValidationResult <object>(new[] { ruleResult1, ruleResult2, ruleResult3 }, new Manifest.ValidationManifest {
                ValidatedType = typeof(object)
            });

            Mock.Get(messageProviderFactory).Setup(x => x.GetProvider(ruleResult1)).Returns(messageProvider1);
            Mock.Get(messageProviderFactory).Setup(x => x.GetProvider(ruleResult2)).Returns(() => null);
            Mock.Get(messageProviderFactory).Setup(x => x.GetProvider(ruleResult3)).Returns(messageProvider3);
            Mock.Get(messageProvider1)
            .Setup(x => x.GetFailureMessageAsync(ruleResult1, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(message1));
            Mock.Get(messageProvider3)
            .Setup(x => x.GetFailureMessageAsync(ruleResult3, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(message3));
            Assert.That(async() => (await sut.GetResultWithMessagesAsync(validationResult, default)).RuleResults.Select(x => x.Message),
                        Is.EquivalentTo(new string[] { null, null, null }));
        }
 public static PSSqlVulnerabilityAssessmentRuleBaselineResults ConvertToPSType(this RuleResults value)
 {
     return(new PSSqlVulnerabilityAssessmentRuleBaselineResults()
     {
         Id = value.Id,
         Name = value.Name,
         Type = value.Type,
         Results = value.Properties.Results?.Select(result => result.ToArray()).ToArray() ?? new string[0][]
     });
 }