Exemplo n.º 1
0
        public void TokenFunctionTest(string equalsToken, string plusToken, int collectionSize)
        {
            var kvps = new KeyValuePair <string, string> [collectionSize];

            Random rand1 = new Random();

            for (int i = 0; i < collectionSize; i++)
            {
                kvps[i] = new KeyValuePair <string, string>($"key{i}", $"{Guid.NewGuid()}{Guid.NewGuid()}{Guid.NewGuid()}");
            }

            string value1 = kvps[rand1.Next(0, collectionSize - 1)].Value;
            string value2 = kvps[rand1.Next(0, collectionSize - 1)].Value;

            string queryString = $"value{equalsToken}{value1}{plusToken}{value2}";

            var sw         = Stopwatch.StartNew();
            var expression = ExpressionBuilder.BuildFunction <KeyValuePair <string, string> >(queryString);

            kvps.FirstOrDefault(expression).Should().NotBeNull().And
            .Should().BeAnyOf(kvps.Where(kvp => kvp.Value == value1 || kvp.Value == value2));

            kvps.Where(expression).Should().NotBeNullOrEmpty().And
            .Contain(kvps.Where(kvp => kvp.Value == value1 || kvp.Value == value2));

            kvps.Any(expression).Should().BeTrue();
            kvps.All(expression).Should().BeFalse();
            kvps.Count(expression).Should().Be(kvps.Count(q => q.Value == value1 || q.Value == value2));

            sw.Stop();
        }
Exemplo n.º 2
0
        public void IntTest(int collectionSize)
        {
            var kvps = new KeyValuePair <string, int> [collectionSize];

            Random rand1 = new Random();

            for (int i = 0; i < collectionSize; i++)
            {
                Random rand2 = new Random(rand1.Next(0, int.MaxValue));

                kvps[i] = new KeyValuePair <string, int>($"key{i}", rand2.Next(1, collectionSize));
            }

            int value1 = kvps[rand1.Next(0, collectionSize - 1)].Value;
            int value2 = kvps[rand1.Next(0, collectionSize - 1)].Value;

            string queryString = $"value={value1}%2B{value2}";

            var sw         = Stopwatch.StartNew();
            var expression = ExpressionBuilder.BuildFunction <KeyValuePair <string, int> >(queryString);

            kvps.FirstOrDefault(expression).Should().NotBeNull().And
            .Should().BeAnyOf(kvps.Where(kvp => kvp.Value == value1 || kvp.Value == value2));

            kvps.Where(expression).Should().NotBeNullOrEmpty().And
            .Contain(kvps.Where(kvp => kvp.Value == value1 || kvp.Value == value2));

            kvps.Any(expression).Should().BeTrue();
            kvps.All(expression).Should().BeFalse();
            kvps.Count(expression).Should().Be(kvps.Count(q => q.Value == value1 || q.Value == value2));

            sw.Stop();
        }
Exemplo n.º 3
0
        public void DateTimeListTest(int collectionSize, int maxSubCollectionSize)
        {
            var kvps = new KeyValuePair <string, List <DateTime> > [collectionSize];

            int day   = 1;
            int month = 1;
            int year  = 2016;

            for (int i = 0; i < collectionSize; i++)
            {
                string key = $"key{i}";

                KeyValuePair <string, List <DateTime> > kvp = new KeyValuePair <string, List <DateTime> >(key, new List <DateTime>());

                for (int j = 0; j < maxSubCollectionSize; j++)
                {
                    kvp.Value.Add(new DateTime(year, month, day++));

                    if (day > 28)
                    {
                        day = 1;
                        month++;
                    }

                    if (month <= 12)
                    {
                        continue;
                    }

                    month = 1;
                    year++;
                }

                kvps[i] = kvp;
            }

            Random rand = new Random();

            DateTime value1 = kvps[rand.Next(0, collectionSize - 1)].Value[0];
            DateTime value2 = kvps[rand.Next(0, collectionSize - 1)].Value[0];

            string queryString = $"value={value1}%2B{value2}";

            var sw = Stopwatch.StartNew();

            var expression = ExpressionBuilder.BuildFunction <KeyValuePair <string, List <DateTime> > >(queryString);

            kvps.FirstOrDefault(expression).Should().NotBeNull().And
            .Should().BeAnyOf(kvps.Where(kvp => kvp.Value.Contains(value1) || kvp.Value.Contains(value2)));

            kvps.Where(expression).Should().NotBeNullOrEmpty().And
            .Contain(kvps.Where(kvp => kvp.Value.Contains(value1) || kvp.Value.Contains(value2)));

            kvps.Any(expression).Should().BeTrue();
            kvps.All(expression).Should().BeFalse();
            kvps.Count(expression).Should().Be(kvps.Count(q => q.Value.Contains(value1) || q.Value.Contains(value2)));

            sw.Stop();
        }
Exemplo n.º 4
0
        public static KeyValuePair <string, string> GetNewestVersion()
        {
            var versions   = new HashSet <KeyValuePair <string, string> >();
            var files      = Directory.EnumerateFiles(Parameter.AntdVersionsDir, "*.*");
            var enumerable = files as string[] ?? files.ToArray();
            var zips       = enumerable.Where(s => s.EndsWith(Parameter.ZipEndsWith)).ToArray();

            if (zips.Length > 0)
            {
                foreach (var zip in zips)
                {
                    versions.Add(SetVersionKeyValuePair(zip));
                }
            }
            var squashes = enumerable.Where(s => s.EndsWith(Parameter.SquashEndsWith)).ToArray();

            if (squashes.Length > 0)
            {
                foreach (var squash in squashes)
                {
                    versions.Add(SetVersionKeyValuePair(squash));
                }
            }
            var versionsOrdered = new KeyValuePair <string, string>[] { };

            if (versions.ToArray().Length > 0)
            {
                versionsOrdered = versions.OrderByDescending(i => i.Value).ToArray();
            }
            var newestVersionFound = new KeyValuePair <string, string>(null, null);

            if (versionsOrdered.Length > 0)
            {
                newestVersionFound = versionsOrdered.FirstOrDefault();
            }
            return(newestVersionFound);
        }