예제 #1
0
 public void Concat(ValidatorResult result)
 {
     if (result != null)
     {
         this.Messages = this.Messages.Concat(result.Messages);
         this.IsValid  = this.IsValid && result.IsValid;
     }
 }
        public override ValidatorResult Validate(MessageModel message)
        {
            ValidatorResult toReturn = base.Validate(message);

            toReturn.Concat(message.RunValidation(new List <(Func <MessageModel, bool> validation, Func <MessageModel, string> message)>()
            {
                { (validation: m => string.Equals(m.Value, m.PayloadAsJObject?.GetPropertyAsString("ImageText") ?? string.Empty, StringComparison.InvariantCultureIgnoreCase), message: m => "Value is not set to Image Text") },
                { (validation: m => string.Equals(m.Label, m.PayloadAsJObject?.GetPropertyAsString("ContentSpaceId") ?? string.Empty, StringComparison.InvariantCultureIgnoreCase), message: m => "Label is not set to Content Space ID") }
            }));
예제 #3
0
        public override ValidatorResult Validate(MessageModel message)
        {
            ValidatorResult toReturn = base.Validate(message);

            toReturn.Concat(message.RunValidation(new List <(Func <MessageModel, bool> validation, Func <MessageModel, string> message)>()
            {
                { Rules.ValuePayloadPropertyRule("ProductId") },
                { Rules.LabelPayloadPropertyRule("Quantity") }
            }));
        public override ValidatorResult Validate(MessageModel message)
        {
            ValidatorResult toReturn = base.Validate(message);

            if (message.PayloadAsJArray != null)
            {
                if (message.PayloadAsJArray.Any())
                {
                    int itemIdx = 0;
                    IEnumerable <IPayloadPropertyValidator> payloadPropertyValidators = new List <IPayloadPropertyValidator>()
                    {
                        new ProductIdValidator(),
                        new ProductQuantityValidator()
                    };
                    message.PayloadAsJArray.ForEach(t =>
                    {
                        IEnumerable <ValidatorResult> results = payloadPropertyValidators.Select(v => v.Validate(t as JObject));
                        toReturn.Concat(results.Where(r => r.Messages.Any()).Select(r => new ValidatorResult()
                        {
                            IsValid  = r.IsValid,
                            Messages = r.Messages.Select(m => $"[Item {itemIdx}] {m}")
                        }));
                        itemIdx++;
                    });
                }
                else
                {
                    toReturn.Concat(new ValidatorResult()
                    {
                        IsValid = false, Messages = new List <string>()
                        {
                            "The payload collection is empty"
                        }
                    });
                }
            }
            else
            {
                toReturn.Concat(new ValidatorResult()
                {
                    IsValid = false, Messages = new List <string>()
                    {
                        "The payload is not a collection of items"
                    }
                });
            }
            return(toReturn);
        }
        public override ValidatorResult Validate(MessageModel message)
        {
            ValidatorResult toReturn = base.Validate(message);

            toReturn.Concat(message.PayloadAsJObject != null
                ? this.PayloadPropertyValidators.Select(v => v.Validate(message.PayloadAsJObject))
                : new List <ValidatorResult>()
            {
                new ValidatorResult()
                {
                    IsValid = false, Messages = new List <string>()
                    {
                        "There is no payload from this message"
                    }
                }
            });
            return(toReturn);
        }