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());
        }
        public void CanCreateActionWithPrimitiveCollectionReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = new ActionConfiguration(builder, "CreateMessages");
            action.ReturnsCollection<string>();

            // Assert
            Assert.NotNull(action.ReturnType);
            Assert.Equal("Collection(Edm.String)", action.ReturnType.FullName);
        }
        public void CanCreateActionWithPrimitiveCollectionReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("CreateMessages");

            action.ReturnsCollection <string>();

            // Assert
            Assert.NotNull(action.ReturnType);
            Assert.Equal("Collection(Edm.String)", action.ReturnType.FullName);
        }
Exemple #4
0
        private IEdmModel GetEdmModel(HttpConfiguration configuration)
        {
            ODataConventionModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataConventionModelBuilder>(configuration);

            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");

            return(builder.GetEdmModel());
        }
        public void CanCreateActionWithComplexReturnType()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            
            ActionConfiguration createAddress = new ActionConfiguration(builder, "CreateAddress");
            createAddress.Returns<Address>();
            
            ActionConfiguration createAddresses = new ActionConfiguration(builder, "CreateAddresses");
            createAddresses.ReturnsCollection<Address>();

            // Assert
            IComplexTypeConfiguration address = createAddress.ReturnType as IComplexTypeConfiguration;
            Assert.NotNull(address);
            Assert.Equal(typeof(Address).FullName, address.FullName);
            Assert.Null(createAddress.EntitySet);

            ICollectionTypeConfiguration addresses = createAddresses.ReturnType as ICollectionTypeConfiguration;
            Assert.NotNull(addresses);
            Assert.Equal(string.Format("Collection({0})", typeof(Address).FullName), addresses.FullName);
            address = addresses.ElementType as IComplexTypeConfiguration;
            Assert.NotNull(address);
            Assert.Equal(typeof(Address).FullName, address.FullName);
            Assert.Null(createAddresses.EntitySet);
        }
        public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context)
        {
            Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null.");

            ActionConfiguration updateItemDefinitionAction = modelBuilder.Action("UpdateItemDefinition");

            updateItemDefinitionAction.Parameter <string>("itemId");
            updateItemDefinitionAction.Parameter <string>("itemDefinition");
            updateItemDefinitionAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            ActionConfiguration createPriceCardAction = modelBuilder.Action("CreatePriceCard");

            createPriceCardAction.Parameter <string>("itemId");
            createPriceCardAction.Parameter <decimal>("price");
            createPriceCardAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            ActionConfiguration updatePriceSnapshotAction = modelBuilder.Action("UpdatePriceSnapshot");

            updatePriceSnapshotAction.Parameter <string>("itemId");
            updatePriceSnapshotAction.Parameter <decimal>("price");
            updatePriceSnapshotAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            ActionConfiguration addNewPriceSnapshotAction = modelBuilder.Action("AddNewPriceSnapshot");

            addNewPriceSnapshotAction.Parameter <string>("itemId");
            addNewPriceSnapshotAction.Parameter <decimal>("price");
            addNewPriceSnapshotAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            ActionConfiguration getDeliveryTimeAction = modelBuilder.Action("GetDeliveryTime");

            addNewPriceSnapshotAction.CollectionParameter <string>("itemIds");
            addNewPriceSnapshotAction.Parameter <string>("primaryInventorySetId");
            addNewPriceSnapshotAction.Parameter <string>("secondaryInventorySetId");
            addNewPriceSnapshotAction.ReturnsCollection <DeliveryTime>();

            ActionConfiguration addPartyAction = modelBuilder.Action("AddParty");

            addPartyAction.Parameter <string>("cartId");
            addPartyAction.Parameter <Party>("party");
            addPartyAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            ActionConfiguration removePartyAction = modelBuilder.Action("RemoveParty");

            removePartyAction.Parameter <string>("cartId");
            removePartyAction.Parameter <Party>("addressName");
            removePartyAction.ReturnsFromEntitySet <CommerceCommand>("Commands");


            // Counters
            var createCounterValueAction = modelBuilder.Action("CreateCounter");

            createCounterValueAction.Parameter <string>("counterName");
            createCounterValueAction.Parameter <long>("startValue");
            createCounterValueAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            var getNextCounterValueAction = modelBuilder.Action("GetNextCounterValue");

            getNextCounterValueAction.Parameter <string>("counterName");
            getNextCounterValueAction.Returns <long>();

            var getOrdernumberForCartAction = modelBuilder.Action("GetOrdernumberForCart");

            getOrdernumberForCartAction.Parameter <string>("cartId");
            getOrdernumberForCartAction.Returns <string>();


            return(Task.FromResult(modelBuilder));
        }
Exemple #7
0
        public static void Register(HttpConfiguration config)
        {
            IList <IODataRoutingConvention> routingConventions = ODataRoutingConventions.CreateDefault();

            routingConventions.Insert(0, new CountODataRoutingConvention());


            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <ApparatusType>("ApparatusTypes");
            builder.EntitySet <App>("Apps");

            builder.EntitySet <AppParam>("AppParams");
            builder.EntitySet <ProjectPart>("ProjectParts");
            builder.EntitySet <Remark>("Remarks");
            builder.EntitySet <TaskApp>("TaskApps");
            builder.EntitySet <MessureValue>("MessureValues");
            builder.EntitySet <CalculateValue>("CalculateValues");
            builder.EntitySet <Formula>("Formulae");

            ActionConfiguration rateProduct = builder.Entity <App>().Action("RateProduct");

            rateProduct.Parameter <int>("Rating");
            rateProduct.Returns <int>();


            ActionConfiguration actionRateAll = builder.Entity <App>().Collection.Action("RateAllProducts");

            actionRateAll.Parameter <int>("Rating");
            actionRateAll.Returns <int>();


            ActionConfiguration actionCheckExistData = builder.Entity <App>().Action("CheckExistData");

            actionCheckExistData.Parameter <DateTimeOffset>("date");
            actionCheckExistData.Returns <bool>();

            ActionConfiguration actionGetCalcValues = builder.Entity <App>().Collection.Action("GetCalcValues");

            actionGetCalcValues.Parameter <int>("topNum");
            actionGetCalcValues.Parameter <DateTimeOffset?>("startDate");
            actionGetCalcValues.Parameter <DateTimeOffset?>("endDate");
            actionGetCalcValues.CollectionParameter <Guid>("appids");
            actionGetCalcValues.ReturnsCollectionFromEntitySet <CalculateValue>("CalculateValues");


            ActionConfiguration actionGetMesValues = builder.Entity <App>().Collection.Action("GetMesValues");

            actionGetMesValues.Parameter <int>("topNum");
            actionGetMesValues.Parameter <DateTimeOffset?>("startDate");
            actionGetMesValues.Parameter <DateTimeOffset?>("endDate");
            actionGetMesValues.CollectionParameter <Guid>("appids");
            actionGetMesValues.ReturnsCollectionFromEntitySet <MessureValue>("MessureValues");


            ActionConfiguration actionGetRemarks = builder.Entity <App>().Collection.Action("GetRemarks");

            actionGetRemarks.Parameter <int>("topNum");
            actionGetRemarks.Parameter <DateTimeOffset?>("startDate");
            actionGetRemarks.Parameter <DateTimeOffset?>("endDate");
            actionGetRemarks.CollectionParameter <Guid>("appids");
            actionGetRemarks.ReturnsCollectionFromEntitySet <Remark>("Remarks");



            ActionConfiguration actionSearcyAppByName = builder.Entity <App>().Collection.Action("SearcyAppByName");

            actionSearcyAppByName.Parameter <string>("match");
            actionSearcyAppByName.ReturnsCollectionFromEntitySet <App>("Apps");

            ActionConfiguration actionSearcyAppCalcName = builder.Entity <App>().Collection.Action("SearcyAppCalcName");

            actionSearcyAppCalcName.Parameter <string>("match");
            actionSearcyAppCalcName.ReturnsCollectionFromEntitySet <App>("Apps");

            ActionConfiguration actionGetChildAppCalcName = builder.Entity <App>().Collection.Action("GetChildAppCalcName");

            actionGetChildAppCalcName.Parameter <string>("appCalcName");
            actionGetChildAppCalcName.Parameter <DateTimeOffset>("date");
            actionGetChildAppCalcName.ReturnsCollection <string>();


            ActionConfiguration actionGetAllFormulaeByAppID = builder.Entity <App>().Action("GetAllFormulaeByAppID");

            actionGetAllFormulaeByAppID.ReturnsCollectionFromEntitySet <Formula>("Formulae");


            ActionConfiguration actionUpdateAppsProject = builder.Entity <ProjectPart>().Action("UpdateAppsProject");

            actionUpdateAppsProject.CollectionParameter <Guid>("appids");
            actionUpdateAppsProject.Returns <bool>();


            ActionConfiguration actionUpdateAppsProjectByNames = builder.Entity <ProjectPart>().Action("UpdateAppsProjectByNames");

            actionUpdateAppsProjectByNames.CollectionParameter <string>("names");
            actionUpdateAppsProjectByNames.Returns <bool>();

            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel(), new CountODataPathHandler(), routingConventions,
                                        new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));



            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });
        }