Example #1
0
        private IEdmModel GetModel()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver(typeof(Customer)));
            ODataModelBuilder builder = new ODataConventionModelBuilder(config);

            builder.ContainerName = "C";
            builder.Namespace     = "A.B";
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

            ActionConfiguration primitive = customer.Action("Primitive");

            primitive.Parameter <int>("Quantity");
            primitive.Parameter <string>("ProductCode");

            ActionConfiguration complex = customer.Action("Complex");

            complex.Parameter <int>("Quantity");
            complex.Parameter <MyAddress>("Address");

            ActionConfiguration primitiveCollection = customer.Action("PrimitiveCollection");

            primitiveCollection.Parameter <string>("Name");
            primitiveCollection.CollectionParameter <int>("Ratings");

            ActionConfiguration complexCollection = customer.Action("ComplexCollection");

            complexCollection.Parameter <string>("Name");
            complexCollection.CollectionParameter <MyAddress>("Addresses");

            return(builder.GetEdmModel());
        }
Example #2
0
        private static IEdmModel CreateModelForFullMetadata(bool sameLinksForIdAndEdit, bool sameLinksForEditAndRead)
        {
            ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataModelBuilder>();

            EntitySetConfiguration <MainEntity> mainSet = builder.EntitySet <MainEntity>("MainEntity");

            Func <EntityInstanceContext <MainEntity>, Uri> idLinkFactory = (e) =>
                                                                           CreateAbsoluteUri("/MainEntity/id/" + e.GetPropertyValue("Id").ToString());

            mainSet.HasIdLink(idLinkFactory, followsConventions: true);

            if (!sameLinksForIdAndEdit)
            {
                Func <EntityInstanceContext <MainEntity>, Uri> editLinkFactory =
                    (e) => CreateAbsoluteUri("/MainEntity/edit/" + e.GetPropertyValue("Id").ToString());
                mainSet.HasEditLink(editLinkFactory, followsConventions: false);
            }

            if (!sameLinksForEditAndRead)
            {
                Func <EntityInstanceContext <MainEntity>, Uri> readLinkFactory =
                    (e) => CreateAbsoluteUri("/MainEntity/read/" + e.GetPropertyValue("Id").ToString());
                mainSet.HasReadLink(readLinkFactory, followsConventions: false);
            }

            EntityTypeConfiguration <MainEntity> main = mainSet.EntityType;

            main.HasKey <int>((e) => e.Id);
            main.Property <short>((e) => e.Int16);
            NavigationPropertyConfiguration mainToRelated = mainSet.EntityType.HasRequired((e) => e.Related);

            main.Action("DoAlways").ReturnsCollectionFromEntitySet <MainEntity>("MainEntity").HasActionLink((c) =>
                                                                                                            CreateAbsoluteUri("/MainEntity/DoAlways/" + c.GetPropertyValue("Id")),
                                                                                                            followsConventions: false);
            main.Action("DoSometimes").ReturnsCollectionFromEntitySet <MainEntity>(
                "MainEntity").HasActionLink((c) =>
                                            CreateAbsoluteUri("/MainEntity/DoSometimes/" + c.GetPropertyValue("Id")),
                                            followsConventions: false);

            main.Function("IsAlways").ReturnsCollectionFromEntitySet <MainEntity>("MainEntity").HasFunctionLink(c =>
                                                                                                                CreateAbsoluteUri(String.Format(
                                                                                                                                      "/MainEntity({0})/Default.IsAlways()", c.GetPropertyValue("Id"))),
                                                                                                                followsConventions: false);

            // action and function bound to collection
            main.Collection.Action("DoAllAction")
            .HasFeedActionLink(c => CreateAbsoluteUri("/MainEntity/Default.DoAllAction"), followsConventions: false);

            main.Collection.Function("DoAllFunction").Returns <int>()
            .HasFeedFunctionLink(
                c => CreateAbsoluteUri("/MainEntity/Default.DoAllFunction()"),
                followsConventions: false);

            mainSet.HasNavigationPropertyLink(mainToRelated, (c, p) => new Uri("/MainEntity/RelatedEntity/" +
                                                                               c.GetPropertyValue("Id"), UriKind.Relative), followsConventions: true);

            EntitySetConfiguration <RelatedEntity> related = builder.EntitySet <RelatedEntity>("RelatedEntity");

            return(builder.GetEdmModel());
        }
        private IEdmModel GetModel()
        {
            if (_model == null)
            {
                ODataModelBuilder builder = new ODataConventionModelBuilder();
                builder.ContainerName = "C";
                builder.Namespace     = "A.B";
                EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

                ActionConfiguration primitive = customer.Action("Primitive");
                primitive.Parameter <int>("Quantity");
                primitive.Parameter <string>("ProductCode");

                ActionConfiguration complex = customer.Action("Complex");
                complex.Parameter <int>("Quantity");
                complex.Parameter <MyAddress>("Address");

                ActionConfiguration primitiveCollection = customer.Action("PrimitiveCollection");
                primitiveCollection.Parameter <string>("Name");
                primitiveCollection.CollectionParameter <int>("Ratings");

                ActionConfiguration complexCollection = customer.Action("ComplexCollection");
                complexCollection.Parameter <string>("Name");
                complexCollection.CollectionParameter <MyAddress>("Addresses");

                _model = builder.GetEdmModel();
            }
            return(_model);
        }
Example #4
0
        private void AddActionsToProduct(EntityTypeConfiguration <Product> config)
        {
            config.Action("FinalPrice")
            .Returns <decimal>();

            config.Action("LowestPrice")
            .Returns <decimal>();
        }
Example #5
0
        private static void AddBoundActionsAndFunctions(EntityTypeConfiguration <Account> account)
        {
            account.Function("GetAddressFunction").Returns <Address>();

            account.Function("GetShipAddresses").ReturnsCollection <Address>();
            account.Action("IncreaseAgeAction").Returns <AccountInfo>();

            ActionConfiguration addShipAddress = account.Action("AddShipAddress");

            addShipAddress.Parameter <Address>("address");
            addShipAddress.Returns <int>();// Total ship addresses count.
        }
        private void AddActionsToOrder(EntityTypeConfiguration <Order> config)
        {
            config.Action("PaymentPending")
            .ReturnsFromEntitySet <Order>(WebApiOdataEntitySet.Orders);

            config.Action("PaymentPaid")
            .ReturnsFromEntitySet <Order>(WebApiOdataEntitySet.Orders)
            .Parameter <string>("PaymentMethodName");

            config.Action("PaymentRefund")
            .ReturnsFromEntitySet <Order>(WebApiOdataEntitySet.Orders)
            .Parameter <bool>("Online");

            config.Action("Cancel")
            .ReturnsFromEntitySet <Order>(WebApiOdataEntitySet.Orders);
        }
Example #7
0
        public static IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder        builder  = new ODataConventionModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;
            EntityTypeConfiguration <Order>    order    = builder.EntitySet <Order>("Orders").EntityType;

            // Add unbound function for get special customer.
            FunctionConfiguration getCustomersWithNameContaining = builder.Function("GetCustomersWithNameContaining");

            getCustomersWithNameContaining.Parameter <string>("ContainedString");
            getCustomersWithNameContaining.ReturnsCollectionFromEntitySet <Customer>("Customers");

            // Add bound action for updating order price.
            ActionConfiguration updateOrderPrice = order.Action("UpdateOrderPrice");

            updateOrderPrice.Parameter <string>("Price");
            updateOrderPrice.ReturnsFromEntitySet <Order>("Orders");

            // Add bound function for delete order from customer and return the rest orders.
            FunctionConfiguration deleteOrderFromCustomer = customer.Function("DeleteOrderFromCustomer");

            deleteOrderFromCustomer.Parameter <int>("OrderId");
            deleteOrderFromCustomer.ReturnsCollectionFromEntitySet <Order>("Orders");

            return(builder.GetEdmModel());
        }
        private void AddActionsToProduct(EntityTypeConfiguration <Product> config)
        {
            config.Action("FinalPrice")
            .Returns <decimal>();

            config.Action("LowestPrice")
            .Returns <decimal>();

            config.Action("CreateAttributeCombinations")
            .ReturnsCollectionFromEntitySet <ProductVariantAttributeCombination>(WebApiOdataEntitySet.ProductVariantAttributeCombinations);

            var manageAttributes = config.Action("ManageAttributes")
                                   .ReturnsCollectionFromEntitySet <ProductVariantAttribute>(WebApiOdataEntitySet.ProductVariantAttributes);

            manageAttributes.Parameter <bool>("Synchronize");
            manageAttributes.CollectionParameter <ManageAttributeType>("Attributes");
        }
Example #9
0
        private static void AddBoundActionsAndFunctions(EntityTypeConfiguration <Employee> employee)
        {
            var actionConfiguration = employee.Action("AddSkill");

            actionConfiguration.Parameter <Skill>("skill");
            actionConfiguration.ReturnsCollection <Skill>();

            var functionConfiguration = employee.Function("GetAccessLevel");

            functionConfiguration.Returns <AccessLevel>();
        }
Example #10
0
        public static void AddOdataServerEntityValidation <TEntity>(this EntityTypeConfiguration <TEntity> builder)
            where TEntity : class
        {
            var validateEntity =
                builder
                .Action("ValidateEntity")
                .Returns <string>();

            validateEntity.Parameter <string>("SetName");
            validateEntity.Parameter <TEntity>("Entity");
        }
Example #11
0
 private IEdmModel GetModel()
 {
     ODataModelBuilder builder = new ODataConventionModelBuilder();
     builder.ContainerName = "Container";
     builder.Namespace = "org.odata";
     EntityTypeConfiguration<Customer> customer = builder.EntitySet<Customer>("Customers").EntityType;
     ActionConfiguration action = customer.Action("DoSomething");
     action.Parameter<int>("p1");
     action.Parameter<Address>("p2");
     action.CollectionParameter<string>("p3");
     action.CollectionParameter<Address>("p4");
     return builder.GetEdmModel();
 }
Example #12
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EnableLowerCamelCase();
            builder.EntitySet <Core.Entities.User>("Users");
            EntityTypeConfiguration <Core.Entities.Organization> organization = builder.EntitySet <Core.Entities.Organization>("Organizations").EntityType;

            builder.EntitySet <Core.Entities.Affiliation>("Affiliations");
            builder.AddEntityType(typeof(Core.Entities.Affiliation));
            builder.EntitySet <Core.Entities.Action>("Actions");
            builder.EntitySet <Core.Entities.Beacon>("Beacons");
            builder.EntitySet <Core.Entities.Event>("Events");
            organization.Function("GetAffiliations").ReturnsCollection <Core.Entities.Affiliation>();
            organization.Action("AddAffiliation").Parameter <Core.Entities.Affiliation>("affiliation");
            organization.Action("RemoveAffiliation").Parameter <Core.Entities.Affiliation>("affiliation");

            IEdmModel model = builder.GetEdmModel();

            config.MapODataServiceRoute("odata", "api/beta", model);
            config.SetSerializeNullDynamicProperty(true);
        }
Example #13
0
        private IEdmModel GetModel()
        {
            ODataModelBuilder builder = ODataConventionModelBuilderFactory.Create();

            builder.ContainerName = "Container";
            builder.Namespace     = "org.odata";
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;
            ActionConfiguration action = customer.Action("DoSomething");

            action.Parameter <int>("p1");
            action.Parameter <Address>("p2");
            action.Parameter <Color?>("color");
            action.CollectionParameter <string>("p3");
            action.CollectionParameter <Address>("p4");
            action.CollectionParameter <Color?>("colors");

            action = customer.Collection.Action("MyAction");
            action.EntityParameter <Customer>("Customer");
            action.CollectionEntityParameter <Customer>("Customers");

            action           = customer.Action("CNSAction");
            action.Namespace = "customize";
            return(builder.GetEdmModel());
        }
        private static IEdmModel CreateModelForFullMetadata(bool sameLinksForIdAndEdit, bool sameLinksForEditAndRead)
        {
            ODataModelBuilder builder = new ODataModelBuilder();

            EntitySetConfiguration <MainEntity> mainSet = builder.EntitySet <MainEntity>("MainEntity");

            Func <EntityInstanceContext <MainEntity>, string> idLinkFactory = (e) =>
                                                                              CreateAbsoluteLink("/MainEntity/id/" + e.EntityInstance.Id.ToString());

            mainSet.HasIdLink(idLinkFactory, followsConventions: true);

            Func <EntityInstanceContext <MainEntity>, string> editLinkFactory;

            if (!sameLinksForIdAndEdit)
            {
                editLinkFactory = (e) => CreateAbsoluteLink("/MainEntity/edit/" + e.EntityInstance.Id.ToString());
                mainSet.HasEditLink(editLinkFactory, followsConventions: false);
            }

            Func <EntityInstanceContext <MainEntity>, string> readLinkFactory;

            if (!sameLinksForEditAndRead)
            {
                readLinkFactory = (e) => CreateAbsoluteLink("/MainEntity/read/" + e.EntityInstance.Id.ToString());
                mainSet.HasReadLink(readLinkFactory, followsConventions: false);
            }

            EntityTypeConfiguration <MainEntity> main = mainSet.EntityType;

            main.HasKey <int>((e) => e.Id);
            main.Property <short>((e) => e.Int16);
            NavigationPropertyConfiguration mainToRelated = mainSet.EntityType.HasRequired((e) => e.Related);

            main.Action("DoAlways").ReturnsCollectionFromEntitySet <MainEntity>("MainEntity").HasActionLink((c) =>
                                                                                                            CreateAbsoluteUri("/MainEntity/DoAlways/" + ((MainEntity)(c.EntityInstance)).Id),
                                                                                                            followsConventions: true);
            main.TransientAction("DoSometimes").ReturnsCollectionFromEntitySet <MainEntity>(
                "MainEntity").HasActionLink((c) =>
                                            CreateAbsoluteUri("/MainEntity/DoSometimes/" + ((MainEntity)(c.EntityInstance)).Id),
                                            followsConventions: false);

            mainSet.HasNavigationPropertyLink(mainToRelated, (c, p) => new Uri("/MainEntity/RelatedEntity/" +
                                                                               c.EntityInstance.Id, UriKind.Relative), followsConventions: true);

            EntitySetConfiguration <RelatedEntity> related = builder.EntitySet <RelatedEntity>("RelatedEntity");

            return(builder.GetEdmModel());
        }
        public void BuilderIncludesMapFromEntityTypeToBindableOperations()
        {
            // Arrange
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

            customer.HasKey(c => c.Id);
            customer.Property(c => c.Name);
            customer.Action("Reward");
            IEdmModel      model        = builder.GetEdmModel();
            IEdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault();

            // Act
            BindableOperationFinder finder = model.GetAnnotationValue <BindableOperationFinder>(model);

            // Assert
            Assert.NotNull(finder);
            Assert.NotNull(finder.FindOperations(customerType).SingleOrDefault());
            Assert.Equal("Reward", finder.FindOperations(customerType).SingleOrDefault().Name);
        }
Example #16
0
        public static IEdmModel GetModel()
        {
            ODataConventionModelBuilder      builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <Window>  windows = builder.EntitySet <Window>("Windows");
            EntityTypeConfiguration <Window> window  = windows.EntityType;

            // Action that takes in a base complex type.
            ActionConfiguration actionConfiguration = window.Action("AddOptionalShape");

            actionConfiguration.Parameter <Shape>("shape");
            actionConfiguration.Returns <int>(); // The number of all optional shapes

            // Function that returns a base complex type
            var functionConfiguration = window.Function("GetTheLastOptionalShape");

            functionConfiguration.Returns <Shape>();

            builder.Namespace = typeof(Window).Namespace;

            return(builder.GetEdmModel());
        }
Example #17
0
        public static IEdmModel GetModel()
        {
            ODataConventionModelBuilder        builder   = new ODataConventionModelBuilder();
            EntitySetConfiguration <Employee>  employees = builder.EntitySet <Employee>("Employees");
            EntityTypeConfiguration <Employee> employee  = employees.EntityType;

            // Action that adds a skill to the skill set.
            ActionConfiguration actionConfiguration = employee.Action("AddAccessLevel");

            actionConfiguration.Parameter <string>("AccessLevel");// Now action parameters does not support Enum type, so use string instead.
            actionConfiguration.Returns <AccessLevel>();

            // Function that tells whether an employee has the given AccessLevel
            var functionConfiguration = builder.Function("HasAccessLevel");

            functionConfiguration.Parameter <int>("ID");
            functionConfiguration.Parameter <AccessLevel>("AccessLevel");
            functionConfiguration.Returns <bool>();

            builder.Namespace = typeof(Employee).Namespace;

            return(builder.GetEdmModel());
        }