Exemplo n.º 1
0
        public void CheckSholdByValid1()
        {
            LengthValidation lengthValidation = new LengthValidation();

            lengthValidation.Max = 10;

            Assert.AreEqual(true, lengthValidation.Validate("1234567890", CultureInfo.CurrentCulture).IsValid);
        }
Exemplo n.º 2
0
        public void CheckSholdByValid2()
        {
            LengthValidation lengthValidation = new LengthValidation();

            lengthValidation.Max = 10;

            Assert.AreEqual(false, lengthValidation.Validate("12345678901", CultureInfo.CurrentCulture).IsValid);

            Assert.AreEqual("String length must be between 0 and 10.", lengthValidation.Validate("12345678901", CultureInfo.CurrentCulture).ErrorContent);
        }
Exemplo n.º 3
0
        public void CheckForMinValue()
        {
            LengthValidation lengthValidation = new LengthValidation();

            lengthValidation.Min = 3;

            ValidationResult r = lengthValidation.Validate("12", CultureInfo.CurrentCulture);

            Assert.AreEqual(false, r.IsValid);

            Assert.AreEqual("String length must be between 3 and 0.", r.ErrorContent);
        }
Exemplo n.º 4
0
        public void Setup()
        {
            _delimiterParser = new DelimiterParser();
            _dataParser      = new DataParser();
            IValidation lengthValidation = new LengthValidation();
            var         validations      = new List <IValidation>
            {
                lengthValidation
            };
            IConstraint maxNumberConstraint = new MaxNumberConstraint();
            var         constraints         = new List <IConstraint>
            {
                maxNumberConstraint
            };

            _validationService = new ValidationService(validations);
            _constraints       = new Constraints(constraints);
            _calculator        = new Calculator(_delimiterParser, _dataParser, _validationService, _constraints);
        }
Exemplo n.º 5
0
        private void Validation(
            string externalId,
            string name,
            string demographic,
            DateTime startDateTime,
            DateTime endDateTime,
            string product,
            string deliveryType,
            decimal?targetRatings,
            List <model.External.Campaign.SalesAreaCampaignTargetViewModel> salesAreaCampaignTargets,
            List <TimeRestriction> timeRestrictions,
            List <ProgrammeRestriction> programmeRestrictions,
            List <CampaignProgramme> campaignProgrammes,
            string campaignGroup,
            string includeRightSizer,
            bool includeOptimisation,
            int campaignPassPriority,
            int campaignSpotMaxRatings,
            bool validateCampaignPassPriority,
            bool validateDeliveryType)
        {
            IValidation validation = new RequiredFieldValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        FieldName = "External Id", FieldToValidate = externalId
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Campaign Name", FieldToValidate = name
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Demographic", FieldToValidate = demographic
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Start Date Time", FieldToValidate = startDateTime
                    },
                    new ValidationInfo()
                    {
                        FieldName = "End Date Time", FieldToValidate = endDateTime
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Product", FieldToValidate = product
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Target Ratings", FieldToValidate = targetRatings
                    },
                    new ValidationInfo()
                    {
                        FieldName       = "Sales Area Campaign Targets",
                        FieldToValidate = salesAreaCampaignTargets
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Include Right Sizer", FieldToValidate = includeRightSizer
                    }
                }
            };

            if (validateDeliveryType)
            {
                validation.Field.Add(new ValidationInfo()
                {
                    FieldName = "Delivery Type", FieldToValidate = deliveryType
                });
            }

            validation.Execute();

            if (validateCampaignPassPriority)
            {
                ValidateCampaignPassPriority(includeOptimisation, campaignPassPriority);
            }

            if (!EnumUtilities.ToDescriptionList <IncludeRightSizer>().Select(value => value.ToUpper())
                .Contains(includeRightSizer.ToUpper()))
            {
                throw new ArgumentException($"Invalid right sizer value: ${includeRightSizer}",
                                            ReflectionUtilities.PropertyName <CreateCampaign>(c => c.IncludeRightSizer));
            }

            if (validateDeliveryType && !Enum.IsDefined(typeof(CampaignDeliveryType), deliveryType))
            {
                throw new ArgumentException($"Invalid delivery type value: ${deliveryType}", ReflectionUtilities.PropertyName <CreateCampaign>(c => c.DeliveryType));
            }

            if (campaignGroup != null)
            {
                validation = new LengthValidation()
                {
                    Field = new List <ValidationInfo>()
                    {
                        new ValidationInfo()
                        {
                            ErrorMessage    = "Campaign Group can't be more than 20 characters: " + campaignGroup,
                            FieldToValidate = campaignGroup,
                            LengthToCompare = 20,
                            Operator        = Operator.LessThanEqual
                        }
                    }
                };
                validation.Execute();
            }

            validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Campaign Spot Max Ratings should be greater than or equal to 0",
                        FieldToValidate = campaignSpotMaxRatings,
                        FieldToCompare  = 0,
                        Operator        = Operator.GreaterThanEqual
                    }
                }
            };
            validation.Execute();

            validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Campaign start date should be less than or equal to end date",
                        FieldToValidate = startDateTime,
                        FieldToCompare  = endDateTime,
                        Operator        = Operator.LessThanEqual
                    }
                }
            };
            validation.Execute();

            if (salesAreaCampaignTargets.Any())
            {
                salesAreaCampaignTargets.ForEach(s => s.Validation(s.SalesAreaGroup, s.Multiparts, s.CampaignTargets,
                                                                   startDateTime, endDateTime));
            }

            if (timeRestrictions != null && timeRestrictions.Any())
            {
                timeRestrictions.ForEach(t =>
                                         t.RequiredFieldValidation(t.StartDateTime, t.EndDateTime, t.DowPattern, t.IsIncludeOrExclude));
                timeRestrictions.ForEach(t => t.RegexValidation(t.DowPattern, t.IsIncludeOrExclude));
                timeRestrictions.ForEach(t => t.CompareValidation(t.StartDateTime, t.EndDateTime));
            }

            if (programmeRestrictions != null && programmeRestrictions.Any())
            {
                programmeRestrictions.ForEach(p =>
                                              p.RequiredFieldValidation(p.IsIncludeOrExclude, p.IsCategoryOrProgramme));
                programmeRestrictions.ForEach(p => p.RegexValidation(p.IsIncludeOrExclude, p.IsCategoryOrProgramme));
            }

            if (campaignProgrammes != null && campaignProgrammes.Any())
            {
                campaignProgrammes.ForEach(x =>
                                           x.RequiredFieldValidation(x.IsCategoryOrProgramme));
                campaignProgrammes.ForEach(p => p.RegexValidation(p.IsCategoryOrProgramme));
            }
        }