private Expression VerifyQueryDeserialization <T>(string clauseString, string expectedResult = null, Action <ODataQuerySettings> settingsCustomizer = null) where T : class
        {
            IEdmModel   model  = GetModel <T>();
            ApplyClause clause = CreateApplyNode(clauseString, model, typeof(T));
            IWebApiAssembliesResolver assembliesResolver = WebApiAssembliesResolverFactory.Create();

            Func <ODataQuerySettings, ODataQuerySettings> customizeSettings = (settings) =>
            {
                if (settingsCustomizer != null)
                {
                    settingsCustomizer.Invoke(settings);
                }

                return(settings);
            };

            var binder = new AggregationBinder(
                customizeSettings(new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.False
            }),
                assembliesResolver,
                typeof(T),
                model,
                clause.Transformations.First());

            var query = Enumerable.Empty <T>().AsQueryable();

            var queryResult = binder.Bind(query);

            var applyExpr = queryResult.Expression;

            VerifyExpression <T>(applyExpr, expectedResult);

            return(applyExpr);
        }
Example #2
0
        public void GetLoadedTypes()
        {
            // Arrange
            MockType baseType =
                new MockType("BaseType")
                .Property(typeof(int), "ID");

            MockType derivedType =
                new MockType("DerivedType")
                .Property(typeof(int), "DerivedTypeId")
                .BaseType(baseType);

            MockAssembly assembly = new MockAssembly(baseType, derivedType);
            IWebApiAssembliesResolver resolver   = WebApiAssembliesResolverFactory.Create(assembly);
            IEnumerable <Type>        foundTypes = TypeHelper.GetLoadedTypes(resolver);

            IEnumerable <string> definedNames = assembly.GetTypes().Select(t => t.FullName);
            IEnumerable <string> foundNames   = foundTypes.Select(t => t.FullName);

            foreach (string name in definedNames)
            {
                Assert.Contains(name, foundNames);
            }

            Assert.DoesNotContain(typeof(TypeHelperTest), foundTypes);
        }
Example #3
0
        private Expression VerifyQueryDeserialization <T>(string clauseString, string expectedResult = null, Action <ODataQuerySettings> settingsCustomizer = null, bool classicEF = false) where T : class
        {
            IEdmModel   model  = GetModel <T>();
            ApplyClause clause = CreateApplyNode(clauseString, model, typeof(T));
            IWebApiAssembliesResolver assembliesResolver = WebApiAssembliesResolverFactory.Create();

            Func <ODataQuerySettings, ODataQuerySettings> customizeSettings = (settings) =>
            {
                if (settingsCustomizer != null)
                {
                    settingsCustomizer.Invoke(settings);
                }

                return(settings);
            };

            var context = new ODataQueryContext(model, typeof(T))
            {
                RequestContainer = new MockContainer()
            };

            var expandClause = clause.Transformations.OfType <ExpandTransformationNode>().FirstOrDefault()?.ExpandClause;


            var binder = classicEF
                ? new AggregationBinderEFFake(
                customizeSettings(new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.False
            }),
                assembliesResolver,
                typeof(T),
                model,
                clause.Transformations.First(t => t.Kind != TransformationNodeKind.Expand), context, expandClause)
                : new AggregationBinder(
                customizeSettings(new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.False
            }),
                assembliesResolver,
                typeof(T),
                model,
                clause.Transformations.First(t => t.Kind != TransformationNodeKind.Expand), context, expandClause);

            var query = Enumerable.Empty <T>().AsQueryable();

            var queryResult = binder.Bind(query);

            var applyExpr = queryResult.Expression;

            VerifyExpression <T>(applyExpr, expectedResult);

            return(applyExpr);
        }