Exemple #1
14
        private IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create();

            builder.EntityType <Customer>().Namespace = "NS";
            builder.ComplexType <Address>().Namespace = "NS";

            FunctionConfiguration getEnum = builder.Function("GetEnum");

            getEnum.Parameter <SimpleEnum>("simpleEnum");
            getEnum.Returns <SimpleEnum>();

            FunctionConfiguration getFlagsEnum = builder.Function("GetFlagsEnum");

            getFlagsEnum.Parameter <FlagsEnum>("flagsEnum");
            getFlagsEnum.Returns <FlagsEnum>();

            FunctionConfiguration function = builder.Function("GetNullableFlagsEnum").Returns <bool>();

            function.Parameter <FlagsEnum?>("flagsEnum");

            builder.Function("GetAddress").Returns <bool>().Parameter <Address>("address");
            builder.Function("GetCustomer").Returns <bool>().Parameter <Customer>("customer");
            return(builder.GetEdmModel());
        }
Exemple #2
0
        public void Can_SetFunctionTitle_OnBindable_Functions()
        {
            // Arrange
            ODataModelBuilder builder             = new ODataModelBuilder();
            EntitySetConfiguration <Movie> movies = builder.EntitySet <Movie>("Movies");

            movies.EntityType.HasKey(m => m.ID);
            FunctionConfiguration entityAction = movies.EntityType.Function("Checkout");

            entityAction.Returns <int>();
            entityAction.Title = "Check out";
            FunctionConfiguration collectionAction = movies.EntityType.Collection.Function("RemoveOld");

            collectionAction.Returns <int>();
            collectionAction.Title = "Remove Old Movies";

            // Act
            IEdmModel                model          = builder.GetEdmModel();
            IEdmOperation            checkout       = model.FindOperations("Default.Checkout").Single();
            IEdmOperation            removeOld      = model.FindOperations("Default.RemoveOld").Single();
            OperationTitleAnnotation checkoutTitle  = model.GetOperationTitleAnnotation(checkout);
            OperationTitleAnnotation removeOldTitle = model.GetOperationTitleAnnotation(removeOld);

            // Assert
            Assert.NotNull(checkoutTitle);
            Assert.Equal("Check out", checkoutTitle.Title);
            Assert.NotNull(removeOldTitle);
            Assert.Equal("Remove Old Movies", removeOldTitle.Title);
        }
Exemple #3
0
        private IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <WorkflowBase>        workflowBases = builder.EntitySet <WorkflowBase>("WorkflowBases");
            EntitySetConfiguration <Employee>            employees     = builder.EntitySet <Employee>("Employees");
            EntitySetConfiguration <Project>             projects      = builder.EntitySet <Project>("Projects");
            EntitySetConfiguration <Quote>               quotes        = builder.EntitySet <Quote>("Quotes");
            EntitySetConfiguration <JobCard>             jobcards      = builder.EntitySet <JobCard>("JobCards");
            EntitySetConfiguration <Party>               parties       = builder.EntitySet <Party>("Parties");
            EntitySetConfiguration <PermissionContainer> permissions   = builder.EntitySet <PermissionContainer>("Permissions");

            permissions.EntityType.HasKey(t => t.Key);
            workflowBases.EntityType.HasKey(t => t.Oid);
            employees.EntityType.HasKey(t => t.Oid);
            projects.EntityType.HasKey(t => t.Oid);
            quotes.EntityType.HasKey(t => t.Oid);
            jobcards.EntityType.HasKey(t => t.Oid);
            parties.EntityType.HasKey(t => t.Oid);

            FunctionConfiguration logon = builder.Function("Login");

            logon.Returns <int>();
            logon.Parameter <string>("userName");
            logon.Parameter <string>("password");
            builder.Action("Logoff");

            ActionConfiguration getPermissions = builder.Action("GetPermissions");

            getPermissions.Parameter <string>("typeName");
            getPermissions.CollectionParameter <string>("keys");
            return(builder.GetEdmModel());
        }
Exemple #4
0
        public void CanManuallyConfigureFunctionLinkFactory()
        {
            // Arrange
            string            uriTemplate = "http://server/service/Customers({0})/Reward";
            Uri               expectedUri = new Uri(string.Format(uriTemplate, 1));
            ODataModelBuilder builder     = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);

            // Act
            FunctionConfiguration reward = customer.Function("Reward");

            reward.HasFunctionLink(ctx => new Uri(string.Format(uriTemplate, ctx.GetPropertyValue("CustomerId"))),
                                   followsConventions: false);
            reward.Returns <bool>();
            IEdmModel              model             = builder.GetEdmModel();
            IEdmEntityType         customerType      = model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault();
            ODataSerializerContext serializerContext = new ODataSerializerContext {
                Model = model
            };

            ResourceContext context = new ResourceContext(serializerContext, customerType.AsReference(), new Customer {
                CustomerId = 1
            });
            IEdmFunction         rewardFunction      = Assert.Single(model.SchemaElements.OfType <IEdmFunction>()); // Guard
            OperationLinkBuilder functionLinkBuilder = model.GetAnnotationValue <OperationLinkBuilder>(rewardFunction);

            //Assert
            Assert.Equal(expectedUri, reward.GetFunctionLink()(context));
            Assert.NotNull(functionLinkBuilder);
            Assert.Equal(expectedUri, functionLinkBuilder.BuildLink(context));
        }
        private IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <Employee>            employees   = builder.EntitySet <Employee>("Employees");
            EntitySetConfiguration <Party>               parties     = builder.EntitySet <Party>("Parties");
            EntitySetConfiguration <PermissionContainer> permissions = builder.EntitySet <PermissionContainer>("Permissions");
            EntitySetConfiguration <Department>          departments = builder.EntitySet <Department>("Departments");

            permissions.EntityType.HasKey(t => t.Key);
            employees.EntityType.HasKey(t => t.Oid);
            parties.EntityType.HasKey(t => t.Oid);
            departments.EntityType.HasKey(t => t.Oid);

            FunctionConfiguration logon = builder.Function("Login");

            logon.Returns <int>();
            logon.Parameter <string>("userName");
            logon.Parameter <string>("password");
            builder.Action("Logoff");

            ActionConfiguration getPermissions = builder.Action("GetPermissions");

            getPermissions.Parameter <string>("typeName");
            getPermissions.CollectionParameter <string>("keys");
            return(builder.GetEdmModel());
        }
Exemple #6
0
        public void CanCreateEdmModel_WithBindableFunction()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);

            // Act
            FunctionConfiguration sendEmail = customer.Function("FunctionName");

            sendEmail.Returns <bool>();
            IEdmModel model = builder.GetEdmModel();

            // Assert
            Assert.Single(model.SchemaElements.OfType <IEdmFunction>());
            IEdmFunction function = Assert.Single(model.SchemaElements.OfType <IEdmFunction>());

            Assert.False(function.IsComposable);
            Assert.True(function.IsBound);
            Assert.Equal("FunctionName", function.Name);
            Assert.NotNull(function.ReturnType);
            Assert.Single(function.Parameters);
            Assert.Equal(BindingParameterConfiguration.DefaultBindingParameterName, function.Parameters.Single().Name);
            Assert.Equal(typeof(Customer).FullName, function.Parameters.Single().Type.FullName());
        }
        public void FunctionLink_PreservesFollowsConventions(bool value)
        {
            // Arrange
            ODataModelBuilder     builder       = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();
            FunctionConfiguration configuration = new FunctionConfiguration(builder, "IgnoreFunction");

            configuration.Returns <int>();
            Mock <IEdmTypeConfiguration> bindingParameterTypeMock = new Mock <IEdmTypeConfiguration>();

            bindingParameterTypeMock.Setup(o => o.Kind).Returns(EdmTypeKind.Entity);
            Type entityType = typeof(object);

            bindingParameterTypeMock.Setup(o => o.ClrType).Returns(entityType);
            configuration.SetBindingParameter("IgnoreParameter", bindingParameterTypeMock.Object);
            configuration.HasFunctionLink((a) => { throw new NotImplementedException(); }, followsConventions: value);
            builder.AddOperation(configuration);
            builder.AddEntityType(entityType);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            var function = Assert.Single(model.SchemaElements.OfType <IEdmFunction>());
            OperationLinkBuilder functionLinkBuilder = model.GetOperationLinkBuilder(function);

            Assert.NotNull(functionLinkBuilder);
            Assert.Equal(value, functionLinkBuilder.FollowsConventions);
        }
Exemple #8
0
        private IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <Employee>         employees         = builder.EntitySet <Employee>("Employees");
            EntitySetConfiguration <Department>       departments       = builder.EntitySet <Department>("Departments");
            EntitySetConfiguration <Party>            parties           = builder.EntitySet <Party>("Parties");
            EntitySetConfiguration <ObjectPermission> objectPermissions = builder.EntitySet <ObjectPermission>("ObjectPermissions");
            EntitySetConfiguration <MemberPermission> memberPermissions = builder.EntitySet <MemberPermission>("MemberPermissions");
            EntitySetConfiguration <TypePermission>   typePermissions   = builder.EntitySet <TypePermission>("TypePermissions");

            employees.EntityType.HasKey(t => t.Oid);
            departments.EntityType.HasKey(t => t.Oid);
            parties.EntityType.HasKey(t => t.Oid);

            FunctionConfiguration login = builder.Function("Login");

            login.Returns <int>();
            login.Parameter <string>("userName");
            login.Parameter <string>("password");

            builder.Action("Logout");

            ActionConfiguration getPermissions = builder.Action("GetPermissions");

            getPermissions.Parameter <string>("typeName");
            getPermissions.CollectionParameter <string>("keys");

            ActionConfiguration getTypePermissions = builder.Action("GetTypePermissions");

            getTypePermissions.Parameter <string>("typeName");
            getTypePermissions.ReturnsFromEntitySet <TypePermission>("TypePermissions");
            return(builder.GetEdmModel());
        }
        private IEdmModel GetEdmModel(ODataConventionModelBuilder builder)
        {
            builder.EntitySet <ConventionCustomer>("ConventionCustomers");
            builder.EntitySet <ConventionOrder>("ConventionOrders");
            builder.ComplexType <ConventionPerson>();
            builder.EntityType <ConventionCustomer>().ComplexProperty <ConventionAddress>(c => c.Address);

            // Top level action import
            ActionConfiguration createConventionCustomerById = builder.Action("CreateConventionCustomerById");

            createConventionCustomerById.Parameter <int>("ID");
            createConventionCustomerById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers");

            // Top level action import without parameter and with a collection of primitive return type
            ActionConfiguration topCollectionPrimitiveAction = builder.Action("CreateCollectionMessages");

            topCollectionPrimitiveAction.ReturnsCollection <string>();

            // Top level function import
            FunctionConfiguration getAllCustomers = builder.Function("GetAllConventionCustomers");

            getAllCustomers.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");

            // Top level function import with one parameter
            FunctionConfiguration getCustomersById = builder.Function("GetConventionCustomerById");

            getCustomersById.IsComposable = true;
            getCustomersById.Parameter <int>("CustomerId");
            getCustomersById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers");

            // Top level function import with two parameters
            FunctionConfiguration getOrder = builder.Function("GetConventionOrderByCustomerIdAndOrderName");

            getOrder.Parameter <int>("CustomerId");
            getOrder.Parameter <string>("OrderName");
            getOrder.ReturnsFromEntitySet <ConventionOrder>("ConventionOrders");

            // Top level function import with complex parameter
            FunctionConfiguration complexFunction = builder.Function("ComplexFunction");

            complexFunction.Parameter <ConventionAddress>("address");
            complexFunction.Returns <string>();

            // Top level function import with entity parameter
            FunctionConfiguration entityFunction = builder.Function("EntityFunction");

            entityFunction.Parameter <ConventionOrder>("order");
            entityFunction.Returns <string>();

            // Top level function import with optional parameter
            FunctionConfiguration optionalFunction = builder.Function("OptionalFunction");

            optionalFunction.Parameter <int>("param").HasDefaultValue("9");
            optionalFunction.Returns <string>();

            return(builder.GetEdmModel());
        }
Exemple #10
0
        private static IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create();

            builder.EntitySet <DateTimeModel>("DateTimeModels");

            FunctionConfiguration function = builder.EntityType <DateTimeModel>().Function("CalcBirthday");

            function.Returns <DateTime>().Parameter <DateTime>("dto");
            return(builder.GetEdmModel());
        }
Exemple #11
0
        public void CanCreateFunctionWithPrimitiveReturnType()
        {
            // Arrange & Act
            ODataModelBuilder     builder  = new ODataModelBuilder();
            FunctionConfiguration function = builder.Function("CreateMessage");

            function.Returns <string>();

            // Assert
            Assert.NotNull(function.ReturnType);
            Assert.Equal("Edm.String", function.ReturnType.FullName);
        }
Exemple #12
0
        private static void MapWorkflowOData(ODataModelBuilder builder)
        {
            builder
            .EntitySet <WorkflowStatusModel>("Workflows")
            .EntityType.HasKey(p => p.Id);
            builder
            .EntitySet <WorkflowActivityModel>("WorkflowActivities")
            .EntityType.HasKey(p => p.IdWorkflowActivity);

            #region [ Functions ]
            FunctionConfiguration myInstances = builder
                                                .EntityType <WorkflowStatusModel>().Collection
                                                .Function("MyInstances");

            myInstances.Namespace = "WorkflowService";
            myInstances.ReturnsCollectionFromEntitySet <WorkflowStatusModel>("Workflows");
            myInstances.Parameter <string>("workflowName");

            FunctionConfiguration myActivities = builder
                                                 .EntityType <WorkflowActivityModel>().Collection
                                                 .Function("MyActivities");
            myActivities.Namespace = "WorkflowService";
            myActivities.ReturnsCollectionFromEntitySet <WorkflowActivityModel>("WorkflowActivities");
            myActivities.Parameter <WorkflowActivityFinderModel>("finder");

            FunctionConfiguration getLastWorkflowActivityFromDocumentUnit = builder
                                                                            .EntityType <WorkflowActivityModel>().Collection
                                                                            .Function("GetLastWorkflowActivityFromDocumentUnit");
            getLastWorkflowActivityFromDocumentUnit.Namespace = "WorkflowService";
            getLastWorkflowActivityFromDocumentUnit.ReturnsFromEntitySet <WorkflowActivityModel>("WorkflowActivities");
            getLastWorkflowActivityFromDocumentUnit.Parameter <Guid>("idDocumentUnit");

            FunctionConfiguration currentWorkflowActivityFromDocumentUnit = builder
                                                                            .EntityType <WorkflowActivityModel>().Collection
                                                                            .Function("CurrentWorkflowActivityFromDocumentUnit");
            currentWorkflowActivityFromDocumentUnit.Namespace = "WorkflowService";
            currentWorkflowActivityFromDocumentUnit.ReturnsFromEntitySet <WorkflowActivityModel>("WorkflowActivities");
            currentWorkflowActivityFromDocumentUnit.Parameter <Guid>("idDocumentUnit");

            FunctionConfiguration getUserAuthorizedWorkflowActivitiesCount = builder
                                                                             .EntityType <WorkflowActivityModel>().Collection
                                                                             .Function("CountUserAuthorizedWorkflowActivities");
            getUserAuthorizedWorkflowActivitiesCount.Namespace = "WorkflowService";
            getUserAuthorizedWorkflowActivitiesCount.Returns <long>();
            getUserAuthorizedWorkflowActivitiesCount.Parameter <WorkflowActivityFinderModel>("finder");

            #endregion

            #region [ Navigation Properties ]

            #endregion
        }
        private IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            FunctionConfiguration getEnum = builder.Function("GetEnum");

            getEnum.Parameter <SimpleEnum>("simpleEnum");
            getEnum.Returns <SimpleEnum>();

            FunctionConfiguration getFlagsEnum = builder.Function("GetFlagsEnum");

            getFlagsEnum.Parameter <FlagsEnum>("flagsEnum");
            getFlagsEnum.Returns <FlagsEnum>();

            return(builder.GetEdmModel());
        }
Exemple #14
0
        private static void MapDossierOData(ODataModelBuilder builder)
        {
            builder
            .EntitySet <DossierModel>("Dossiers")
            .EntityType.HasKey(p => p.UniqueId);
            builder
            .EntitySet <DossierFolderTableValuedModel>("DossierFolders")
            .EntityType.HasKey(p => p.IdDossierFolder);

            #region [ Functions ]

            FunctionConfiguration getDossierById = builder
                                                   .EntityType <DossierModel>().Collection
                                                   .Function("GetDossierById");
            getDossierById.Namespace = "DossierService";
            getDossierById.Parameter <Guid>("id");
            getDossierById.ReturnsCollectionFromEntitySet <DossierModel>("Dossiers");

            FunctionConfiguration getDossierByYearAndNumber = builder
                                                              .EntityType <DossierModel>().Collection
                                                              .Function("GetDossierByYearAndNumber");
            getDossierByYearAndNumber.Namespace = "DossierService";
            getDossierByYearAndNumber.Parameter <short>("year");
            getDossierByYearAndNumber.Parameter <int>("number");
            getDossierByYearAndNumber.ReturnsCollectionFromEntitySet <DossierModel>("Dossiers");

            FunctionConfiguration getNextDossierFolders = builder
                                                          .EntityType <DossierFolderTableValuedModel>().Collection
                                                          .Function("GetNextDossierFolders");
            getNextDossierFolders.Namespace = "DossierService";
            getNextDossierFolders.Parameter <Guid>("id");
            getNextDossierFolders.ReturnsCollectionFromEntitySet <DossierFolderTableValuedModel>("DossierFolders");

            FunctionConfiguration hasChildren = builder
                                                .EntityType <DossierFolderTableValuedModel>().Collection
                                                .Function("HasChildren");
            hasChildren.Namespace = "DossierService";
            hasChildren.Parameter <Guid>("id");
            hasChildren.Returns <bool>();

            #endregion

            #region [ Navigation Properties ]

            #endregion
        }
Exemple #15
0
        public void Cant_SetFunctionTitle_OnNonBindableFunctions()
        {
            // Arrange
            ODataModelBuilder     builder  = new ODataModelBuilder();
            FunctionConfiguration function = builder.Function("MyFunction");

            function.Returns <int>();
            function.Title = "My Function";

            // Act
            IEdmModel           model          = builder.GetEdmModel();
            IEdmOperationImport functionImport = model.EntityContainer.OperationImports().OfType <IEdmFunctionImport>().Single();

            Assert.NotNull(functionImport);
            OperationTitleAnnotation functionTitleAnnotation = model.GetOperationTitleAnnotation(functionImport.Operation);

            // Assert
            Assert.Null(functionTitleAnnotation);
        }
Exemple #16
0
        public static IEdmModel GetModel()
        {
            var configuration = RoutingConfigurationFactory.CreateWithTypes();
            ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create(configuration);

            builder.EntitySet <RoutingCustomer>("RoutingCustomers");
            builder.EntitySet <Product>("Products");
            builder.EntitySet <SalesPerson>("SalesPeople");
            builder.EntitySet <EmailAddress>("EmailAddresses");
            builder.EntitySet <üCategory>("üCategories");
            builder.EntitySet <EnumCustomer>("EnumCustomers");
            builder.Singleton <RoutingCustomer>("VipCustomer");
            builder.Singleton <Product>("MyProduct");
            builder.EntitySet <DateTimeOffsetKeyCustomer>("DateTimeOffsetKeyCustomers");
            builder.EntitySet <Destination>("Destinations");
            builder.EntitySet <Incident>("Incidents");
            builder.ComplexType <Dog>();
            builder.ComplexType <Cat>();
            builder.EntityType <SpecialProduct>();
            builder.ComplexType <UsAddress>();

            ActionConfiguration getRoutingCustomerById = builder.Action("GetRoutingCustomerById");

            getRoutingCustomerById.Parameter <int>("RoutingCustomerId");
            getRoutingCustomerById.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers");

            ActionConfiguration getSalesPersonById = builder.Action("GetSalesPersonById");

            getSalesPersonById.Parameter <int>("salesPersonId");
            getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getAllVIPs = builder.Action("GetAllVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "RoutingCustomers");

            builder.EntityType <RoutingCustomer>().ComplexProperty <Address>(c => c.Address);
            builder.EntityType <RoutingCustomer>().Action("GetRelatedRoutingCustomers").ReturnsCollectionFromEntitySet <RoutingCustomer>("RoutingCustomers");

            ActionConfiguration getBestRelatedRoutingCustomer = builder.EntityType <RoutingCustomer>().Action("GetBestRelatedRoutingCustomer");

            ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedRoutingCustomer, "RoutingCustomers");

            ActionConfiguration getVIPS = builder.EntityType <RoutingCustomer>().Collection.Action("GetVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "RoutingCustomers");

            builder.EntityType <RoutingCustomer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products");
            builder.EntityType <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople");
            builder.EntityType <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getMostProfitable = builder.EntityType <VIP>().Collection.Action("GetMostProfitable");

            ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "RoutingCustomers");

            ActionConfiguration getVIPRoutingCustomers = builder.EntityType <SalesPerson>().Action("GetVIPRoutingCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomers, "RoutingCustomers");

            ActionConfiguration getVIPRoutingCustomersOnCollection = builder.EntityType <SalesPerson>().Collection.Action("GetVIPRoutingCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomersOnCollection, "RoutingCustomers");

            builder.EntityType <VIP>().HasRequired(v => v.RelationshipManager);
            builder.EntityType <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson);

            // function bound to an entity
            FunctionConfiguration topProductId = builder.EntityType <Product>().Function("TopProductId");

            topProductId.Returns <int>();

            FunctionConfiguration topProductIdByCity = builder.EntityType <Product>().Function("TopProductIdByCity");

            topProductIdByCity.Parameter <string>("city");
            topProductIdByCity.Returns <string>();

            FunctionConfiguration topProductIdByCityAndModel = builder.EntityType <Product>().Function("TopProductIdByCityAndModel");

            topProductIdByCityAndModel.Parameter <string>("city");
            topProductIdByCityAndModel.Parameter <int>("model");
            topProductIdByCityAndModel.Returns <string>();

            FunctionConfiguration optionFunctions = builder.EntityType <Product>().Collection.Function("GetCount").Returns <int>();

            optionFunctions.Parameter <double>("minSalary");
            optionFunctions.Parameter <double>("maxSalary").Optional();
            optionFunctions.Parameter <double>("aveSalary").Optional().HasDefaultValue("1200.99");

            // function bound to a collection of entities
            FunctionConfiguration topProductOfAll = builder.EntityType <Product>().Collection.Function("TopProductOfAll");

            topProductOfAll.Returns <string>();

            FunctionConfiguration topProductOfAllByCity = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCity");

            topProductOfAllByCity.Parameter <string>("city");
            topProductOfAllByCity.Returns <string>();

            FunctionConfiguration copyProductByCity = builder.EntityType <Product>().Function("CopyProductByCity");

            copyProductByCity.Parameter <string>("city");
            copyProductByCity.Returns <string>();

            FunctionConfiguration topProductOfAllByCityAndModel = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCityAndModel");

            topProductOfAllByCityAndModel.Parameter <string>("city");
            topProductOfAllByCityAndModel.Parameter <int>("model");
            topProductOfAllByCityAndModel.Returns <string>();

            // Function bound to the base entity type and derived entity type
            builder.EntityType <RoutingCustomer>().Function("GetOrdersCount").Returns <string>();
            builder.EntityType <VIP>().Function("GetOrdersCount").Returns <string>();

            // Overloaded function only bound to the base entity type with one paramter
            var getOrderCount = builder.EntityType <RoutingCustomer>().Function("GetOrdersCount");

            getOrderCount.Parameter <int>("factor");
            getOrderCount.Returns <string>();

            // Function only bound to the derived entity type
            builder.EntityType <SpecialVIP>().Function("GetSpecialGuid").Returns <string>();

            // Function bound to the collection of the base and the derived entity type
            builder.EntityType <RoutingCustomer>().Collection.Function("GetAllEmployees").Returns <string>();
            builder.EntityType <VIP>().Collection.Function("GetAllEmployees").Returns <string>();

            // Bound function with enum type parameters
            var boundFunction = builder.EntityType <RoutingCustomer>().Collection.Function("BoundFuncWithEnumParameters");

            boundFunction.Parameter <SimpleEnum>("SimpleEnum");
            boundFunction.Parameter <FlagsEnum>("FlagsEnum");
            boundFunction.Returns <string>();

            // Bound function with enum type parameter for attribute routing
            var boundFunctionForAttributeRouting = builder.EntityType <RoutingCustomer>().Collection
                                                   .Function("BoundFuncWithEnumParameterForAttributeRouting");

            boundFunctionForAttributeRouting.Parameter <SimpleEnum>("SimpleEnum");
            boundFunctionForAttributeRouting.Returns <string>();

            // Unbound function with enum type parameters
            var function = builder.Function("UnboundFuncWithEnumParameters");

            function.Parameter <LongEnum>("LongEnum");
            function.Parameter <FlagsEnum>("FlagsEnum");
            function.Returns <string>();

            // Unbound function
            builder.Function("UnboundFunction").ReturnsCollection <int>().IsComposable = true;

            // Action only bound to the derived entity type
            builder.EntityType <SpecialVIP>().Action("ActionBoundToSpecialVIP");

            // Action only bound to the derived entity type
            builder.EntityType <SpecialVIP>().Collection.Action("ActionBoundToSpecialVIPs");

            // Function only bound to the base entity collection type
            builder.EntityType <RoutingCustomer>().Collection.Function("FunctionBoundToRoutingCustomers").Returns <int>();

            // Function only bound to the derived entity collection type
            builder.EntityType <VIP>().Collection.Function("FunctionBoundToVIPs").Returns <int>();

            // Bound function with multiple parameters
            var functionBoundToProductWithMultipleParamters = builder.EntityType <Product>().Function("FunctionBoundToProductWithMultipleParamters");

            functionBoundToProductWithMultipleParamters.Parameter <int>("P1");
            functionBoundToProductWithMultipleParamters.Parameter <int>("P2");
            functionBoundToProductWithMultipleParamters.Parameter <string>("P3");
            functionBoundToProductWithMultipleParamters.Returns <int>();

            // Overloaded bound function with no parameter
            builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>();

            // Overloaded bound function with one parameter
            builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>().Parameter <int>("P1");

            // Overloaded bound function with multiple parameters
            var functionBoundToProduct = builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>();

            functionBoundToProduct.Parameter <int>("P1");
            functionBoundToProduct.Parameter <int>("P2");
            functionBoundToProduct.Parameter <string>("P3");

            // Unbound function with one parameter
            var unboundFunctionWithOneParamters = builder.Function("UnboundFunctionWithOneParamters");

            unboundFunctionWithOneParamters.Parameter <int>("P1");
            unboundFunctionWithOneParamters.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers");
            unboundFunctionWithOneParamters.IsComposable = true;

            // Unbound function with multiple parameters
            var functionWithMultipleParamters = builder.Function("UnboundFunctionWithMultipleParamters");

            functionWithMultipleParamters.Parameter <int>("P1");
            functionWithMultipleParamters.Parameter <int>("P2");
            functionWithMultipleParamters.Parameter <string>("P3");
            functionWithMultipleParamters.Returns <int>();

            // Overloaded unbound function with no parameter
            builder.Function("OverloadUnboundFunction").Returns <int>();

            // Overloaded unbound function with one parameter
            builder.Function("OverloadUnboundFunction").Returns <int>().Parameter <int>("P1");

            // Overloaded unbound function with multiple parameters
            var overloadUnboundFunction = builder.Function("OverloadUnboundFunction").Returns <int>();

            overloadUnboundFunction.Parameter <int>("P1");
            overloadUnboundFunction.Parameter <int>("P2");
            overloadUnboundFunction.Parameter <string>("P3");

            var functionWithComplexTypeParameter =
                builder.EntityType <RoutingCustomer>().Function("CanMoveToAddress").Returns <bool>();

            functionWithComplexTypeParameter.Parameter <Address>("address");

            var functionWithCollectionOfComplexTypeParameter =
                builder.EntityType <RoutingCustomer>().Function("MoveToAddresses").Returns <bool>();

            functionWithCollectionOfComplexTypeParameter.CollectionParameter <Address>("addresses");

            var functionWithCollectionOfPrimitiveTypeParameter =
                builder.EntityType <RoutingCustomer>().Function("CollectionOfPrimitiveTypeFunction").Returns <bool>();

            functionWithCollectionOfPrimitiveTypeParameter.CollectionParameter <int>("intValues");

            var functionWithEntityTypeParameter =
                builder.EntityType <RoutingCustomer>().Function("EntityTypeFunction").Returns <bool>();

            functionWithEntityTypeParameter.EntityParameter <Product>("product");

            var functionWithCollectionEntityTypeParameter =
                builder.EntityType <RoutingCustomer>().Function("CollectionEntityTypeFunction").Returns <bool>();

            functionWithCollectionEntityTypeParameter.CollectionEntityParameter <Product>("products");

            return(builder.GetEdmModel());
        }
Exemple #17
0
        private static void RegisterEntityFunctions(ODataConventionModelBuilder builder)
        {
            FunctionConfiguration meanRating = builder.EntityType <Product>().Function("MeanProductRating");

            meanRating.Returns <decimal>();
        }
Exemple #18
0
        public void CanCreateEdmModel_ForBindableFunction_WithSupportedParameterType()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntityType <Customer>();

            customer.HasKey(c => c.CustomerId);
            customer.Property(c => c.Name);

            // Act
            FunctionConfiguration functionBuilder = customer.Function("FunctionName");

            functionBuilder.Parameter <int>("primitive");
            functionBuilder.CollectionParameter <int>("collectionPrimitive");

            functionBuilder.Parameter <bool?>("nullablePrimitive");
            functionBuilder.CollectionParameter <bool?>("nullableCollectionPrimitive");

            functionBuilder.Parameter <Color>("enum");
            functionBuilder.CollectionParameter <Color>("collectionEnum");

            functionBuilder.Parameter <Color?>("nullableEnum");
            functionBuilder.CollectionParameter <Color?>("nullableCollectionEnum");

            functionBuilder.Parameter <Address>("complex");
            functionBuilder.CollectionParameter <Address>("collectionComplex");

            functionBuilder.EntityParameter <Customer>("entity");
            functionBuilder.CollectionEntityParameter <Customer>("collectionEntity");

            functionBuilder.Returns <bool>();

            IEdmModel model = builder.GetEdmModel();

            // Assert
            Assert.Single(model.SchemaElements.OfType <IEdmFunction>());
            IEdmFunction function = Assert.Single(model.SchemaElements.OfType <IEdmFunction>());

            Assert.False(function.IsComposable);
            Assert.True(function.IsBound);
            Assert.Equal("FunctionName", function.Name);
            Assert.NotNull(function.ReturnType);

            Assert.Equal(13, function.Parameters.Count());

            function.AssertHasParameter(model, BindingParameterConfiguration.DefaultBindingParameterName, typeof(Customer), true);

            function.AssertHasParameter(model, parameterName: "primitive", parameterType: typeof(int), isNullable: false);
            function.AssertHasParameter(model, parameterName: "collectionPrimitive", parameterType: typeof(IList <int>), isNullable: false);

            function.AssertHasParameter(model, parameterName: "nullablePrimitive", parameterType: typeof(bool?), isNullable: true);
            function.AssertHasParameter(model, parameterName: "nullableCollectionPrimitive", parameterType: typeof(IList <bool?>), isNullable: true);

            function.AssertHasParameter(model, parameterName: "enum", parameterType: typeof(Color), isNullable: false);
            function.AssertHasParameter(model, parameterName: "collectionEnum", parameterType: typeof(IList <Color>), isNullable: false);

            function.AssertHasParameter(model, parameterName: "nullableEnum", parameterType: typeof(Color?), isNullable: true);
            function.AssertHasParameter(model, parameterName: "nullableCollectionEnum", parameterType: typeof(IList <Color?>), isNullable: true);

            function.AssertHasParameter(model, parameterName: "complex", parameterType: typeof(Address), isNullable: true);
            function.AssertHasParameter(model, parameterName: "collectionComplex", parameterType: typeof(IList <Address>), isNullable: true);

            function.AssertHasParameter(model, parameterName: "entity", parameterType: typeof(Customer), isNullable: true);
            function.AssertHasParameter(model, parameterName: "collectionEntity", parameterType: typeof(IList <Customer>), isNullable: true);
        }
        public static IEdmModel GetEdmModel(ODataConventionModelBuilder builder)
        {
            builder.EntitySet <ConventionCustomer>("ConventionCustomers");
            builder.EntitySet <ConventionOrder>("ConventionOrders");

            EnumTypeConfiguration <ConventionGender> enumType = builder.EnumType <ConventionGender>();

            enumType.Member(ConventionGender.Female);
            enumType.Member(ConventionGender.Male);
            #region functions

            FunctionConfiguration getAllCustomers = builder.Function("GetAllConventionCustomers");
            getAllCustomers.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");
            getAllCustomers.IsComposable = true;

            // Return all the customers whose name contains CustomerName
            FunctionConfiguration getAllCustomersOverload = builder.Function("GetAllConventionCustomers");
            getAllCustomersOverload.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");
            getAllCustomersOverload.Parameter <string>("CustomerName");
            getAllCustomersOverload.IsComposable = true;

            FunctionConfiguration getCustomersById = builder.Function("GetConventionCustomerById");
            getCustomersById.Parameter <int>("CustomerId");
            getCustomersById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers");
            getCustomersById.IsComposable = true;

            FunctionConfiguration getOrder = builder.Function("GetConventionOrderByCustomerIdAndOrderName");
            getOrder.Parameter <int>("CustomerId");
            getOrder.Parameter <string>("OrderName");
            getOrder.ReturnsFromEntitySet <ConventionOrder>("ConventionOrders");

            FunctionConfiguration getCustomerNameById = builder.Function("GetConventionCustomerNameById");
            getCustomerNameById.Parameter <int>("CustomerId");
            getCustomerNameById.Returns <string>();

            FunctionConfiguration getDefinedGenders = builder.Function("GetDefinedGenders");
            getDefinedGenders.ReturnsCollection <ConventionGender>()
            .IsComposable = true;

            FunctionConfiguration function = builder.Function("AdvancedFunction").Returns <bool>();
            function.CollectionParameter <int>("nums");
            function.CollectionParameter <ConventionGender>("genders");
            function.Parameter <ConventionAddress>("location");
            function.CollectionParameter <ConventionAddress>("addresses");
            function.EntityParameter <ConventionCustomer>("customer");
            function.CollectionEntityParameter <ConventionCustomer>("customers");

            #endregion

            #region actions

            ActionConfiguration resetDataSource = builder.Action("ResetDataSource");

            // bug: error message:  non-binding parameter type must be either Primitive, Complex, Collection of Primitive or a Collection of Complex.

            /*
             * ActionConfiguration createCustomer = builder.Action("CreateCustomer");
             * createCustomer.Parameter<ConventionCustomer>("Customer");
             * createCustomer.ReturnsFromEntitySet<ConventionCustomer>("ConventionCustomers");
             */

            ActionConfiguration udpateAddress = builder.Action("UpdateAddress");
            udpateAddress.Parameter <ConventionAddress>("Address");
            udpateAddress.Parameter <int>("ID");
            udpateAddress.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");

            ActionConfiguration action = builder.Action("AdvancedAction");
            action.CollectionParameter <int>("nums");
            action.CollectionParameter <ConventionGender>("genders");
            action.Parameter <ConventionAddress>("location");
            action.CollectionParameter <ConventionAddress>("addresses");
            action.EntityParameter <ConventionCustomer>("customer");
            action.CollectionEntityParameter <ConventionCustomer>("customers");

            #endregion

            var schemaNamespace = typeof(ConventionCustomer).Namespace;

            builder.Namespace = schemaNamespace;

            var edmModel  = builder.GetEdmModel();
            var container = edmModel.EntityContainer as EdmEntityContainer;

            #region function imports

            var entitySet = container.FindEntitySet("ConventionCustomers");
            var getCustomersByIdOfEdmFunction = edmModel.FindDeclaredOperations(schemaNamespace + ".GetConventionCustomerById").First() as EdmFunction;
            container.AddFunctionImport("GetConventionCustomerByIdImport", getCustomersByIdOfEdmFunction, new EdmPathExpression(entitySet.Name));

            var functionsOfGetAllConventionCustomers   = edmModel.FindDeclaredOperations(schemaNamespace + ".GetAllConventionCustomers");
            var getAllConventionCustomersOfEdmFunction = functionsOfGetAllConventionCustomers.FirstOrDefault(f => f.Parameters.Count() == 0) as EdmFunction;
            container.AddFunctionImport("GetAllConventionCustomersImport", getAllConventionCustomersOfEdmFunction, new EdmPathExpression(entitySet.Name));

            // TODO delete this overload after bug 1640 is fixed: It can not find the correct overload function if the the function is exposed as a function import.
            var getAllConventionCustomersOverloadOfEdmFunction = functionsOfGetAllConventionCustomers.FirstOrDefault(f => f.Parameters.Count() > 0) as EdmFunction;
            container.AddFunctionImport("GetAllConventionCustomersImport", getAllConventionCustomersOverloadOfEdmFunction, new EdmPathExpression(entitySet.Name));

            var entitySet1 = container.FindEntitySet("ConventionOrders");
            var GetConventionOrderByCustomerIdAndOrderNameOfEdmFunction = edmModel.FindDeclaredOperations(schemaNamespace + ".GetConventionOrderByCustomerIdAndOrderName").First() as EdmFunction;
            container.AddFunctionImport("GetConventionOrderByCustomerIdAndOrderNameImport", GetConventionOrderByCustomerIdAndOrderNameOfEdmFunction, new EdmPathExpression(entitySet1.Name));

            var getConventionCustomerNameByIdOfEdmFunction = edmModel.FindDeclaredOperations(schemaNamespace + ".GetConventionCustomerNameById").First() as EdmFunction;
            container.AddFunctionImport("GetConventionCustomerNameByIdImport", getConventionCustomerNameByIdOfEdmFunction, null);

            #endregion

            #region action imports

            var resetDataSourceOfEdmAction = edmModel.FindDeclaredOperations(schemaNamespace + ".ResetDataSource").FirstOrDefault() as EdmAction;
            container.AddActionImport("ResetDataSourceImport", resetDataSourceOfEdmAction);

            // TODO: it is a potential issue that entity can not be used as an un-bound parameter.

            /*
             * var createCustomerOfEdmAction = edmModel.FindDeclaredOperations(schemaNamespace + ".CreateCustomer").FirstOrDefault() as EdmAction;
             * container.AddActionImport("CreateCustomerImport", createCustomerOfEdmAction);
             */
            var updateAddressOfEdmAction = edmModel.FindDeclaredOperations(schemaNamespace + ".UpdateAddress").FirstOrDefault() as EdmAction;
            container.AddActionImport("UpdateAddressImport", updateAddressOfEdmAction, new EdmPathExpression(entitySet.Name));

            #endregion

            return(edmModel);
        }
        public void FunctionLink_PreservesFollowsConventions(bool value)
        {
            // Arrange
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock<ODataModelBuilder>();
            FunctionConfiguration configuration = new FunctionConfiguration(builder, "IgnoreFunction");
            configuration.Returns<int>();
            Mock<IEdmTypeConfiguration> bindingParameterTypeMock = new Mock<IEdmTypeConfiguration>();
            bindingParameterTypeMock.Setup(o => o.Kind).Returns(EdmTypeKind.Entity);
            Type entityType = typeof(object);
            bindingParameterTypeMock.Setup(o => o.ClrType).Returns(entityType);
            configuration.SetBindingParameter("IgnoreParameter", bindingParameterTypeMock.Object);
            configuration.HasFunctionLink((a) => { throw new NotImplementedException(); }, followsConventions: value);
            builder.AddProcedure(configuration);
            builder.AddEntityType(entityType);

            // Act
            IEdmModel model = builder.GetEdmModel();

            // Assert
            var function = Assert.Single(model.SchemaElements.OfType<IEdmFunction>());
            FunctionLinkBuilder functionLinkBuilder = model.GetFunctionLinkBuilder(function);
            Assert.NotNull(functionLinkBuilder);
            Assert.Equal(value, functionLinkBuilder.FollowsConventions);
        }
        public static IEdmModel GetModel()
        {
            HttpConfiguration configuration = new HttpConfiguration();

            configuration.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver());
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder(configuration);

            builder.EntitySet <RoutingCustomer>("RoutingCustomers");
            builder.EntitySet <Product>("Products");
            builder.EntitySet <SalesPerson>("SalesPeople");
            builder.EntitySet <EmailAddress>("EmailAddresses");
            builder.EntitySet <üCategory>("üCategories");
            builder.EntitySet <EnumCustomer>("EnumCustomers");
            builder.Singleton <RoutingCustomer>("VipCustomer");
            builder.Singleton <Product>("MyProduct");
            builder.EntitySet <DateTimeOffsetKeyCustomer>("DateTimeOffsetKeyCustomers");
            builder.ComplexType <Dog>();
            builder.ComplexType <Cat>();

            ActionConfiguration getRoutingCustomerById = builder.Action("GetRoutingCustomerById");

            getRoutingCustomerById.Parameter <int>("RoutingCustomerId");
            getRoutingCustomerById.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers");

            ActionConfiguration getSalesPersonById = builder.Action("GetSalesPersonById");

            getSalesPersonById.Parameter <int>("salesPersonId");
            getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getAllVIPs = builder.Action("GetAllVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "RoutingCustomers");

            builder.EntityType <RoutingCustomer>().ComplexProperty <Address>(c => c.Address);
            builder.EntityType <RoutingCustomer>().Action("GetRelatedRoutingCustomers").ReturnsCollectionFromEntitySet <RoutingCustomer>("RoutingCustomers");

            ActionConfiguration getBestRelatedRoutingCustomer = builder.EntityType <RoutingCustomer>().Action("GetBestRelatedRoutingCustomer");

            ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedRoutingCustomer, "RoutingCustomers");

            ActionConfiguration getVIPS = builder.EntityType <RoutingCustomer>().Collection.Action("GetVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "RoutingCustomers");

            builder.EntityType <RoutingCustomer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products");
            builder.EntityType <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople");
            builder.EntityType <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getMostProfitable = builder.EntityType <VIP>().Collection.Action("GetMostProfitable");

            ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "RoutingCustomers");

            ActionConfiguration getVIPRoutingCustomers = builder.EntityType <SalesPerson>().Action("GetVIPRoutingCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomers, "RoutingCustomers");

            ActionConfiguration getVIPRoutingCustomersOnCollection = builder.EntityType <SalesPerson>().Collection.Action("GetVIPRoutingCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomersOnCollection, "RoutingCustomers");

            builder.EntityType <VIP>().HasRequired(v => v.RelationshipManager);
            builder.EntityType <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson);

            // function bound to an entity
            FunctionConfiguration topProductId = builder.EntityType <Product>().Function("TopProductId");

            topProductId.Returns <int>();

            FunctionConfiguration topProductIdByCity = builder.EntityType <Product>().Function("TopProductIdByCity");

            topProductIdByCity.Parameter <string>("city");
            topProductIdByCity.Returns <string>();

            FunctionConfiguration topProductIdByCityAndModel = builder.EntityType <Product>().Function("TopProductIdByCityAndModel");

            topProductIdByCityAndModel.Parameter <string>("city");
            topProductIdByCityAndModel.Parameter <int>("model");
            topProductIdByCityAndModel.Returns <string>();

            // function bound to a collection of entities
            FunctionConfiguration topProductOfAll = builder.EntityType <Product>().Collection.Function("TopProductOfAll");

            topProductOfAll.Returns <string>();

            FunctionConfiguration topProductOfAllByCity = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCity");

            topProductOfAllByCity.Parameter <string>("city");
            topProductOfAllByCity.Returns <string>();

            FunctionConfiguration topProductOfAllByCityAndModel = builder.EntityType <Product>().Collection.Function("TopProductOfAllByCityAndModel");

            topProductOfAllByCityAndModel.Parameter <string>("city");
            topProductOfAllByCityAndModel.Parameter <int>("model");
            topProductOfAllByCityAndModel.Returns <string>();

            // Function bound to the base entity type and derived entity type
            builder.EntityType <RoutingCustomer>().Function("GetOrdersCount").Returns <string>();
            builder.EntityType <VIP>().Function("GetOrdersCount").Returns <string>();

            // Overloaded function only bound to the base entity type with one paramter
            var getOrderCount = builder.EntityType <RoutingCustomer>().Function("GetOrdersCount");

            getOrderCount.Parameter <int>("factor");
            getOrderCount.Returns <string>();

            // Function only bound to the derived entity type
            builder.EntityType <SpecialVIP>().Function("GetSpecialGuid").Returns <string>();

            // Function bound to the collection of the base and the derived entity type
            builder.EntityType <RoutingCustomer>().Collection.Function("GetAllEmployees").Returns <string>();
            builder.EntityType <VIP>().Collection.Function("GetAllEmployees").Returns <string>();

            // Bound function with enum type parameters
            var boundFunction = builder.EntityType <RoutingCustomer>().Collection.Function("BoundFuncWithEnumParameters");

            boundFunction.Parameter <SimpleEnum>("SimpleEnum");
            boundFunction.Parameter <FlagsEnum>("FlagsEnum");
            boundFunction.Returns <string>();

            // Bound function with enum type parameter for attribute routing
            var boundFunctionForAttributeRouting = builder.EntityType <RoutingCustomer>().Collection
                                                   .Function("BoundFuncWithEnumParameterForAttributeRouting");

            boundFunctionForAttributeRouting.Parameter <SimpleEnum>("SimpleEnum");
            boundFunctionForAttributeRouting.Returns <string>();

            // Unbound function with enum type parameters
            var function = builder.Function("UnboundFuncWithEnumParameters");

            function.Parameter <LongEnum>("LongEnum");
            function.Parameter <FlagsEnum>("FlagsEnum");
            function.Returns <string>();

            // Unbound function
            builder.Function("UnboundFunction").ReturnsCollection <int>().IsComposable = true;

            // Action only bound to the derived entity type
            builder.EntityType <SpecialVIP>().Action("ActionBoundToSpecialVIP");

            // Action only bound to the derived entity type
            builder.EntityType <SpecialVIP>().Collection.Action("ActionBoundToSpecialVIPs");

            // Function only bound to the base entity collection type
            builder.EntityType <RoutingCustomer>().Collection.Function("FunctionBoundToRoutingCustomers").Returns <int>();

            // Function only bound to the derived entity collection type
            builder.EntityType <VIP>().Collection.Function("FunctionBoundToVIPs").Returns <int>();

            // Bound function with multiple parameters
            var functionBoundToProductWithMultipleParamters = builder.EntityType <Product>().Function("FunctionBoundToProductWithMultipleParamters");

            functionBoundToProductWithMultipleParamters.Parameter <int>("P1");
            functionBoundToProductWithMultipleParamters.Parameter <int>("P2");
            functionBoundToProductWithMultipleParamters.Parameter <string>("P3");
            functionBoundToProductWithMultipleParamters.Returns <int>();

            // Overloaded bound function with no parameter
            builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>();

            // Overloaded bound function with one parameter
            builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>().Parameter <int>("P1");

            // Overloaded bound function with multiple parameters
            var functionBoundToProduct = builder.EntityType <Product>().Function("FunctionBoundToProduct").Returns <int>();

            functionBoundToProduct.Parameter <int>("P1");
            functionBoundToProduct.Parameter <int>("P2");
            functionBoundToProduct.Parameter <string>("P3");

            // Unbound function with one parameter
            var unboundFunctionWithOneParamters = builder.Function("UnboundFunctionWithOneParamters");

            unboundFunctionWithOneParamters.Parameter <int>("P1");
            unboundFunctionWithOneParamters.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers");
            unboundFunctionWithOneParamters.IsComposable = true;

            // Unbound function with multiple parameters
            var functionWithMultipleParamters = builder.Function("UnboundFunctionWithMultipleParamters");

            functionWithMultipleParamters.Parameter <int>("P1");
            functionWithMultipleParamters.Parameter <int>("P2");
            functionWithMultipleParamters.Parameter <string>("P3");
            functionWithMultipleParamters.Returns <int>();

            // Overloaded unbound function with no parameter
            builder.Function("OverloadUnboundFunction").Returns <int>();

            // Overloaded unbound function with one parameter
            builder.Function("OverloadUnboundFunction").Returns <int>().Parameter <int>("P1");

            // Overloaded unbound function with multiple parameters
            var overloadUnboundFunction = builder.Function("OverloadUnboundFunction").Returns <int>();

            overloadUnboundFunction.Parameter <int>("P1");
            overloadUnboundFunction.Parameter <int>("P2");
            overloadUnboundFunction.Parameter <string>("P3");

            return(builder.GetEdmModel());
        }