예제 #1
0
        public static void CanDelete(AppPatterns patterns, DeletePattern command)
        {
            Guard.NotNull(command, nameof(command));

            if (!patterns.ContainsKey(command.PatternId))
            {
                throw new DomainObjectNotFoundException(command.PatternId.ToString(), typeof(AppPattern));
            }
        }
예제 #2
0
        public static void CanUpdate(AppPatterns patterns, UpdatePattern command)
        {
            Guard.NotNull(command, nameof(command));

            if (!patterns.ContainsKey(command.PatternId))
            {
                throw new DomainObjectNotFoundException(command.PatternId.ToString(), typeof(AppPattern));
            }

            Validate.It(() => "Cannot update pattern.", error =>
            {
                if (string.IsNullOrWhiteSpace(command.Name))
                {
                    error(new ValidationError("Pattern name can not be empty.", nameof(command.Name)));
                }

                if (patterns.Any(x => x.Key != command.PatternId && x.Value.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    error(new ValidationError("Pattern name is already assigned.", nameof(command.Name)));
                }

                if (string.IsNullOrWhiteSpace(command.Pattern))
                {
                    error(new ValidationError("Pattern can not be empty.", nameof(command.Pattern)));
                }
                else if (!command.Pattern.IsValidRegex())
                {
                    error(new ValidationError("Pattern is not a valid regular expression.", nameof(command.Pattern)));
                }

                if (patterns.Any(x => x.Key != command.PatternId && x.Value.Pattern == command.Pattern))
                {
                    error(new ValidationError("Pattern already exists.", nameof(command.Pattern)));
                }
            });
        }
예제 #3
0
        public static void CanUpdate(AppPatterns patterns, UpdatePattern command)
        {
            Guard.NotNull(command, nameof(command));

            if (!patterns.ContainsKey(command.PatternId))
            {
                throw new DomainObjectNotFoundException(command.PatternId.ToString(), typeof(AppPattern));
            }

            Validate.It(() => "Cannot update pattern.", e =>
            {
                if (string.IsNullOrWhiteSpace(command.Name))
                {
                    e(Not.Defined("Name"), nameof(command.Name));
                }

                if (patterns.Any(x => x.Key != command.PatternId && x.Value.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    e("A pattern with the same name already exists.");
                }

                if (string.IsNullOrWhiteSpace(command.Pattern))
                {
                    e(Not.Defined("Pattern"), nameof(command.Pattern));
                }
                else if (!command.Pattern.IsValidRegex())
                {
                    e(Not.Valid("Pattern"), nameof(command.Pattern));
                }

                if (patterns.Any(x => x.Key != command.PatternId && x.Value.Pattern == command.Pattern))
                {
                    e("This pattern already exists but with another name.");
                }
            });
        }
예제 #4
0
        public static void CanUpdate(AppPatterns patterns, UpdatePattern command)
        {
            Guard.NotNull(command, nameof(command));

            if (!patterns.ContainsKey(command.PatternId))
            {
                throw new DomainObjectNotFoundException(command.PatternId.ToString());
            }

            Validate.It(e =>
            {
                if (string.IsNullOrWhiteSpace(command.Name))
                {
                    e(Not.Defined(nameof(command.Name)), nameof(command.Name));
                }

                if (patterns.Any(x => x.Key != command.PatternId && x.Value.Name.Equals(command.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    e(T.Get("apps.patterns.nameAlreadyExists"));
                }

                if (string.IsNullOrWhiteSpace(command.Pattern))
                {
                    e(Not.Defined(nameof(command.Pattern)), nameof(command.Pattern));
                }
                else if (!command.Pattern.IsValidRegex())
                {
                    e(Not.Valid(nameof(command.Pattern)), nameof(command.Pattern));
                }

                if (patterns.Any(x => x.Key != command.PatternId && x.Value.Pattern == command.Pattern))
                {
                    e(T.Get("apps.patterns.patternAlreadyExists"));
                }
            });
        }