public void TestWhitelist()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults             results;
            string                    assetsDirectory   = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string                    manifestFile      = Path.Combine(assetsDirectory, "manifest.json");
            string                    defaultConfigFile = Path.Combine(assetsDirectory, "default.config");
            ImmutableHashSet <string> ignoredPackages   = ImmutableHashSet <string> .Empty;

            IEnumerable <Regex> whitelistedPackages = new Regex[]
            {
                new Regex(@"VS\.Redist\.Common\.NetCore\.AppHostPack\.x86_x64\.3\.1"),
                new Regex(@"^VS\.Redist\.Common\.NetCore\.SharedFramework\.(x86|x64)\.[0-9]+\.[0-9]+$")
            };

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null,
                null);

            Assert.IsFalse(results.UpdatedPackages.Any(n => whitelistedPackages.All(pattern => !pattern.IsMatch(n.PackageId))),
                           "A package was updated even though it wasn't in the whitelist.");
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            const string data    = @"{Hello|Hi|Hi-Hi} my {mate|m8|friend|friends}, {i|we} want to {tell|say} you {hello|hi|hi-hi}.";
            var          pockets = chunks.All(data, "chunk").Select(v => legs.All(v, "alternative"));

            foreach (var result in CartesianProduct(pockets))
            {
                Console.WriteLine(string.Join("", result.ToArray()));
            }
        }
Esempio n. 3
0
        public bool IsTemplateCorrect(ConfirmationEmail confirmation)
        {
            if (!confirmation.Subject.Contains("Ryanair"))
            {
                return(false);
            }

            var regexs = new Regex[]
            {
                new Regex(CofirmationTemplate.FlightNumberPattern),
                new Regex(CofirmationTemplate.AmountPattern(this.currencyPolicy.CurrencySymbolForRegex)),
                new Regex(CofirmationTemplate.PassengersPattern)
            };

            return(regexs.All(regex => regex.Match(confirmation.Content).Success));
        }
Esempio n. 4
0
        public static IEnumerable <HtmlNode> GetElementsWithClass(this HtmlNode doc, string tag, params string[] classNames)
        {
            var exprs = new Regex[classNames.Length];

            for (int i = 0; i < exprs.Length; i++)
            {
                exprs[i] = new Regex("\\b" + Regex.Escape(classNames[i]) + "\\b", RegexOptions.Compiled);
            }

            return(doc
                   .Descendants()
                   .Where(n => n.NodeType == HtmlNodeType.Element)
                   .Where(e =>
                          e.Name == tag &&
                          exprs.All(r =>
                                    r.IsMatch(e.GetAttributeValue("class", ""))
                                    )
                          ));
        }
Esempio n. 5
0
        public bool Validate(string value)
        {
            value = new Regex(@"['\""&,\\]|\s{2,}").Replace(value, "").Trim();
            if (!new Regex(@"[0-9]+").IsMatch(value))
            {
                return(false);
            }

            if (!value.All(char.IsDigit))
            {
                return(false);
            }
            if (12 > value.Length || value.Length > 19)
            {
                return(false);
            }

            return(IsValidLuhnn(value));
        }
Esempio n. 6
0
        public void ChangeGlobalFilterToAllPhrasesContainedInSomeColumnCaseInsensitive(FilterRowsAction type, string userFilterInput)
        {
            var phrases = new Regex(@"\w+")
                          .Matches(userFilterInput.ToLower())
                          .Cast <Match>()
                          .Where(x => x.Success)
                          .Select(x => x.Value)
                          .ToArray();

            ChangeGlobalFilter(type,
                               (richCols, record) => {
                var cols = richCols
                           .Select(col => (col.TextValueFor(record) ?? "")
                                   .ToLower())
                           .ToArray();

                return(phrases.All(phrase =>
                                   cols.Any(colTxt => colTxt.Contains(phrase))));
            });
        }
Esempio n. 7
0
    private static string[] GetValidMessage(string line, List <string> patterns)
    {
        var validations = new Regex[] { new Regex(@"[^A-Za-z0-9](?<streetName>[A-Za-z]{4})[^A-Za-z0-9]"), new Regex(@"\D(?<streetNumber>\d{3})-(?<password>(\d{4})|(\d{6}))\D") };

        //get the valid patterns
        var validPatterns = patterns.Where(pattern => validations.All(validation => validation.IsMatch(pattern)));

        //Position the patterns accurately
        var patternsPosition = new Dictionary <int, string>();

        foreach (var validPattern in validPatterns)
        {
            var indexOfPattern = line.IndexOf(validPattern);
            patternsPosition[indexOfPattern] = validPattern;
        }

        //Sort the patterns
        patternsPosition = patternsPosition.OrderBy(p => p.Key).ToDictionary(k => k.Key, v => v.Value);

        if (patternsPosition.Count > 0)
        {
            //Get the middle pattern
            var middlePattern = patternsPosition.Values.ToArray()[patternsPosition.Count / 2];

            //Get the parameters of the pattern
            var streetName = validations[0].Match(middlePattern).Groups["streetName"].Value;

            var addressDetails = validations[1].Matches(middlePattern).Cast <Match>().Last();
            var streetNumber   = addressDetails.Groups["streetNumber"].Value;
            var password       = addressDetails.Groups["password"].Value;

            return(new string[] { streetName, streetNumber, password });
        }
        else
        {
            return(null);
        }
    }