Exemplo n.º 1
0
        internal static void AddEntityType(DSPMetadata metadata, string entityTypeName, KeyValuePair <string, Type>[] properties, bool useComplexType, bool useOpenTypes)
        {
            var entityType = metadata.AddEntityType(entityTypeName, null, null, false);

            metadata.AddKeyProperty(entityType, "ID", typeof(int));
            entityType.IsOpenType = useOpenTypes;

            if (!useOpenTypes)
            {
                Microsoft.OData.Service.Providers.ResourceType resourceTypeForProps;
                if (useComplexType)
                {
                    string complexTypeName = GetComplexTypeName(entityTypeName);
                    resourceTypeForProps = metadata.AddComplexType(complexTypeName, null, null, false);
                    metadata.AddComplexProperty(entityType, "ComplexProperty", resourceTypeForProps);
                }
                else
                {
                    resourceTypeForProps = entityType;
                }

                foreach (KeyValuePair <string, Type> property in properties)
                {
                    metadata.AddPrimitiveProperty(resourceTypeForProps, property.Key, property.Value);
                }
            }

            string resourceSetName = GetResourceSetName(entityTypeName);

            metadata.AddResourceSet(resourceSetName, entityType);
        }
Exemplo n.º 2
0
        private static DSPMetadata GetModel(bool openType, bool namedStreams, Action <DSPMetadata> metadataModifier = null)
        {
            #region Model Definition
            // Navigation Collection Property: Client - Entity, Server - NonEntity
            DSPMetadata metadata = new DSPMetadata("ModelWithNonNullableProperties", "AstoriaUnitTests.Tests");

            // Define people type having non-nullable properties
            var peopleType = metadata.AddEntityType("PeopleType", null, null, false);
            var officeType = metadata.AddComplexType("OfficeType", null, null, false);
            metadata.AddPrimitiveProperty(officeType, "Building", typeof(string));
            metadata.AddPrimitiveProperty(officeType, "OfficeNumber", typeof(int));

            peopleType.IsOpenType = openType;
            metadata.AddKeyProperty(peopleType, "ID", typeof(int));
            if (!openType)
            {
                metadata.AddPrimitiveProperty(peopleType, "Name", typeof(string));
                metadata.AddPrimitiveProperty(peopleType, "Body", typeof(byte[]));
                metadata.AddPrimitiveProperty(peopleType, "Age", typeof(Nullable <int>));
                metadata.AddComplexProperty(peopleType, "Office", officeType);
            }

            var peopleSet = metadata.AddResourceSet("People", peopleType);

            if (metadataModifier != null)
            {
                metadataModifier(metadata);
            }

            metadata.SetReadOnly();
            #endregion Model Definition

            return(metadata);
        }
Exemplo n.º 3
0
        private static DSPServiceDefinition SetupService()
        {
            DSPMetadata metadata = new DSPMetadata("ActionsWithLargePayload", "AstoriaUnitTests.ActionTestsWithLargePayload");
            var         customer = metadata.AddEntityType("Customer", null, null, false);

            metadata.AddKeyProperty(customer, "ID", typeof(int));
            var customers = metadata.AddResourceSet("Customers", customer);

            ComplexType = metadata.AddComplexType("AddressComplexType", null, null, false);
            metadata.AddPrimitiveProperty(ComplexType, "ZipCode", typeof(int));
            metadata.AddPrimitiveProperty(ComplexType, "City", typeof(string));

            DSPContext context = new DSPContext();

            metadata.SetReadOnly();

            DSPResource customer1 = new DSPResource(customer);

            customer1.SetValue("ID", 1);
            context.GetResourceSetEntities("Customers").Add(customer1);

            MyDSPActionProvider actionProvider = new MyDSPActionProvider();

            SetUpActionWithLargeParameterPayload(actionProvider, metadata, customer);
            SetUpActionWithLargeCollectionParameterPayload(actionProvider, metadata, customer);
            SetupLargeNumberOfActions(actionProvider, metadata, customer);

            DSPServiceDefinition service = new DSPServiceDefinition()
            {
                Metadata           = metadata,
                CreateDataSource   = (m) => context,
                ForceVerboseErrors = true,
                Writable           = true,
                ActionProvider     = actionProvider,
            };

            return(service);
        }