Exemplo n.º 1
0
        private static void AddProcedureLinkBuilder(IEdmModel model, IEdmOperation operation, ProcedureConfiguration procedure)
        {
            ActionConfiguration   actionConfiguration = procedure as ActionConfiguration;
            IEdmAction            action = operation as IEdmAction;
            FunctionConfiguration functionConfiguration = procedure as FunctionConfiguration;
            IEdmFunction          function = operation as IEdmFunction;

            if (procedure.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Entity)
            {
                if (actionConfiguration != null && actionConfiguration.GetActionLink() != null && action != null)
                {
                    model.SetActionLinkBuilder(
                        action,
                        new ActionLinkBuilder(actionConfiguration.GetActionLink(), actionConfiguration.FollowsConventions));
                }
                else if (functionConfiguration != null && functionConfiguration.GetFunctionLink() != null && function != null)
                {
                    model.SetFunctionLinkBuilder(
                        function,
                        new FunctionLinkBuilder(functionConfiguration.GetFunctionLink(), functionConfiguration.FollowsConventions));
                }
            }
            else if (procedure.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Collection)
            {
                CollectionTypeConfiguration collectionTypeConfiguration =
                    (CollectionTypeConfiguration)procedure.BindingParameter.TypeConfiguration;

                if (collectionTypeConfiguration.ElementType.Kind == EdmTypeKind.Entity)
                {
                    if (actionConfiguration != null && actionConfiguration.GetFeedActionLink() != null && action != null)
                    {
                        model.SetActionLinkBuilder(
                            action,
                            new ActionLinkBuilder(actionConfiguration.GetFeedActionLink(), actionConfiguration.FollowsConventions));
                    }
                    else if (functionConfiguration != null && functionConfiguration.GetFeedFunctionLink() != null && function != null)
                    {
                        model.SetFunctionLinkBuilder(
                            function,
                            new FunctionLinkBuilder(functionConfiguration.GetFeedFunctionLink(), functionConfiguration.FollowsConventions));
                    }
                }
            }
        }
        public void WhenFeedActionLinksNotManuallyConfigured_ConventionBasedBuilderUsesConventions()
        {
            // Arrange
            Uri expectedUri                       = new Uri("http://server/Movies/Default.Watch(param=@param)");
            ODataModelBuilder builder             = new ODataConventionModelBuilder();
            EntityTypeConfiguration <Movie> movie = builder.EntitySet <Movie>("Movies").EntityType;
            FunctionConfiguration           watch = movie.Collection.Function("Watch").Returns <int>(); // function bound to collection

            watch.Parameter <string>("param");
            IEdmModel model = builder.GetEdmModel();

            HttpRequestMessage request       = new HttpRequestMessage(HttpMethod.Get, "http://server/Movies");
            HttpConfiguration  configuration = new HttpConfiguration();
            string             routeName     = "Route";

            configuration.MapODataServiceRoute(routeName, null, model);
            request.SetConfiguration(configuration);
            request.EnableODataDependencyInjectionSupport(routeName);

            UrlHelper urlHelper = new UrlHelper(request);

            // Act
            IEdmEntityContainer container     = model.SchemaElements.OfType <IEdmEntityContainer>().SingleOrDefault();
            IEdmFunction        watchFunction = Assert.Single(model.SchemaElements.OfType <IEdmFunction>()); // Guard
            IEdmEntitySet       entitySet     = container.EntitySets().SingleOrDefault();

            ResourceSetContext context = new ResourceSetContext
            {
                EntitySetBase = entitySet,
                Url           = urlHelper,
                Request       = request
            };

            OperationLinkBuilder functionLinkBuilder = model.GetAnnotationValue <OperationLinkBuilder>(watchFunction);

            //Assert
            Assert.Equal(expectedUri, watch.GetFeedFunctionLink()(context));
            Assert.NotNull(functionLinkBuilder);
            Assert.Equal(expectedUri, functionLinkBuilder.BuildLink(context));
        }
Exemplo n.º 3
0
        public void CanManuallyConfigureFeedFunctionLinkFactory()
        {
            // Arrange
            Uri expectedUri           = new Uri("http://localhost/service/Customers/Reward");
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);
            FunctionConfiguration reward = customer.Collection.Function("Reward").Returns <int>();

            reward.HasFeedFunctionLink(ctx => expectedUri, followsConventions: false);
            IEdmModel model = builder.GetEdmModel();

            // Act
            IEdmFunction        rewardFuntion       = Assert.Single(model.SchemaElements.OfType <IEdmFunction>()); // Guard
            FunctionLinkBuilder functionLinkBuilder = model.GetAnnotationValue <FunctionLinkBuilder>(rewardFuntion);
            FeedContext         context             = new FeedContext();

            //Assert
            Assert.Equal(expectedUri, reward.GetFeedFunctionLink()(context));
            Assert.NotNull(functionLinkBuilder);
            Assert.Equal(expectedUri, functionLinkBuilder.BuildFunctionLink(context));
        }