Пример #1
0
 private IBusinessRule warningRule(string warning)
 {
     return(CreateRule.For <IParameter>()
            .Property(item => item.Value)
            .WithRule((param, value) => false)
            .WithError((param, value) => warning));
 }
 public static IEnumerable <IBusinessRule> All()
 {
     yield return(CreateRule.For <DTOValuePoint>()
                  .Property(x => x.XValue)
                  .WithRule(cannotRepeat)
                  .WithError((dto, timeValue) => AppConstants.Validation.XDimensionColumnMustNotHaveRepeatedValues(dto._tableFormulaDTO.XDisplayName)));
 }
Пример #3
0
        public static Task CanCreate(CreateRule command, IAppProvider appProvider)
        {
            Guard.NotNull(command, nameof(command));

            return(Validate.It(() => "Cannot create rule.", async error =>
            {
                if (command.Trigger == null)
                {
                    error(new ValidationError("Trigger is required.", nameof(command.Trigger)));
                }
                else
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Id, command.Trigger, appProvider);

                    errors.Foreach(error);
                }

                if (command.Action == null)
                {
                    error(new ValidationError("Trigger is required.", nameof(command.Action)));
                }
                else
                {
                    var errors = await RuleActionValidator.ValidateAsync(command.Action);

                    errors.Foreach(error);
                }
            }));
        }
Пример #4
0
        public void Handle(CreateRule command)
        {
            var company = _repository.Get(command.CompanyId);

            company.CreateRule(command.RuleId,
                               command.Name,
                               command.Message,
                               command.ZoneList,
                               command.ZoneRequired,
                               command.Type,
                               command.Category,
                               command.AppliesToCurrentBooking,
                               command.AppliesToFutureBooking,
                               command.AppliesToPickup,
                               command.AppliesToDropoff,
                               command.Priority,
                               command.IsActive,
                               command.DaysOfTheWeek,
                               command.StartTime,
                               command.EndTime,
                               command.ActiveFrom,
                               command.ActiveTo,
                               command.Market,
                               command.DisableFutureBookingOnError);

            _repository.Save(company, command.Id.ToString());
        }
Пример #5
0
 public static IBusinessRule FileExists <T>(Expression <Func <T, string> > property)
 {
     return(CreateRule.For <T>()
            .Property(property)
            .WithRule((item, file) => FileHelper.FileExists(file))
            .WithError((item, file) => Validation.FileDoesNotExist(file)));
 }
Пример #6
0
 public static IBusinessRule ParameterIsValid()
 {
     return(CreateRule.For <IParameterDTO>()
            .Property(p => p.Value)
            .WithRule((p, value) => rulesFor(p, value).IsEmpty)
            .WithError((p, value) => rulesFor(p, value).Message));
 }
Пример #7
0
 public static IBusinessRule ParameterIsValid <TParameterContainer, TProperty>(Expression <Func <TParameterContainer, TProperty> > parameterValue, Func <TParameterContainer, IParameterDTO> parmeterDelegate)
 {
     return(CreateRule.For <TParameterContainer>()
            .Property(parameterValue)
            .WithRule((parameterContainer, value) => rulesFor(parmeterDelegate(parameterContainer), value).IsEmpty)
            .WithError((parameterContainer, value) => rulesFor(parmeterDelegate(parameterContainer), value).Message));
 }
 private IBusinessRule createNonEmptyNameRule()
 {
     return(CreateRule.For <FormulaInfoDTO>()
            .Property(x => x.Name)
            .WithRule((dto, name) => dto.nameIsValid(name))
            .WithError(AppConstants.Validation.EmptyName));
 }
Пример #9
0
 private IBusinessRule createRelativeContainerPathNotEmptyRule()
 {
     return(CreateRule.For <ApplicationMoleculeBuilderDTO>()
            .Property(x => x.RelativeContainerPath)
            .WithRule((dto, path) => !path.IsNullOrEmpty())
            .WithError(AppConstants.Validation.RelativeContainerPathNotSet));
 }
Пример #10
0
 public static IBusinessRule NotNull <T, U>(Expression <Func <T, U> > property) where U : class
 {
     return(CreateRule.For <T>()
            .Property(property)
            .WithRule((o, u) => u != null)
            .WithError(Validation.ValueIsRequired));
 }
Пример #11
0
        public static Task CanCreate(CreateRule command, ISchemaProvider schemas)
        {
            Guard.NotNull(command, nameof(command));

            return(Validate.It(() => "Cannot create rule.", async error =>
            {
                if (command.Trigger == null)
                {
                    error(new ValidationError("Trigger must be defined.", nameof(command.Trigger)));
                }
                else
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(command.Trigger, schemas);

                    errors.Foreach(error);
                }

                if (command.Action == null)
                {
                    error(new ValidationError("Trigger must be defined.", nameof(command.Action)));
                }
                else
                {
                    var errors = await RuleActionValidator.ValidateAsync(command.Action);

                    errors.Foreach(error);
                }
            }));
        }
Пример #12
0
        public static Task CanCreate(CreateRule command, IAppProvider appProvider)
        {
            Guard.NotNull(command);

            return(Validate.It(() => "Cannot create rule.", async e =>
            {
                if (command.Trigger == null)
                {
                    e(Not.Defined("Trigger"), nameof(command.Trigger));
                }
                else
                {
                    var errors = await RuleTriggerValidator.ValidateAsync(command.AppId.Id, command.Trigger, appProvider);

                    errors.Foreach(x => x.AddTo(e));
                }

                if (command.Action == null)
                {
                    e(Not.Defined("Action"), nameof(command.Action));
                }
                else
                {
                    var errors = command.Action.Validate();

                    errors.Foreach(x => x.AddTo(e));
                }
            }));
        }
Пример #13
0
 public static IBusinessRule NonEmptyRule <T>(Expression <Func <T, string> > property, string error = Validation.ValueIsRequired)
 {
     return(CreateRule.For <T>()
            .Property(property)
            .WithRule((o, v) => v.StringIsNotEmpty())
            .WithError(error));
 }
 private static IBusinessRule notEmptyTransportNameRule()
 {
     return(CreateRule.For <TransporterMoleculeContainerDTO>()
            .Property(x => x.TransportName)
            .WithRule((dto, name) => !name.Trim().IsNullOrEmpty())
            .WithError(AppConstants.Validation.EmptyTransportName));
 }
Пример #15
0
 private IBusinessRule createTargetHasToBeSetRule()
 {
     return(CreateRule.For <EventAssignmentBuilderDTO>()
            .Property(x => x.ChangedEntityPath)
            .WithRule((dto, path) => !path.IsNullOrEmpty())
            .WithError(AppConstants.Validation.ChangedEntityNotSet));
 }
 private static IBusinessRule uniqueTransportNameRule()
 {
     return(CreateRule.For <TransporterMoleculeContainerDTO>()
            .Property(x => x.TransportName)
            .WithRule((dto, name) => dto.IsNameUnique(name))
            .WithError(AppConstants.Validation.TransportNameAllreadyUsed));
 }
Пример #17
0
 private IBusinessRule moleuleNameShouldBePresentInProjectRule()
 {
     return(CreateRule.For <ApplicationBuilderDTO>()
            .Property(x => x.MoleculeName)
            .WithRule((dto, moleculeName) => _getMoleculeNames().Contains(moleculeName))
            .WithError(AppConstants.Exceptions.AppliedMoleculeNotInProject));
 }
Пример #18
0
            private static IBusinessRule mustHaveAllPreviousPathElementsSet(Expression <Func <StartValueDTO <T>, string> > propertyToCheck)
            {
                var index = getPathIndex(propertyToCheck);

                return(CreateRule.For <StartValueDTO <T> >()
                       .Property(propertyToCheck).WithRule((dto, pathElement) => areAllPreviousPathElementsNonEmpty(dto, pathElement, index))
                       .WithError((dto, pathElement) => AppConstants.Validation.CannotSetPathElementWhenPreviousElementsAreEmpty));
            }
Пример #19
0
            private static IBusinessRule mustNotAlreadyContainStartValue(Expression <Func <StartValueDTO <T>, string> > propertyToCheck)
            {
                var index = getPathIndex(propertyToCheck);

                return(CreateRule.For <StartValueDTO <T> >()
                       .Property(propertyToCheck)
                       .WithRule((dto, pathElement) => noDuplicatesInBuildingBlockRule(dto, pathElement, index))
                       .WithError((dto, pathElement) => AppConstants.Validation.PathIsIdenticalToExistingPath(newPathWithReplacement(dto, pathElement, index))));
            }
Пример #20
0
        protected Task On(CreateRule command, CommandContext context)
        {
            return(handler.CreateSyncedAsync <RuleDomainObject>(context, async r =>
            {
                await GuardRule.CanCreate(command, appProvider);

                r.Create(command);
            }));
        }
Пример #21
0
        protected Task On(CreateRule command, CommandContext context)
        {
            return(handler.CreateAsync <RuleDomainObject>(context, async w =>
            {
                await GuardRule.CanCreate(command, schemas);

                w.Create(command);
            }));
        }
        public InvariantResult IsValid(CreateRule obj)
        {
            // Validate rule name.
            if (string.IsNullOrWhiteSpace(obj.Name))
            {
                return(InvariantResult.ForInvalid(this.Code, InvariantResources.R001));
            }

            return(InvariantResult.ForValid(this.Code));
        }
        public InvariantResult IsValid(CreateRule obj)
        {
            // Validate rule priority.
            if (obj.Priority <= 0)
            {
                return(InvariantResult.ForInvalid(this.Code, string.Format(InvariantResources.R003, obj.Priority)));
            }

            return(InvariantResult.ForValid(this.Code));
        }
Пример #24
0
        public async Task <RuleResultDto> Add(Guid tenantId, CreateRuleDto createRuleDto)
        {
            CreateRule createRule = this.createRuleConversionProfile.Convert(tenantId, createRuleDto);

            RuleResult ruleResult = await this.createRuleService.CreateRule(createRule);

            return(new RuleResultDto
            {
                AffectedRule = ruleResult.AffectedRule != null?this.ConvertToDto(ruleResult.AffectedRule) : null,
                                   ErrorMessages = ruleResult.ErrorMessages.Select(m => new { m.Code, m.Message })
            });
        }
Пример #25
0
        public void RuleMinderAddsExistingRule()
        {
            var ruleSet =
                CreateRule <UrlIsValidRuleHandler, UrlRequest> .On <UrlRequest>(request => request.Url = "/SomeWebService")
                .Build();

            var rm =
                SiteMinder.Create()
                .AddRule <UrlIsValidRuleSet, UrlIsValidRuleHandler, UrlRequest>(webServiceUpRuleSet => ruleSet);

            Assert.Equal(1, rm.Rules.Count);
        }
Пример #26
0
        public async Task CanCreate_should_throw_exception_if_trigger_null()
        {
            var command = new CreateRule
            {
                Trigger = null,
                Action  = new WebhookAction
                {
                    Url = validUrl
                }
            };

            await Assert.ThrowsAsync <ValidationException>(() => GuardRule.CanCreate(command, schemas));
        }
Пример #27
0
        public InvariantResult IsValid(CreateRule obj)
        {
            ContentTypeKey contentTypeKey = ContentTypeKey.New(obj.TenantId, obj.ContentTypeCode);
            ContentType    contentType    = this.contentTypeRepository.GetById(contentTypeKey).GetAwaiter().GetResult();

            // Validate content type.
            if (contentType == null)
            {
                return(InvariantResult.ForInvalid(this.Code, string.Format(InvariantResources.R004, obj.TenantId, obj.ContentTypeCode)));
            }

            return(InvariantResult.ForValid(this.Code));
        }
Пример #28
0
        public CreateRule ToCommand()
        {
            var command = new CreateRule {
                Action = Action
            };

            if (Trigger != null)
            {
                command.Trigger = Trigger.ToTrigger();
            }

            return(command);
        }
Пример #29
0
        public async Task CanCreate_should_throw_exception_if_action_null()
        {
            var command = new CreateRule
            {
                Trigger = new ContentChangedTrigger
                {
                    Schemas = new List <ContentChangedTriggerSchema>()
                },
                Action = null
            };

            await Assert.ThrowsAsync <ValidationException>(() => GuardRule.CanCreate(command, schemas));
        }
        public InvariantResult IsValid(CreateRule obj)
        {
            if (obj.RootCondition != null)
            {
                IEnumerable <string> messages = this.ValidateRecursive(obj.RootCondition, obj.TenantId);

                if (messages.Any())
                {
                    return(InvariantResult.ForInvalid(this.Code, messages.Distinct().ToArray()));
                }
            }

            return(InvariantResult.ForValid(this.Code));
        }