Ejemplo n.º 1
0
        public static void Test_Simple_Required_PatternValidator(string value, bool valid)
        {
            // (-∞, ∞)
            var range = new PatternValidator("a", true);

            Assert.True(range.IsValid(value) == valid);
        }
Ejemplo n.º 2
0
        public async Task Should_not_add_error_if_value_is_empty()
        {
            var sut = new PatternValidator("[a-z]{3}:[0-9]{2}");

            await sut.ValidateAsync(string.Empty, errors);

            Assert.Empty(errors);
        }
Ejemplo n.º 3
0
        public async Task Should_add_timeout_error_when_regex_is_too_slow()
        {
            var sut = new PatternValidator(@"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$");

            await sut.ValidateAsync("https://archiverbx.blob.core.windows.net/static/C:/Users/USR/Documents/Projects/PROJ/static/images/full/1234567890.jpg", errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Regex is too slow." });
        }
Ejemplo n.º 4
0
        public async Task Should_add_error_with_custom_message_if_value_is_not_valid()
        {
            var sut = new PatternValidator("[a-z]{3}:[0-9]{2}", "Custom Error Message.");

            await sut.ValidateAsync("foo", errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Custom Error Message." });
        }
Ejemplo n.º 5
0
        public async Task Should_add_error_with_default_message_if_value_is_not_valid()
        {
            var sut = new PatternValidator("[a-z]{3}:[0-9]{2}");

            await sut.ValidateAsync("foo", errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is not valid." });
        }
        private RobotsPageDefinition FromTokens(IEnumerable <Token> tokens)
        {
            var validationResult = PatternValidator.Validate(tokens);

            if (validationResult.IsValid)
            {
                return(new RobotsPageDefinition
                {
                    PageAccessEntries = TokenParser.GetPageAccessEntries(tokens)
                });
            }

            return(new RobotsPageDefinition());
        }
        private RobotsFile FromTokens(IEnumerable <Token> tokens, Uri baseUri)
        {
            var validationResult = PatternValidator.Validate(tokens);

            if (validationResult.IsValid)
            {
                return(new RobotsFile(baseUri)
                {
                    SiteAccessEntries = TokenParser.GetSiteAccessEntries(tokens),
                    SitemapEntries = TokenParser.GetSitemapUrlEntries(tokens)
                });
            }

            return(RobotsFile.AllowAllRobots(baseUri));
        }
Ejemplo n.º 8
0
        public TimeZoneInfo GetUserTimeZone(UserEntity user)
        {
            TimeZoneInfo timeZoneInfo = null;

            if (_systemSettings.AllowUsersToSetTimeZone)
            {
                var timeZoneId = string.Empty;
                if (user != null)
                {
                    timeZoneId = _userAttributeService.GetValue(user, UserAttribute.TimeZoneId, "", false, true);
                }

                if (PatternValidator.IsValidTimeZoneId(timeZoneId))
                {
                    timeZoneInfo = FindTimeZoneById(timeZoneId);
                }
            }

            return(timeZoneInfo ?? DefaultTimeZone);
        }
Ejemplo n.º 9
0
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            var value = values[parameterName].ToStringOrDefault();

            return(PatternValidator.IsValidSlug(value));
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Console program entry.
        /// </summary>
        /// <param name="args">
        ///     args[0]: Placeholder bitmap path
        ///     args[1]: Target bitmaps directory path
        ///     args[2]: Bitmaps search pattern
        /// </param>
        public static void Main(string[] args)
        {
            ShowBanner();

            var bitmapPlaceholder = string.Empty;
            var bitmapsDirectory  = string.Empty;
            var bitmapsPattern    = string.Empty;

            if (args.Length < 3)
            {
                Line.Write("Not enough arguments provided. Using manual input...", ConsoleColor.Yellow, "WARN");

                while (PlaceholderValidator.GetStatus(bitmapPlaceholder) != PlaceholderStatus.IsValid)
                {
                    Line.Write("Please type a valid placeholder file under the size of 8MiB:", ConsoleColor.Cyan, "STEP");
                    bitmapPlaceholder = Console.ReadLine();

                    if (bitmapPlaceholder != null && File.Exists(bitmapPlaceholder))
                    {
                        if (PlaceholderValidator.GetStatus(bitmapPlaceholder) == PlaceholderStatus.IsTooLarge)
                        {
                            Line.Write($"Placeholder file is larger than 8MiB!", ConsoleColor.Red, "STOP");
                            bitmapPlaceholder = string.Empty;
                        }
                    }
                }

                while (DirectoryValidator.GetStatus(bitmapsDirectory) != DirectoryStatus.IsValid)
                {
                    Line.Write("Please type a valid target directory path:", ConsoleColor.Cyan, "STEP");
                    bitmapsDirectory = Console.ReadLine();
                }

                while (PatternValidator.GetStatus(bitmapsPattern) != PatternStatus.IsValid)
                {
                    Line.Write("Please type a valid file search pattern:", ConsoleColor.Cyan, "STEP");
                    bitmapsPattern = Console.ReadLine();
                }
            }
            else
            {
                bitmapPlaceholder = args[0];
                bitmapsDirectory  = args[1];
                bitmapsPattern    = args[2];

                var placeholderStatus = PlaceholderValidator.GetStatus(bitmapPlaceholder);
                var fileExists        = placeholderStatus != PlaceholderStatus.DoesNotExist;
                var sizeIsUnder16MiB  = placeholderStatus != PlaceholderStatus.IsTooLarge;

                var directoryExists = DirectoryValidator.GetStatus(bitmapsDirectory) != DirectoryStatus.DoesNotExist;
                var patternIsValid  = PatternValidator.GetStatus(bitmapsPattern) != PatternStatus.IsInvalid;

                // prematurely exit if the following conditions aren't satisfied
                ExitIfFalse(fileExists, "Placeholder does not exist.", ExitCodes.InvalidPlaceholderPath);
                ExitIfFalse(sizeIsUnder16MiB, "Placeholder is larger than 8MiB.", ExitCodes.PlaceholderFileTooLong);
                ExitIfFalse(directoryExists, "Bitmaps directory does not exist.", ExitCodes.InvalidFilesFolderPath);
                ExitIfFalse(patternIsValid, "Searcg pattern is invalid.", ExitCodes.InvalidFileNamePattern);
            }

            // if everything is successful, get all files and back them up
            var files = Directory
                        .GetFiles(bitmapsDirectory, $"*{bitmapsPattern}*.bitmap", SearchOption.AllDirectories)
                        .Where(x => !x.Contains("multiplayer"))
                        .ToArray();

            Bbkpify.Main.ApplyPlaceholderAsync(files, bitmapPlaceholder).GetAwaiter().GetResult();

            Line.Write($"\nApplied '{bitmapPlaceholder}' to '{bitmapsDirectory}'!", ConsoleColor.Green, "DONE");
            Console.ReadLine();
            Environment.Exit((int)ExitCodes.Success);
        }
Ejemplo n.º 11
0
 public static IChainableConstraint <IStringConstraints> IsSlug(this IStringConstraints constraints, bool ignoreEmpty = true)
 {
     return(constraints.Satisfy(v => (ignoreEmpty && string.IsNullOrEmpty(v)) || PatternValidator.IsValidSlug(v)));
 }
Ejemplo n.º 12
0
 public PatternValidatorTests()
 {
     _validator = new PatternValidator();
 }