当前位置: 首页>>代码示例>>C#>>正文


C# ResourceType.AddProperty方法代码示例

本文整理汇总了C#中Microsoft.OData.Service.Providers.ResourceType.AddProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceType.AddProperty方法的具体用法?C# ResourceType.AddProperty怎么用?C# ResourceType.AddProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.OData.Service.Providers.ResourceType的用法示例。


在下文中一共展示了ResourceType.AddProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerifyVersionOfEntityWithGeographyPropertyIsV3

        public void VerifyVersionOfEntityWithGeographyPropertyIsV3()
        {
            ResourceType rt = new ResourceType(typeof(IDictionary<string, string>), ResourceTypeKind.EntityType, null, "TestNamespace", "TestEntity", false);
            var keyProperty = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) {CanReflectOnInstanceTypeProperty = false };
            var geographyProperty = new ResourceProperty("GeographyProperty", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(Geography))) { CanReflectOnInstanceTypeProperty = false };
            rt.AddProperty(keyProperty);
            rt.AddProperty(geographyProperty);
            rt.SetReadOnly();

            Assert.AreEqual(v4, rt.MetadataVersion, "MetadataVersion must be 4.0");
            Assert.AreEqual(MetadataEdmSchemaVersion.Version4Dot0, rt.SchemaVersion, "Schema version must be 4.0");
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:12,代码来源:ResourceTypeTests.cs

示例2: OperationLinkBuilderTests

        public OperationLinkBuilderTests()
        {
            ResourceType intType = ResourceType.GetPrimitiveResourceType(typeof(int));

            var customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "FQ.NS", "Customer", false);
            customerType.CanReflectOnInstanceType = false;
            customerType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, intType) { CanReflectOnInstanceTypeProperty = false });
            customerType.SetReadOnly();

            var operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType), new ServiceActionParameter("P2", intType) }, null);
            operation.SetReadOnly();
            this.operationWithParameters = new OperationWrapper(operation);

            var typeWithEscapedName = new ResourceType(typeof(object), ResourceTypeKind.ComplexType, null, "FQ NS", "+ /", false);
            typeWithEscapedName.CanReflectOnInstanceType = false;
            typeWithEscapedName.AddProperty(new ResourceProperty("Number", ResourcePropertyKind.Primitive, intType) { CanReflectOnInstanceTypeProperty = false });
            typeWithEscapedName.SetReadOnly();

            operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType), new ServiceActionParameter("P2", typeWithEscapedName) }, null);
            operation.SetReadOnly();
            this.operationWithEscapedParameter = new OperationWrapper(operation);

            var bestCustomerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, customerType, "FQ.NS", "BestCustomer", false);
            bestCustomerType.SetReadOnly();

            operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType) }, null);
            operation.SetReadOnly();
            this.operationBoundToBaseType = new OperationWrapper(operation);

            this.entityToSerialize = EntityToSerialize.CreateFromExplicitValues(new object(), bestCustomerType, new TestSerializedEntityKey("http://odata.org/Service.svc/Customers/", bestCustomerType.FullName));

            var metadataUri = new Uri("http://odata.org/Service.svc/$metadata");
            this.testSubject = new OperationLinkBuilder("MyContainer", metadataUri);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:34,代码来源:OperationLinkBuilderTests.cs

示例3: DataServiceProviderWrapperShouldFailOnMultipleActionsWithSameNameAndBindingType

        public void DataServiceProviderWrapperShouldFailOnMultipleActionsWithSameNameAndBindingType()
        {
            var entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Fake.NS", "Type", false) { CanReflectOnInstanceType = false };
            entityType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) {CanReflectOnInstanceTypeProperty = false});
            entityType.SetReadOnly();

            var resourceSet = new ResourceSet("MyEntitySet", entityType);
            resourceSet.SetReadOnly();

            ResourceType stringType = ResourceType.GetPrimitiveResourceType(typeof(string));
            var duplicateAction1 = new ServiceAction("Duplicate", stringType, OperationParameterBindingKind.Always, new[] { new ServiceActionParameter("p1", entityType), new ServiceActionParameter("p2", stringType) }, null);
            duplicateAction1.SetReadOnly();
            var duplicateAction2 = new ServiceAction("Duplicate", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", entityType) }, null);
            duplicateAction2.SetReadOnly();

            var actionProvider = new TestActionProvider
            {
                GetServiceActionsCallback = ctx => new[] { duplicateAction1, duplicateAction2 }
            };

            var providerWrapper = CreateProviderWrapper(actionProvider, p => p.AddResourceSet(resourceSet));

            Action getVisibleOperations = () => providerWrapper.GetVisibleOperations().ToList();
            getVisibleOperations.ShouldThrow<DataServiceException>()
                .WithMessage(ErrorStrings.DataServiceActionProviderWrapper_DuplicateAction("Duplicate"))
                .And.StatusCode.Should().Be(500);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:27,代码来源:DataServiceProviderWrapperTests.cs

示例4: GetTestInstance

        /// <summary>
        /// Returns a test instance of one of the provider OM types.
        /// </summary>
        /// <param name="type">The type to get instance of.</param>
        /// <returns>The </returns>
        public static object GetTestInstance(Type type)
        {
            if (type == typeof(ResourceType))
            {
                ResourceProperty p = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false };
                ResourceType resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "NoBaseType", false);
                Assert.IsTrue(resourceType.KeyProperties.Count == 0, "It's okay not to have key properties, since we haven't set this type to readonly yet");
                resourceType.AddProperty(p);
                return resourceType;
            }
            else if (type == typeof(ResourceProperty))
            {
                return new ResourceProperty("NonKeyProperty", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)));
            }
            else if (type == typeof(ServiceOperation))
            {
                ServiceOperationParameter parameter = new ServiceOperationParameter("o", ResourceType.GetPrimitiveResourceType(typeof(string)));
                ServiceOperation operation = new ServiceOperation("Dummy", ServiceOperationResultKind.Void, null, null, "POST", new ServiceOperationParameter[] { parameter });
                return operation;
            }
            else if (type == typeof(ServiceOperationParameter))
            {
                return new ServiceOperationParameter("o", ResourceType.GetPrimitiveResourceType(typeof(string)));
            }
            else if (type == typeof(ResourceSet))
            {
                ResourceProperty p = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int)));

                ResourceType resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "NoBaseType", false);
                resourceType.AddProperty(p);
                return new ResourceSet("Customers", resourceType);
            }

            throw new Exception(String.Format("Unexpected type encountered: '{0}'", type.FullName));
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:40,代码来源:ResourceTypeUtils.cs

示例5: OperationSerializerTests

        public OperationSerializerTests()
        {
            ResourceType intType = ResourceType.GetPrimitiveResourceType(typeof(int));

            var customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "FQ.NS", "Customer", false);
            customerType.CanReflectOnInstanceType = false;
            customerType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, intType) { CanReflectOnInstanceTypeProperty = false });
            customerType.SetReadOnly();

            var operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType), new ServiceActionParameter("P2", intType) }, null);
            operation.SetReadOnly();
            this.baseTypeOperation = new OperationWrapper(operation);

            var bestCustomerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, customerType, "FQ.NS", "BestCustomer", false);
            bestCustomerType.SetReadOnly();

            operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", bestCustomerType) }, null);
            operation.SetReadOnly();
            this.derivedTypeOperation = new OperationWrapper(operation);

            operation = new ServiceAction("Unambiguous", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType) }, null);
            operation.SetReadOnly();
            this.unambiguousOperation = new OperationWrapper(operation);

            this.entityToSerialize = EntityToSerialize.CreateFromExplicitValues(new object(), bestCustomerType, new TestSerializedEntityKey("http://odata.org/Service.svc/Customers(0)/", bestCustomerType.FullName));

            this.testSubject = CreateOperationSerializer(AlwaysAdvertiseActions);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:28,代码来源:OperationSerializerTests.cs

示例6: InvalidCasesTest

        public void InvalidCasesTest()
        {
            ResourceProperty id = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false };
            ResourceType customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "CustomerType", false);
            customerType.AddProperty(id);
            ResourceType orderType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "OrderType", false);
            orderType.AddProperty(id);

            ResourceProperty customerOrders = new ResourceProperty("Orders", ResourcePropertyKind.ResourceSetReference, orderType);
            ResourceProperty orderCustomer = new ResourceProperty("Customer", ResourcePropertyKind.ResourceReference, customerType);
            customerType.AddProperty(customerOrders);
            orderType.AddProperty(orderCustomer);
            customerOrders.CanReflectOnInstanceTypeProperty = false;
            orderCustomer.CanReflectOnInstanceTypeProperty = false;
            customerType.SetReadOnly();
            orderType.SetReadOnly();

            ResourceSet customerSet = new ResourceSet("Customers", customerType);
            ResourceSet orderSet = new ResourceSet("Orders", orderType);

            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSetEnd),
                "Value cannot be null.\r\nParameter name: resourceSet",
                null, customerType, customerOrders);

            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSetEnd),
                "Value cannot be null.\r\nParameter name: resourceType",
                customerSet, null, customerOrders);

            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSetEnd),
                "The resourceProperty parameter must be a navigation property on the resource type specified by the resourceType parameter.",
                customerSet, customerType, id);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSetEnd),
                "The resourceProperty parameter must be a navigation property on the resource type specified by the resourceType parameter.",
                customerSet, customerType, orderCustomer);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSetEnd),
                "The resourceType parameter must be a type that is assignable to the resource set specified by the resourceSet parameter.",
                customerSet,
                orderType,
                orderCustomer);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:45,代码来源:ResourceAssociationSetEndTests.cs

示例7: InvalidCasesTest

        public void InvalidCasesTest()
        {
            ResourceProperty id = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false };
            ResourceType customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "CustomerType", false);
            customerType.AddProperty(id);
            ResourceType orderType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "OrderType", false);
            orderType.AddProperty(id);

            ResourceProperty customerOrders = new ResourceProperty("Orders", ResourcePropertyKind.ResourceSetReference, orderType);
            ResourceProperty orderCustomer = new ResourceProperty("Customer", ResourcePropertyKind.ResourceReference, customerType);
            customerType.AddProperty(customerOrders);
            orderType.AddProperty(orderCustomer);
            customerOrders.CanReflectOnInstanceTypeProperty = false;
            orderCustomer.CanReflectOnInstanceTypeProperty = false;
            customerType.SetReadOnly();
            orderType.SetReadOnly();

            ResourceSet customerSet = new ResourceSet("Customers", customerType);
            ResourceSet orderSet = new ResourceSet("Orders", orderType);

            ResourceAssociationSetEnd end1 = new ResourceAssociationSetEnd(customerSet, customerType, null);
            ResourceAssociationSetEnd end2 = new ResourceAssociationSetEnd(orderSet, orderType, null);

            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet), 
                "Value cannot be null or empty.\r\nParameter name: name", 
                null, end1, end2);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet), 
                "Value cannot be null or empty.\r\nParameter name: name", 
                string.Empty, end1, end2);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet), 
                "Value cannot be null.\r\nParameter name: end1", 
                "Customer_Order", null, end2);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet), 
                "Value cannot be null.\r\nParameter name: end2", 
                "Customer_Order", end1, null);
            ExceptionUtils.CheckInvalidConstructorParameters(
                typeof(ResourceAssociationSet),
                "The ResourceProperty of the ResourceAssociationEnds cannot both be null.", 
                "Customer_Order", end1, end2);

        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:45,代码来源:ResourceAssociationSetTests.cs

示例8: CreateEntityToSerialize

        private static EntityToSerialize CreateEntityToSerialize(bool shouldIncludeTypeSegment)
        {
            ResourceType baseType = new ResourceType(typeof(MyType), ResourceTypeKind.EntityType, null, "TestNamespace", "BaseType", /*isAbstract*/ false);
            baseType.AddProperty(new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, new ResourceType(typeof(int), ResourceTypeKind.Primitive, null, "int")));

            baseType.SetReadOnly();

            Uri serviceUri = new Uri("http://dummy");

            KeySerializer keySerializer = KeySerializer.Create(UrlConvention.CreateWithExplicitValue(false));

            Func<ResourceProperty, object> getPropertyValue = p => "fakePropertyValue";
            return EntityToSerialize.Create(new MyType { ID = 42 }, baseType, "MySet", shouldIncludeTypeSegment, getPropertyValue, keySerializer, serviceUri);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:14,代码来源:EntityToSerializeTests.cs

示例9: Initialize

        public void Initialize()
        {
            this.host = new DataServiceHost2Simulator();

            var context = new DataServiceOperationContext(this.host);
            this.dataServiceSimulator = new DataServiceSimulator { OperationContext = context };

            var providerSimulator = new DataServiceProviderSimulator();

            DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(this.dataServiceSimulator.Instance.GetType(), providerSimulator);
            IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior;

            var resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "SelectTestNamespace", "Fake", false) { CanReflectOnInstanceType = false, IsOpenType = true };
            resourceType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false });
            var resourceSet = new ResourceSet("FakeSet", resourceType);
            resourceSet.SetReadOnly();

            providerSimulator.AddResourceSet(resourceSet);

            var configuration = new DataServiceConfiguration(providerSimulator);
            configuration.SetEntitySetAccessRule("*", EntitySetRights.All);

            var provider = new DataServiceProviderWrapper(
                new DataServiceCacheItem(
                    configuration,
                    staticConfiguration), 
                providerSimulator, 
                providerSimulator, 
                this.dataServiceSimulator,
                false);

            this.dataServiceSimulator.ProcessingPipeline = new DataServiceProcessingPipeline();
            this.dataServiceSimulator.Provider = provider;
            provider.ProviderBehavior = providerBehavior;
            this.dataServiceSimulator.Configuration = new DataServiceConfiguration(providerSimulator);
            this.dataServiceSimulator.Configuration.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4;

            this.responseMessageSimulator = new ODataResponseMessageSimulator();
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:39,代码来源:MessageWriterBuilderTests.cs

示例10: ResourceTypeMustBeDeclaringType_2

        public void ResourceTypeMustBeDeclaringType_2()
        {
            ResourceType baseCustomerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Test", "Employee", true /*isAbstract*/);
            ResourceType customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, baseCustomerType, "Test", "Customer", false /*isAbstract*/);
            ResourceSet customerSet = new ResourceSet("CustomerSet", customerType);

            ResourceType orderType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Test", "Employee", false /*isAbstract*/);
            ResourceProperty orderProperty = new ResourceProperty("Orders", ResourcePropertyKind.ResourceSetReference, orderType);
            baseCustomerType.AddProperty(orderProperty);

            try
            {
                new ResourceAssociationSetEnd(customerSet, customerType, orderProperty);
                Assert.Fail("Creating resource association set end should never have succeeded");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(
                    DataServicesResourceUtil.GetString("ResourceAssociationSetEnd_ResourceTypeMustBeTheDeclaringType", customerType.FullName, orderProperty.Name),
                    e.Message);
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:22,代码来源:ResourceAssociationTests.cs

示例11: GetTargetSetTestsSetBindingTypeShouldPerformCorrectValidation

        public void GetTargetSetTestsSetBindingTypeShouldPerformCorrectValidation()
        {
            ResourceType actorEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "foo", "Actor", false) { CanReflectOnInstanceType = false };
            ResourceProperty idProperty = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false };
            actorEntityType.AddProperty(idProperty);

            ResourceType addressComplexType = new ResourceType(typeof(object), ResourceTypeKind.ComplexType, null, "foo", "Address", false) { CanReflectOnInstanceType = false };
            addressComplexType.AddProperty(new ResourceProperty("StreetAddress", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string))) { CanReflectOnInstanceTypeProperty = false });
            addressComplexType.AddProperty(new ResourceProperty("ZipCode", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false });

            actorEntityType.AddProperty(new ResourceProperty("PrimaryAddress", ResourcePropertyKind.ComplexType, addressComplexType) { CanReflectOnInstanceTypeProperty = false });
            actorEntityType.AddProperty(new ResourceProperty("OtherAddresses", ResourcePropertyKind.Collection, ResourceType.GetCollectionResourceType(addressComplexType)) { CanReflectOnInstanceTypeProperty = false });

            ResourceType movieEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "foo", "Movie", false) { CanReflectOnInstanceType = false };
            movieEntityType.AddProperty(idProperty);

            ResourceProperty moviesNavProp = new ResourceProperty("Movies", ResourcePropertyKind.ResourceSetReference, movieEntityType) { CanReflectOnInstanceTypeProperty = false };
            actorEntityType.AddProperty(moviesNavProp);
            ResourceProperty actorsNavProp = new ResourceProperty("Actors", ResourcePropertyKind.ResourceSetReference, actorEntityType) { CanReflectOnInstanceTypeProperty = false };
            movieEntityType.AddProperty(actorsNavProp);

            ResourceType derivedActorEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, actorEntityType, "foo", "DerivedActor", false) { CanReflectOnInstanceType = false };
            ResourceType derivedMovieEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, movieEntityType, "foo", "DerivedMovie", false) { CanReflectOnInstanceType = false };

            actorEntityType.SetReadOnly();
            derivedActorEntityType.SetReadOnly();
            movieEntityType.SetReadOnly();
            derivedMovieEntityType.SetReadOnly();
            addressComplexType.SetReadOnly();
            DataServiceProviderSimulator providerSimulator = new DataServiceProviderSimulator();
            providerSimulator.AddResourceType(actorEntityType);
            providerSimulator.AddResourceType(derivedActorEntityType);
            providerSimulator.AddResourceType(movieEntityType);
            providerSimulator.AddResourceType(derivedMovieEntityType);
            providerSimulator.AddResourceType(addressComplexType);

            ResourceSet actorSet = new ResourceSet("Actors", actorEntityType);
            ResourceSet movieSet = new ResourceSet("Movies", movieEntityType);
            actorSet.SetReadOnly();
            movieSet.SetReadOnly();
            providerSimulator.AddResourceSet(actorSet);
            providerSimulator.AddResourceSet(movieSet);

            providerSimulator.AddResourceAssociationSet(new ResourceAssociationSet("Actors_Movies", new ResourceAssociationSetEnd(actorSet, actorEntityType, moviesNavProp), new ResourceAssociationSetEnd(movieSet, movieEntityType, actorsNavProp)));

            DataServiceConfiguration config = new DataServiceConfiguration(providerSimulator);
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4;

            var dataService = new DataServiceSimulator()
            {
                OperationContext = new DataServiceOperationContext(new DataServiceHostSimulator())
            };

            dataService.ProcessingPipeline = new DataServiceProcessingPipeline();
            DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(dataService.Instance.GetType(), providerSimulator);
            IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior;

            DataServiceProviderWrapper provider = new DataServiceProviderWrapper(
                new DataServiceCacheItem(
                    config, 
                    staticConfiguration), 
                providerSimulator, 
                providerSimulator, 
                dataService,
                false);
            dataService.Provider = provider;
            provider.ProviderBehavior = providerBehavior;

            var testCases = new[]
            {
                new
                {
                    AppendParameterName = true,
                    Path = "",
                    BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set),
                    TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set),
                    ErrorMessage = default(string)
                },
                new
                {
                    AppendParameterName = true,
                    Path = "/Movies",
                    BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set),
                    TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(movieSet, provider, set => set),
                    ErrorMessage = default(string)
                },
                new
                {
                    AppendParameterName = true,
                    Path = "/Movies/Actors/Movies",
                    BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set),
                    TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(movieSet, provider, set => set),
                    ErrorMessage = default(string)
                },
                new
                {
                    AppendParameterName = true,
                    Path = "/foo.DerivedActor/Movies/foo.DerivedMovie/Actors/foo.DerivedActor/Movies",
                    BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set),
//.........这里部分代码省略.........
开发者ID:AlineGuan,项目名称:odata.net,代码行数:101,代码来源:MetadataObjectModelTests.cs

示例12: BuildTypeProperties


//.........这里部分代码省略.........
                                    // Note that we can't just make IEnumerable<T> not be a complex types since in certain cases we used to recognize it as such
                                    //   and we would break those cases. One example is user registered known types.
                                    Type collectionType = GetIEnumerableElement(resourcePropertyType);
                                    if (collectionType != null)
                                    {
                                        throw new InvalidOperationException(Strings.ReflectionProvider_CollectionOfCollectionProperty(property.Name, parentResourceType.FullName));
                                    }

                                    kind = ResourcePropertyKind.Collection;
                                }
                                else
                                {
                                    kind = ResourcePropertyKind.ComplexType;
                                }
                            }
                            else
                            {
                                Debug.Assert(resourceType.ResourceTypeKind == ResourceTypeKind.EntityType, "Must be an entity type");
                                kind = collection ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference;
                            }
                        }
                    }

                    // if resource type is null OR
                    // if complex type has a property of entity type
                    if (resourceType == null ||
                        (resourceType.ResourceTypeKind == ResourceTypeKind.EntityType && parentResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType))
                    {
                        if (resourceType == null)
                        {
                            // Provide a better error message for collection of collection
                            if (collection && GetIEnumerableElement(resourcePropertyType) != null)
                            {
                                throw new InvalidOperationException(Strings.ReflectionProvider_CollectionOfCollectionProperty(property.Name, parentResourceType.FullName));
                            }

                            // Provide a better error message for collection of wrong types
                            if (collection)
                            {
                                throw new InvalidOperationException(Strings.ReflectionProvider_CollectionOfUnsupportedTypeProperty(property.Name, parentResourceType.FullName, resourcePropertyType));
                            }

                            if (CommonUtil.IsUnsupportedType(resourcePropertyType))
                            {
                                throw new InvalidOperationException(Strings.BadProvider_UnsupportedPropertyType(property.Name, parentResourceType.FullName));
                            }

                            throw new InvalidOperationException(Strings.ReflectionProvider_InvalidProperty(property.Name, parentResourceType.FullName));
                        }

                        // Navigation property on a complex type is not supported
                        throw new InvalidOperationException(Strings.ReflectionProvider_ComplexTypeWithNavigationProperty(property.Name, parentResourceType.FullName));
                    }

                    if (resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
                    {
                        ResourceSet container = InternalGetContainerForResourceType(resourcePropertyType, metadataCacheItem.EntitySets.Values);
                        if (container == null)
                        {
                            throw new InvalidOperationException(Strings.ReflectionProvider_EntityPropertyWithNoEntitySet(parentResourceType.FullName, property.Name));
                        }
                    }

                    if (kind == ResourcePropertyKind.Collection)
                    {
                        // Collection properties need the collection type (representing the IEnumerable<> part).
                        resourceType = ResourceType.GetCollectionResourceType(resourceType);
                    }

                    if (etagPropertyNames.Remove(property.Name))
                    {
                        kind |= ResourcePropertyKind.ETag;
                    }

                    ResourceProperty resourceProperty = new ResourceProperty(property.Name, kind, resourceType);
                    MimeTypeAttribute attribute = BaseServiceProvider.GetMimeTypeAttribute(property);
                    if (attribute != null)
                    {
                        resourceProperty.MimeType = attribute.MimeType;
                    }

                    parentResourceType.AddProperty(resourceProperty);
                }
                else
                {
                    throw new InvalidOperationException(Strings.ReflectionProvider_InvalidProperty(property.Name, parentResourceType.FullName));
                }
            }

            if (parentResourceType.ResourceTypeKind == ResourceTypeKind.EntityType &&
                (parentResourceType.KeyProperties == null || parentResourceType.KeyProperties.Count == 0))
            {
                throw new InvalidOperationException(Strings.ReflectionProvider_KeyPropertiesCannotBeIgnored(parentResourceType.FullName));
            }

            if (etagPropertyNames.Count != 0)
            {
                throw new InvalidOperationException(Strings.ReflectionProvider_ETagPropertyNameNotValid(etagPropertyNames.ElementAt(0), parentResourceType.FullName));
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:ReflectionServiceProvider.cs

示例13: CreateResourceTypeWithKeyProperties

        private static ResourceType CreateResourceTypeWithKeyProperties(params string[] keyPropertyNames)
        {
            var resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "FQ.NS", "EntityType", false) {CanReflectOnInstanceType = false};

            foreach (var keyPropertyName in keyPropertyNames)
            {
                resourceType.AddProperty(new ResourceProperty(keyPropertyName, ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) {CanReflectOnInstanceTypeProperty = false});
            }

            resourceType.SetReadOnly();
            return resourceType;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:12,代码来源:MetadataProviderEdmModelTests.cs

示例14: PopulateMetadata

        private static IDataServiceMetadataProvider PopulateMetadata(object dataSourceInstance)
        {
            List<ResourceType> types = new List<ResourceType>(4);
            ResourceType customer = new ResourceType(
                typeof(RowEntityTypeWithIDAsKey),
                ResourceTypeKind.EntityType,
                null, /*baseType*/
                "AstoriaUnitTests.Stubs", /*namespaceName*/
                "Customer",
                false /*isAbstract*/);

            customer.CanReflectOnInstanceType = false;

            ResourceType order = new ResourceType(
                typeof(RowEntityTypeWithIDAsKey),
                ResourceTypeKind.EntityType,
                null,
                "AstoriaUnitTests.Stubs",
                "Order",
                false);

            order.CanReflectOnInstanceType = false;

            ResourceType region = new ResourceType(
                typeof(RowEntityTypeWithIDAsKey),
                ResourceTypeKind.EntityType,
                null, /*baseType*/
                "AstoriaUnitTests.Stubs", /*namespaceName*/
                "Region",
                false /*isAbstract*/);

            region.CanReflectOnInstanceType = false;

            ResourceType address = new ResourceType(
                typeof(RowComplexType),
                ResourceTypeKind.ComplexType,
                null,
                "AstoriaUnitTests.Stubs",
                "Address",
                false);

            address.CanReflectOnInstanceType = false;

            ResourceType product = new ResourceType(
                typeof(RowEntityTypeWithIDAsKey),
                ResourceTypeKind.EntityType,
                null, /*baseType*/
                "AstoriaUnitTests.Stubs", /*namespaceName*/
                "Product",
                false /*isAbstract*/);

            product.CanReflectOnInstanceType = false;

            ResourceType orderDetail = new ResourceType(
                typeof(RowEntityType),
                ResourceTypeKind.EntityType,
                null, /*baseType*/
                "AstoriaUnitTests.Stubs", /*namespaceName*/
                "OrderDetail",
                false /*isAbstract*/);

            orderDetail.CanReflectOnInstanceType = false;

            ResourceType currency = new ResourceType(
                typeof(RowComplexType),
                ResourceTypeKind.ComplexType,
                null,
                "AstoriaUnitTests.Stubs",
                "CurrencyAmount",
                false);

            ResourceType headquarter = new ResourceType(
                typeof(RowComplexType),
                ResourceTypeKind.ComplexType,
                null,
                "AstoriaUnitTests.Stubs",
                "Headquarter",
                false);

            headquarter.CanReflectOnInstanceType = false;

            ResourceSet customerEntitySet = new ResourceSet("Customers", customer);
            ResourceSet orderEntitySet = new ResourceSet("Orders", order);
            ResourceSet regionEntitySet = new ResourceSet("Regions", region);
            ResourceSet productEntitySet = new ResourceSet("Products", product);
            ResourceSet orderDetailEntitySet = new ResourceSet("OrderDetails", orderDetail);

            ResourceSet memberCustomerEntitySet = new ResourceSet("MemberCustomers", customer);
            ResourceSet memberOrderEntitySet = new ResourceSet("MemberOrders", order);
            ResourceSet memberRegionEntitySet = new ResourceSet("MemberRegions", region);
            ResourceSet memberProductEntitySet = new ResourceSet("MemberProducts", product);
            ResourceSet memberOrderDetailEntitySet = new ResourceSet("MemberOrderDetails", orderDetail);

            ResourceProperty keyProperty = new ResourceProperty(
                "ID",
                ResourcePropertyKind.Key | ResourcePropertyKind.Primitive,
                ResourceType.GetPrimitiveResourceType(typeof(int)));

            // populate customer properties
            customer.AddProperty(keyProperty);
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:CustomRowBasedContext.cs

示例15: AddNamedStreamValidationTest

        public void AddNamedStreamValidationTest()
        {
            ResourceProperty idProperty = new ResourceProperty("ID", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)));
            ResourceProperty name = new ResourceProperty("Name", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)));
            idProperty.CanReflectOnInstanceTypeProperty = false;
            name.CanReflectOnInstanceTypeProperty = false;

            ResourceType entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "namespace", "entityType", false);

            // Adding named stream to readonly type
            entityType.AddProperty(idProperty);
            entityType.SetReadOnly();
            ResourceProperty stream1 = new ResourceProperty("Stream1", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)));
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => entityType.AddProperty(stream1),
                string.Format("The resource type '{0}' cannot be modified since it is already set to read-only.", entityType.FullName),
                "Adding to a sealed type should fail.");

            // Adding a named stream which will collide with properties declared on this type
            ResourceType type1 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "namespace", "type1", true);
            type1.AddProperty(idProperty);
            ResourceProperty idStream = new ResourceProperty("ID", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)));
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => type1.AddProperty(idStream),
                "A property with same name 'ID' already exists in type 'namespace.type1'. Please make sure that there is no property with the same name defined in one of the base types.",
                "Named stream can't have the same name as a property.");

            // Adding a named stream which will collide with properties declared on base type
            type1 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "namespace", "type1", true);
            type1.AddProperty(idProperty);
            ResourceType type2 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, type1, "namespace", "type2", false);
            // We don't detect name collision between named streams and properties until we enumerate properties after the type is set to readonly.
            idStream = new ResourceProperty("ID", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)));
            type2.AddProperty(idStream);
            type2.Properties.Count();
            type2.SetReadOnly();
            // Detect name collision now.
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => type2.Properties.Count(),
                "A property with same name 'ID' already exists in type 'namespace.type2'. Please make sure that there is no property with the same name defined in one of the base types.",
                "Named stream can't have the same name as a property on base type.");

            // Adding a named stream which will collide with named streams declared on this type
            type1 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "namespace", "type1", true);
            type1.AddProperty(idProperty);
            ResourceProperty nameStream = new ResourceProperty("Name", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)));
            type1.AddProperty(nameStream);
            // Adding the same named stream instance
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => type1.AddProperty(nameStream),
                "A property with same name 'Name' already exists in type 'namespace.type1'. Please make sure that there is no property with the same name defined in one of the base types.",
                "Named stream can't have the same name as another named stream.");
            // Adding a new instance with the same name
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => type1.AddProperty(new ResourceProperty("Name", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)))),
                "A property with same name 'Name' already exists in type 'namespace.type1'. Please make sure that there is no property with the same name defined in one of the base types.",
                "Named stream can't have the same name as another named stream - new instance.");

            // Adding a named stream which will collide with named streams declared on base type
            type1 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "namespace", "type1", true);
            type1.AddProperty(idProperty);
            type1.AddProperty(nameStream);
            type2 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, type1, "namespace", "type2", false);
            type2.AddProperty(nameStream);  // Adding the same instance
            type2.SetReadOnly();
            // Delay detection until ValidateType(), this is because you can add named streams to the base type that collides with those on the derived type.
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => type2.Properties.Count(),
                "A property with same name 'Name' already exists in type 'namespace.type2'. Please make sure that there is no property with the same name defined in one of the base types.",
                "Named stream can't have the same name as another named stream - new instance.");
            type2 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, type1, "namespace", "type2", false);
            type2.AddProperty(new ResourceProperty(nameStream.Name, ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream))));  // Adding a new instance with the same name
            type2.SetReadOnly();
            // Delay detection until ValidaType(), this is because you can add named streams to the base type that collides with those on the derived type.
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => type2.Properties.Count(),
                "A property with same name 'Name' already exists in type 'namespace.type2'. Please make sure that there is no property with the same name defined in one of the base types.",
                "Named stream can't have the same name as another named stream - new instance.");

            // Adding a property which will collide with named streams declared on this type
            type1 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "namespace", "type1", true);
            type1.AddProperty(idProperty);
            nameStream = new ResourceProperty("Name", ResourcePropertyKind.Stream, ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)));
            type1.AddProperty(nameStream);
            ExceptionUtils.ExpectedException<InvalidOperationException>(
                () => type1.AddProperty(name),
                "A property with same name 'Name' already exists in type 'namespace.type1'. Please make sure that there is no property with the same name defined in one of the base types.",
                "Can't add property with the same name as a named stream.");

            // Adding a property which will collide with named streams declared on base type
            type1 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "namespace", "type1", true);
            type1.AddProperty(idProperty);
            type1.AddProperty(nameStream);
            // We don't detect name collision between named streams and properties until we enumerate properties after the type is set to readonly.
            type2 = new ResourceType(typeof(object), ResourceTypeKind.EntityType, type1, "namespace", "type2", false);
            type2.AddProperty(name);
            type2.Properties.Count();
            type2.SetReadOnly();
            // Detect name collision now.
            ExceptionUtils.ExpectedException<InvalidOperationException>(
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:ResourceTypeTests.cs


注:本文中的Microsoft.OData.Service.Providers.ResourceType.AddProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。