Ejemplo n.º 1
0
        private static void VerifyURI(DataServiceContext context, IQueryable actualQuery, string expectedQueryUri, IEnumerable expectedResults, bool expectKeyInUri)
        {
            string expectedUri = String.Format(
                "{0}/TripLegs{1}{2}",
                context.BaseUri.AbsoluteUri,
                expectKeyInUri ? "(1)" : String.Empty,
                expectedQueryUri);

            Assert.AreEqual(Uri.UnescapeDataString(expectedUri), Uri.UnescapeDataString(actualQuery.ToString()), "LINQ query did not produce the expected URI.");

            LinqTests.RunTest(expectedResults, actualQuery, true);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Drives drives = new Drives();

            drives.GetDrivesInfo();
            drives.SearchFile();

            LinqTests lt = new LinqTests();

            lt.init();


            Console.ReadLine();
        }
Ejemplo n.º 3
0
        }//LD Main

        #region region testing methods

        //LD linq
        private static void Test001()
        {
            LinqTests aLinqTestInstance = new LinqTests();

            aLinqTestInstance.LastExtensionMethod();
        }
Ejemplo n.º 4
0
        public void InvalidAnyAllUsage()
        {
            DataServiceContext ctx = new DataServiceContext(new Uri("http://localhost"), ODataProtocolVersion.V4);
            var moviesQuery        = ctx.CreateQuery <Movie>("Movies");
            var collectionsQuery   = ctx.CreateQuery <EntityWithCollections>("Values");
            var testCases          = new Tuple <IQueryable, string>[]
            {
                // in $filter, onyl navigation and collection properties are supported.
                new Tuple <IQueryable, string>(
                    moviesQuery.Where(m => m.Name.Any()),
                    "The source parameter for the 'Any' method has to be either a navigation or a collection property."),
                new Tuple <IQueryable, string>(
                    moviesQuery.Where(m => m.Name.Any(c => c == 'a')),
                    "The source parameter for the 'Any' method has to be either a navigation or a collection property."),
                new Tuple <IQueryable, string>(
                    moviesQuery.Where(m => m.Name.All(c => c == 'a')),
                    "The source parameter for the 'All' method has to be either a navigation or a collection property."),

                // in $orderby
                new Tuple <IQueryable, string>(
                    moviesQuery.OrderBy(m => m.Actors.Any()),
                    "The method 'Any' is not supported by the 'orderby' query option."),
                new Tuple <IQueryable, string>(
                    moviesQuery.OrderBy(m => m.Actors.Any(a => a.FirstName.StartsWith("a"))),
                    "The method 'Any' is not supported by the 'orderby' query option."),
                new Tuple <IQueryable, string>(
                    moviesQuery.OrderBy(m => m.Actors.All(a => a.FirstName.StartsWith("a"))),
                    "The method 'All' is not supported by the 'orderby' query option."),

                new Tuple <IQueryable, string>(
                    moviesQuery.OrderBy(m => m.Name).ThenBy(m => m.Actors.Any()),
                    "The method 'Any' is not supported by the 'orderby' query option."),
                new Tuple <IQueryable, string>(
                    moviesQuery.OrderBy(m => m.Name).ThenBy(m => m.Actors.Any()),
                    "The method 'Any' is not supported by the 'orderby' query option."),
                new Tuple <IQueryable, string>(
                    moviesQuery.OrderByDescending(m => m.Name).ThenBy(m => m.Actors.Any()),
                    "The method 'Any' is not supported by the 'orderby' query option."),
                new Tuple <IQueryable, string>(
                    moviesQuery.OrderByDescending(m => m.Name).ThenBy(m => m.Actors.Any()),
                    "The method 'Any' is not supported by the 'orderby' query option."),
                new Tuple <IQueryable, string>(
                    collectionsQuery.OrderByDescending(m => m.CollectionOfInt.Any()),
                    "The method 'Any' is not supported by the 'orderby' query option."),
                new Tuple <IQueryable, string>(
                    collectionsQuery.OrderByDescending(m => m.ID).ThenBy(m => m.CollectionOfInt.Any()),
                    "The method 'Any' is not supported by the 'orderby' query option."),

                // in $select
                new Tuple <IQueryable, string>(
                    moviesQuery.Select(m => m.Awards.Any()),
                    "The method 'Select' is not supported."),
                new Tuple <IQueryable, string>(
                    moviesQuery.Select(m => new Movie()
                {
                    ID = m.ID, Awards = m.Awards.Any() ? m.Awards : new List <Award>()
                }),
                    "Initializing instances of the entity type AstoriaUnitTests.Tests.LinqAnyAllTests+Movie with the expression IIF(m.Awards.Any(), m.Awards, value(System.Collections.Generic.List`1[AstoriaUnitTests.Tests.LinqAnyAllTests+Award])) is not supported."),
                new Tuple <IQueryable, string>(
                    moviesQuery.Select(m => new Movie()
                {
                    ID = m.ID, Actors = m.Actors.OrderBy(a => a.Awards.Any()).ToList()
                }),
                    "Initializing instances of the entity type AstoriaUnitTests.Tests.LinqAnyAllTests+Movie with the expression m.Actors.OrderBy(a => a.Awards.Any()) is not supported."),
                new Tuple <IQueryable, string>(
                    moviesQuery.Select(m => new { ID = m.ID, Actors = m.Actors.Any() }),
                    "Constructing or initializing instances of the type <>f__AnonymousType1b`2[System.Int32,System.Boolean] with the expression m.Actors.Any() is not supported."),
                new Tuple <IQueryable, string>(
                    moviesQuery.Select(m => new { ID = m.ID, Actors = m.Actors.OrderBy(a => a.Awards.Any()).ToList() }),
                    "Constructing or initializing instances of the type <>f__AnonymousType1b`2[System.Int32,System.Collections.Generic.List`1[AstoriaUnitTests.Tests.LinqAnyAllTests+Person]] with the expression m.Actors.OrderBy(a => a.Awards.Any()) is not supported."),
            };

            TestUtil.RunCombinations(testCases, (testCase) =>
            {
                LinqTests.VerifyNotSupportedQuery(testCase.Item1, testCase.Item2);
            });
        }